aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/status_callback.py
diff options
context:
space:
mode:
authorKingPoo <haojingbo@huawei.com>2016-11-09 22:39:01 -0500
committerKingPoo <haojingbo@huawei.com>2016-11-09 22:39:01 -0500
commit404fcf8f737f405da7fd2e61441dd20a57d63935 (patch)
treebe6f2214774edb1c803303eede8e810028a7584d /deploy/status_callback.py
parent5f7e61eb5419681359af3ff3e37fac2b771a5c08 (diff)
autopep8 make py files more standard
Change-Id: Ibaa74a1f508b28548668e764d1860393caa356d4 Signed-off-by: KingPoo <haojingbo@huawei.com>
Diffstat (limited to 'deploy/status_callback.py')
-rwxr-xr-xdeploy/status_callback.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/deploy/status_callback.py b/deploy/status_callback.py
index e430326b..d4712ef7 100755
--- a/deploy/status_callback.py
+++ b/deploy/status_callback.py
@@ -3,14 +3,16 @@ import json
import sys
import logging
+
def task_error(host, data):
logging.info("task_error: host=%s,data=%s" % (host, data))
- if type(data) == dict:
+ if isinstance(data, dict):
invocation = data.pop('invocation', {})
notify_host("localhost", host, "failed")
+
class CallbackModule(object):
"""
logs playbook results, per host, in /var/log/ansible/hosts
@@ -58,7 +60,8 @@ class CallbackModule(object):
def playbook_on_task_start(self, name, is_conditional):
pass
- def playbook_on_vars_prompt(self, varname, private=True, prompt=None, encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
+ def playbook_on_vars_prompt(self, varname, private=True, prompt=None,
+ encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
pass
def playbook_on_setup(self):
@@ -101,7 +104,10 @@ class CallbackModule(object):
def raise_for_status(resp):
if resp.status < 200 or resp.status > 300:
- raise RuntimeError("%s, %s, %s" % (resp.status, resp.reason, resp.read()))
+ raise RuntimeError(
+ "%s, %s, %s" %
+ (resp.status, resp.reason, resp.read()))
+
def auth(conn):
credential = {}
@@ -116,6 +122,7 @@ def auth(conn):
raise_for_status(resp)
return json.loads(resp.read())["token"]
+
def notify_host(compass_host, host, status):
if status == "succ":
body = {"ready": True}
@@ -125,8 +132,8 @@ def notify_host(compass_host, host, status):
host = host.strip("host")
url = "/api/clusterhosts/%s/state" % host
else:
- logging.error("notify_host: host %s with status %s is not supported" \
- % (host, status))
+ logging.error("notify_host: host %s with status %s is not supported"
+ % (host, status))
return
headers = {"Content-type": "application/json",
@@ -135,12 +142,15 @@ def notify_host(compass_host, host, status):
conn = httplib.HTTPConnection(compass_host, 80)
token = auth(conn)
headers["X-Auth-Token"] = token
- logging.info("host=%s,url=%s,body=%s,headers=%s" % (compass_host,url,json.dumps(body),headers))
+ logging.info("host=%s,url=%s,body=%s,headers=%s" %
+ (compass_host, url, json.dumps(body), headers))
conn.request("POST", url, json.dumps(body), headers)
resp = conn.getresponse()
try:
raise_for_status(resp)
- logging.info("notify host status success!!! status=%s, body=%s" % (resp.status, resp.read()))
+ logging.info(
+ "notify host status success!!! status=%s, body=%s" %
+ (resp.status, resp.read()))
except Exception as e:
logging.error("http request failed %s" % str(e))
raise