Commit 24bd11cf authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_slap_tool: Remove minor duplication

parent 2b579871
...@@ -101,6 +101,15 @@ def convertToREST(function): ...@@ -101,6 +101,15 @@ def convertToREST(function):
wrapper.__doc__ = function.__doc__ wrapper.__doc__ = function.__doc__
return wrapper return wrapper
def castToStr(dict_kw):
instance = etree.Element('instance')
for _id, _value in dict_kw.iteritems():
# cast everything to string
etree.SubElement(instance, "parameter",
attrib={'id':_id}).text = str(_value)
return etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8')
def _assertACI(document): def _assertACI(document):
sm = getSecurityManager() sm = getSecurityManager()
...@@ -876,30 +885,12 @@ class SlapTool(BaseTool): ...@@ -876,30 +885,12 @@ class SlapTool(BaseTool):
else: else:
filter_kw = dict() filter_kw = dict()
instance = etree.Element('instance')
for parameter_id, parameter_value in partition_parameter_kw.iteritems():
# cast everything to string
parameter_value = str(parameter_value)
etree.SubElement(instance, "parameter",
attrib={'id':parameter_id}).text = parameter_value
instance_xml = etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8')
instance = etree.Element('instance')
for parameter_id, parameter_value in filter_kw.iteritems():
# cast everything to string
parameter_value = str(parameter_value)
etree.SubElement(instance, "parameter",
attrib={'id':parameter_id}).text = parameter_value
sla_xml = etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8')
kw = dict(software_release=software_release, kw = dict(software_release=software_release,
software_type=software_type, software_type=software_type,
software_title=partition_reference, software_title=partition_reference,
instance_xml=instance_xml, instance_xml=castToStr(partition_parameter_kw),
shared=shared, shared=shared,
sla_xml=sla_xml, sla_xml=castToStr(filter_kw),
state=state) state=state)
portal = self.getPortalObject() portal = self.getPortalObject()
...@@ -932,6 +923,7 @@ class SlapTool(BaseTool): ...@@ -932,6 +923,7 @@ class SlapTool(BaseTool):
if compute_node_id and compute_partition_id: if compute_node_id and compute_partition_id:
requester.requestInstance(**kw) requester.requestInstance(**kw)
else: else:
# requester is a person so we use another method
requester.requestSoftwareInstance(**kw) requester.requestSoftwareInstance(**kw)
requested_software_instance = self.REQUEST.get('request_instance') requested_software_instance = self.REQUEST.get('request_instance')
if requested_software_instance is not None: if requested_software_instance is not None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment