fixed command.Execute() and changed the logging level of service.executeCommand()
Change-Id: I8cc853c99fedb6517f9820036c41d450c26e3bf8
This commit is contained in:
parent
89d379e5e7
commit
fe8dae24a8
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
__author__ = "Lisa Zangrando"
|
__author__ = "Lisa Zangrando"
|
||||||
@ -211,9 +212,12 @@ class Execute(HTTPCommand):
|
|||||||
super(Execute, self).__init__(name)
|
super(Execute, self).__init__(name)
|
||||||
|
|
||||||
def sendRequest(self, synergy_url, manager, command, args=None):
|
def sendRequest(self, synergy_url, manager, command, args=None):
|
||||||
|
if args is None:
|
||||||
|
args = {}
|
||||||
|
|
||||||
payload = {"manager": manager,
|
payload = {"manager": manager,
|
||||||
"command": command,
|
"command": command,
|
||||||
"args": args}
|
"args": json.dumps(args)}
|
||||||
|
|
||||||
super(Execute, self).sendRequest(synergy_url + "/synergy/execute",
|
super(Execute, self).sendRequest(synergy_url + "/synergy/execute",
|
||||||
payload)
|
payload)
|
||||||
|
@ -13,7 +13,6 @@ except ImportError:
|
|||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from synergy.common import config
|
from synergy.common import config
|
||||||
from synergy.common import serializer
|
|
||||||
from synergy.common import service
|
from synergy.common import service
|
||||||
from synergy.common import wsgi
|
from synergy.common import wsgi
|
||||||
|
|
||||||
@ -242,7 +241,8 @@ class Synergy(service.Service):
|
|||||||
|
|
||||||
if query:
|
if query:
|
||||||
parameters = parse_qs(query)
|
parameters = parse_qs(query)
|
||||||
LOG.info(parameters)
|
LOG.debug("execute command: parameters=%s" % parameters)
|
||||||
|
|
||||||
if "manager" in parameters:
|
if "manager" in parameters:
|
||||||
manager_name = escape(parameters['manager'][0])
|
manager_name = escape(parameters['manager'][0])
|
||||||
|
|
||||||
@ -271,57 +271,12 @@ class Synergy(service.Service):
|
|||||||
except Exception:
|
except Exception:
|
||||||
result = result.__dict__
|
result = result.__dict__
|
||||||
|
|
||||||
LOG.info("command result %s" % result)
|
LOG.debug("execute command: result=%s" % result)
|
||||||
|
|
||||||
start_response("200 OK", [("Content-Type", "text/html")])
|
start_response("200 OK", [("Content-Type", "text/html")])
|
||||||
return ["%s" % json.dumps(result)]
|
return ["%s" % json.dumps(result)]
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.info("executeCommand error: %s" % ex)
|
LOG.debug("execute command: error=%s" % ex)
|
||||||
start_response("404 NOT FOUND",
|
|
||||||
[("Content-Type", "text/plain")])
|
|
||||||
return ["error: %s" % ex]
|
|
||||||
else:
|
|
||||||
start_response("404 NOT FOUND", [("Content-Type", "text/plain")])
|
|
||||||
return ["manager %r not found!" % manager_name]
|
|
||||||
|
|
||||||
def executeCommand2(self, environ, start_response):
|
|
||||||
manager_name = None
|
|
||||||
command = None
|
|
||||||
|
|
||||||
synergySerializer = serializer.SynergySerializer()
|
|
||||||
query = environ.get("QUERY_STRING", None)
|
|
||||||
# LOG.info("QUERY_STRING %s" % query)
|
|
||||||
if query:
|
|
||||||
parameters = parse_qs(query)
|
|
||||||
|
|
||||||
if "manager" in parameters:
|
|
||||||
manager_name = escape(parameters['manager'][0])
|
|
||||||
|
|
||||||
if "command" in parameters:
|
|
||||||
command_string = escape(parameters['command'][0])
|
|
||||||
command_string = command_string.replace("'", "\"")
|
|
||||||
entity = json.loads(command_string)
|
|
||||||
command = synergySerializer.deserialize_entity(context=None,
|
|
||||||
entity=entity)
|
|
||||||
|
|
||||||
if not query or not manager_name or not command:
|
|
||||||
start_response("404 NOT FOUND", [("Content-Type", "text/plain")])
|
|
||||||
return ["wrong query"]
|
|
||||||
|
|
||||||
if manager_name in self.managers:
|
|
||||||
manager = self.managers[manager_name]
|
|
||||||
try:
|
|
||||||
cmd_result = manager.execute(command=command.getName(),
|
|
||||||
**command.getParameters())
|
|
||||||
command.addResult("result", cmd_result)
|
|
||||||
result = synergySerializer.serialize_entity(context=None,
|
|
||||||
entity=command)
|
|
||||||
# LOG.info("command result %s" % result)
|
|
||||||
|
|
||||||
start_response("200 OK", [("Content-Type", "text/html")])
|
|
||||||
return ["%s" % json.dumps(result)]
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.info("executeCommand error: %s" % ex)
|
|
||||||
start_response("404 NOT FOUND",
|
start_response("404 NOT FOUND",
|
||||||
[("Content-Type", "text/plain")])
|
[("Content-Type", "text/plain")])
|
||||||
return ["error: %s" % ex]
|
return ["error: %s" % ex]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user