Removed tabs and others indentation extra spaces
This commit is contained in:
parent
86548bb750
commit
494ae3c594
|
@ -35,9 +35,7 @@ class ResultsCollectorJSONCallback(CallbackBase):
|
|||
|
||||
def v2_runner_on_ok(self, result, *args, **kwargs):
|
||||
host = result._host
|
||||
#print(dir(result._task), result._result.get("ansible_facts"))
|
||||
#self.host_ok.append({ "host" :host.get_name(), "result" : result._result})
|
||||
self.host_ok.append({ "host" :host.get_name(), "name" : result._task.name, "result" : result._result })
|
||||
self.host_ok.append({ "host" :host.get_name(), "name" : result._task.name, "result" : result._result})
|
||||
|
||||
def v2_runner_on_failed(self, result, *args, **kwargs):
|
||||
host = result._host
|
||||
|
@ -72,7 +70,7 @@ class Ansible(PyExecPlugin):
|
|||
|
||||
# required for
|
||||
# https://github.com/ansible/ansible/blob/devel/lib/ansible/inventory/manager.py#L204
|
||||
|
||||
|
||||
if (len(self.extra_vars) > 0) and self.extra_vars[0].get("ansible_host"):
|
||||
sources = self.extra_vars[0].get("ansible_host")
|
||||
else:
|
||||
|
|
|
@ -10,13 +10,12 @@ class Plugin(PyExecPlugin):
|
|||
"outputKeys" : ["result"],
|
||||
"ownerEmail" : "m.lettere@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, data=None, config=None):
|
||||
super().__init__(data, config)
|
||||
|
||||
|
||||
def execute(self):
|
||||
code = self.data.get("code")
|
||||
if code != None:
|
||||
ret = eval(code, { "data" : self.data})
|
||||
return { "result" : ret }
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ class Plugin(PyExecPlugin):
|
|||
self.ep1["params"] = data.get("endpoint1").get("params")
|
||||
self.ep1["files"] = data.get("endpoint1").get("files")
|
||||
self.ep1["expect"] = data.get("endpoint1").get("expect")
|
||||
|
||||
|
||||
self.datamap = data.get("datamap") or { "place" : "body" }
|
||||
|
||||
|
||||
self.ep2["method"] = data.get("endpoint2").get("method") or "post"
|
||||
self.ep2["url"] = data.get("endpoint2").get("url")
|
||||
self.ep2["headers"] = data.get("endpoint2").get("headers") or {}
|
||||
|
@ -39,7 +39,7 @@ class Plugin(PyExecPlugin):
|
|||
self.ep2["expect"] = data.get("endpoint2").get("expect")
|
||||
|
||||
self.fail = data.get("fail") != False
|
||||
|
||||
|
||||
def doRequest1(self):
|
||||
self.session = requests.Session()
|
||||
ep = self.ep1
|
||||
|
@ -48,18 +48,18 @@ class Plugin(PyExecPlugin):
|
|||
self.response1 = self.session.send(self.request1, stream=True)
|
||||
self.content_type = self.response1.headers["Content-type"]
|
||||
return self.response1
|
||||
|
||||
|
||||
def doRequest2(self):
|
||||
ep = self.ep2
|
||||
logging.getLogger("pyexec").debug("Entering request2 %s - %s", ep["method"], ep["url"])
|
||||
|
||||
|
||||
if self.datamap["place"] == "body":
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=ep["headers"], data = self.response1.content).prepare()
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=ep["headers"], data = self.response1.content).prepare()
|
||||
elif self.datamap["place"] == "params":
|
||||
params = self.ep2["params"] or {}
|
||||
params[self.datamap["name"]] = self.response1.content
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=ep["headers"], params = params).prepare()
|
||||
params.pop(self.datamap["name"])
|
||||
params = self.ep2["params"] or {}
|
||||
params[self.datamap["name"]] = self.response1.content
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=ep["headers"], params = params).prepare()
|
||||
params.pop(self.datamap["name"])
|
||||
elif self.datamap["place"] == "files":
|
||||
#encode custom multipart in order to exploit streaming
|
||||
files = self.ep2["files"] or {}
|
||||
|
@ -91,15 +91,15 @@ class Plugin(PyExecPlugin):
|
|||
#self.request2 = requests.Request(ep["method"], ep["url"], headers=ep["headers"], files = files).prepare()
|
||||
#files.pop(self.datamap["name"])
|
||||
elif self.datamap["place"] == "headers":
|
||||
headers = self.ep2["headers"] or {}
|
||||
headers[self.datamap["name"]] = self.response1.content
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=headers, data = ep["body"], params=ep["params"]).prepare()
|
||||
|
||||
headers = self.ep2["headers"] or {}
|
||||
headers[self.datamap["name"]] = self.response1.content
|
||||
self.request2 = requests.Request(ep["method"], ep["url"], headers=headers, data = ep["body"], params=ep["params"]).prepare()
|
||||
|
||||
self.response2 = self.session.send(self.request2, stream=True)
|
||||
logging.getLogger("pyexec").debug("Request2 sentg %s", datetime.now())
|
||||
self.session.close()
|
||||
return self.response2
|
||||
|
||||
|
||||
def chunkedUpload(self, prolog, response1, epilog, chunksize=1024):
|
||||
logging.getLogger("pyexec").debug("Sending prolog - %s", datetime.now())
|
||||
yield str.encode(prolog)
|
||||
|
@ -117,7 +117,7 @@ class Plugin(PyExecPlugin):
|
|||
return "COMPLETED" if (response.status_code in ep["expect"]) else "FAILED"
|
||||
else:
|
||||
return "COMPLETED" if (response.status_code == ep["expect"]) else "FAILED"
|
||||
|
||||
|
||||
def buildOutput(self, status1, status2):
|
||||
msg = None
|
||||
hdrs1 = {}
|
||||
|
@ -133,7 +133,7 @@ class Plugin(PyExecPlugin):
|
|||
}
|
||||
|
||||
elif status2 == "FAILED":
|
||||
msg = "{} to {} failed with status {} ({}) - {}".format(self.ep2["method"], self.ep2["url"], self.response2.status_code, self.response2.reason, self.response2.text)
|
||||
msg = "{} to {} failed with status {} ({}) - {}".format(self.ep2["method"], self.ep2["url"], self.response2.status_code, self.response2.reason, self.response2.text)
|
||||
if self.fail:
|
||||
raise Exception(msg)
|
||||
else:
|
||||
|
@ -147,12 +147,11 @@ class Plugin(PyExecPlugin):
|
|||
"endpoint2" : { "status" : self.response2.status_code, "reason" : self.response2.reason, "headers" : hdrs2}
|
||||
}
|
||||
|
||||
|
||||
def execute(self):
|
||||
self.doRequest1()
|
||||
status1 = self.computeStatus(self.ep1, self.response1)
|
||||
status2 = "FAILED"
|
||||
if status1 == "COMPLETED":
|
||||
self.doRequest2()
|
||||
status2 = self.computeStatus(self.ep2, self.response2)
|
||||
self.doRequest2()
|
||||
status2 = self.computeStatus(self.ep2, self.response2)
|
||||
return self.buildOutput(status1, status2)
|
||||
|
|
|
@ -10,7 +10,7 @@ from pyexecplugins.pyexecplugins import PyExecPlugin
|
|||
|
||||
class Plugin(PyExecPlugin):
|
||||
name = "Mail"
|
||||
|
||||
|
||||
taskdef = {
|
||||
"name" : "pymail",
|
||||
"description" : "Send mail with pymail worker",
|
||||
|
@ -18,7 +18,7 @@ class Plugin(PyExecPlugin):
|
|||
"outputKeys" : [],
|
||||
"ownerEmail" : "m.lettere@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
def getProtocol(self, config):
|
||||
if config is not None and config["pymail"] is not None:
|
||||
return (config["pymail"].get("protocol") or "plain")
|
||||
|
@ -69,7 +69,6 @@ class Plugin(PyExecPlugin):
|
|||
if self.html is not None:
|
||||
self.html = self.html.format_map(data.get("extra_vars") or {})
|
||||
|
||||
|
||||
def sendMail(self):
|
||||
logging.getLogger("pyexec").debug("Sending mail from %s to %s subj %s ",self.frm, self.to, self.subject)
|
||||
m = self.buildMessage()
|
||||
|
@ -80,7 +79,7 @@ class Plugin(PyExecPlugin):
|
|||
else:
|
||||
self.sendPlainMail(m)
|
||||
logging.getLogger("pyexec").debug("Mail sent.")
|
||||
|
||||
|
||||
def buildMessage(self):
|
||||
if self.html is not None:
|
||||
m = MIMEMultipart("alternative")
|
||||
|
@ -99,7 +98,6 @@ class Plugin(PyExecPlugin):
|
|||
m["Bcc"] = ', '.join(self.bcc)
|
||||
logging.getLogger("pyexec").debug("Message built")
|
||||
return m
|
||||
|
||||
|
||||
def sendPlainMail(self, m):
|
||||
logging.getLogger("pyexec").debug("Sending mail %s - %s - %s",self.server, self.port, self.user)
|
||||
|
@ -117,6 +115,6 @@ class Plugin(PyExecPlugin):
|
|||
s.login(self.user, self.password)
|
||||
s.send_message(m)
|
||||
s.quit()
|
||||
|
||||
|
||||
def execute(self):
|
||||
return self.sendMail()
|
||||
|
|
|
@ -7,7 +7,7 @@ from subprocess import PIPE
|
|||
|
||||
class Plugin(PyExecPlugin):
|
||||
name = "Packer"
|
||||
|
||||
|
||||
taskdef = {
|
||||
"name" : "pypacker",
|
||||
"retryCount" : 0,
|
||||
|
@ -16,7 +16,7 @@ class Plugin(PyExecPlugin):
|
|||
"outputKeys" : ["results"],
|
||||
"ownerEmail" : "m.lettere@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, data=None, config=None):
|
||||
super().__init__(data, config)
|
||||
self.template = data["template"]
|
||||
|
|
|
@ -5,7 +5,6 @@ from pyexecplugins.pyexecplugins import PyExecPlugin
|
|||
|
||||
class Plugin(PyExecPlugin):
|
||||
name = "Shell"
|
||||
|
||||
taskdef = {
|
||||
"name" : "pyshell",
|
||||
"description" : "Execute an Shell commands on target machine. Commands are in the form of an array of objects like { 'line': 'ls -l', 'expect' : 0, 'withshell' : False}. For expect 0 is the default, for withshell False is the default thus they can be omitted.",
|
||||
|
@ -13,7 +12,7 @@ class Plugin(PyExecPlugin):
|
|||
"outputKeys" : ["results"],
|
||||
"ownerEmail" : "m.lettere@gmail.com"
|
||||
}
|
||||
|
||||
|
||||
def __init__(self, data=None, config=None):
|
||||
super().__init__(data, config)
|
||||
|
||||
|
|
Loading…
Reference in New Issue