Example #1
0
 def default(self, string):
     events = []
     dom = xmlutil.safe_minidom_parse_string(string)
     events_node = self.find_first_child_named(dom, 'events')
     for event_node in self.find_children_named(events_node, 'event'):
         events.append(self._extract_event(event_node))
     return {'body': {'events': events}}
Example #2
0
 def default(self, string):
     events = []
     dom = xmlutil.safe_minidom_parse_string(string)
     events_node = self.find_first_child_named(dom, "events")
     for event_node in self.find_children_named(events_node, "event"):
         events.append(self._extract_event(event_node))
     return {"body": {"events": events}}
Example #3
0
def action_peek_xml(body):
    """Determine action to invoke."""

    dom = xmlutil.safe_minidom_parse_string(body)
    action_node = dom.childNodes[0]

    return action_node.tagName
Example #4
0
 def deserialize(self, text):
     dom = xmlutil.safe_minidom_parse_string(text)
     metadata_node = self.find_first_child_named(dom, "metadata")
     key = metadata_node.getAttribute("key")
     metadata = {}
     metadata[key] = self.extract_text(metadata_node)
     return {'body': {'metadata': metadata}}
Example #5
0
 def default(self, string):
     dom = xmlutil.safe_minidom_parse_string(string)
     action_node = dom.childNodes[0]
     action_name = action_node.tagName
     action_data = None
     if action_node.hasAttribute("admin_password"):
         action_data = {'admin_password':
                        action_node.getAttribute("admin_password")}
     return {'body': {action_name: action_data}}
Example #6
0
    def default(self, string):
        node = xmlutil.safe_minidom_parse_string(string)
        service = {}
        service_node = self.find_first_child_named(node, 'service')
        if service_node is None:
            return service
        service['host'] = service_node.getAttribute('host')
        service['binary'] = service_node.getAttribute('binary')

        return dict(body=service)
Example #7
0
    def default(self, string):
        node = xmlutil.safe_minidom_parse_string(string)
        service = {}
        service_node = self.find_first_child_named(node, "service")
        if service_node is None:
            return service
        service["host"] = service_node.getAttribute("host")
        service["binary"] = service_node.getAttribute("binary")
        service["disabled_reason"] = service_node.getAttribute("disabled_reason")

        return dict(body=service)
Example #8
0
 def default(self, string):
     """Deserialize an xml-formatted security group create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     security_group = {}
     sg_node = self.find_first_child_named(dom, "security_group")
     if sg_node is not None:
         if sg_node.hasAttribute("name"):
             security_group["name"] = sg_node.getAttribute("name")
         desc_node = self.find_first_child_named(sg_node, "description")
         if desc_node:
             security_group["description"] = self.extract_text(desc_node)
     return {"body": {"security_group": security_group}}
Example #9
0
    def test_safe_parse_xml(self):

        normal_body = ('<?xml version="1.0" ?>'
                       '<foo><bar><v1>hey</v1><v2>there</v2></bar></foo>')

        dom = xmlutil.safe_minidom_parse_string(normal_body)
        # Some versions of minidom inject extra newlines so we ignore them
        result = str(dom.toxml()).replace('\n', '')
        self.assertEqual(normal_body, result)

        self.assertRaises(exception.MalformedRequestBody,
                          xmlutil.safe_minidom_parse_string,
                          tests_utils.killer_xml_body())
Example #10
0
    def default(self, string):
        node = xmlutil.safe_minidom_parse_string(string)

        updates = {}
        updates_node = self.find_first_child_named(node, "updates")
        if updates_node is not None:
            maintenance = self.find_first_child_named(updates_node, "maintenance_mode")
            if maintenance is not None:
                updates[maintenance.tagName] = self.extract_text(maintenance)

            status = self.find_first_child_named(updates_node, "status")
            if status is not None:
                updates[status.tagName] = self.extract_text(status)

        return dict(body=updates)
Example #11
0
    def test_safe_parse_xml(self):

        normal_body = ("""
                 <?xml version="1.0" ?><foo>
                    <bar>
                        <v1>hey</v1>
                        <v2>there</v2>
                    </bar>
                </foo>""").strip()

        dom = xmlutil.safe_minidom_parse_string(normal_body)
        self.assertEqual(normal_body, str(dom.toxml()))

        self.assertRaises(exception.MalformedRequestBody,
                          xmlutil.safe_minidom_parse_string,
                          tests_utils.killer_xml_body())
Example #12
0
 def default(self, string):
     """Deserialize an xml-formatted server group create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     server_group = self._extract_server_group(dom)
     return {'body': {'server_group': server_group}}
Example #13
0
 def deserialize(self, text):
     dom = xmlutil.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Example #14
0
 def default(self, string):
     """Deserialize an xml-formatted security group create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     security_group_rule = self._extract_security_group_rule(dom)
     return {'body': {'security_group_rule': security_group_rule}}
Example #15
0
 def deserialize(self, text):
     dom = xmlutil.safe_minidom_parse_string(text)
     metadata_node = self.find_first_child_named(dom, "metadata")
     metadata = self.extract_metadata(metadata_node)
     return {'body': {'metadata': metadata}}
Example #16
0
 def deserialize(self, text):
     dom = xmlutil.safe_minidom_parse_string(text)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Example #17
0
 def _extract_metadata_container(self, datastring):
     dom = xmlutil.safe_minidom_parse_string(datastring)
     metadata_node = self.find_first_child_named(dom, "metadata")
     metadata = self.extract_metadata(metadata_node)
     return {'body': {'metadata': metadata}}
Example #18
0
    def default(self, string):
        """Deserialize an xml-formatted cell create request."""
        node = xmlutil.safe_minidom_parse_string(string)

        return {'body': {'cell': self._extract_cell(node)}}
Example #19
0
 def default(self, string):
     """Deserialize an xml-formatted server create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     app = self._extract_app(dom)
     return {'body': {'app': app}}
Example #20
0
 def _from_xml(self, datastring):
     plurals = set(self.metadata.get('plurals', {}))
     node = xmlutil.safe_minidom_parse_string(datastring).childNodes[0]
     return {node.nodeName: self._from_xml_node(node, plurals)}
Example #21
0
 def update(self, datastring):
     dom = xmlutil.safe_minidom_parse_string(datastring)
     metadata_item = self.extract_metadata(dom)
     return {'body': {'meta': metadata_item}}
Example #22
0
 def deserialize(self, text):
     dom = xmlutil.safe_minidom_parse_string(text)
     metadata_node = self.find_first_child_named(dom, "metadata")
     metadata = self.extract_metadata(metadata_node)
     return {'body': {'metadata': metadata}}
Example #23
0
 def _from_xml(self, datastring):
     plurals = set(self.metadata.get('plurals', {}))
     node = xmlutil.safe_minidom_parse_string(datastring).childNodes[0]
     return {node.nodeName: self._from_xml_node(node, plurals)}
Example #24
0
 def _extract_metadata_container(self, datastring):
     dom = xmlutil.safe_minidom_parse_string(datastring)
     metadata_node = self.find_first_child_named(dom, "metadata")
     metadata = self.extract_metadata(metadata_node)
     return {'body': {'metadata': metadata}}
Example #25
0
 def default(self, string):
     """Deserialize an xml-formatted security group create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     security_group_rule = self._extract_security_group_rule(dom)
     return {'body': {'security_group_rule': security_group_rule}}
Example #26
0
 def default(self, string):
     """Deserialize an xml-formatted volume create request."""
     dom = xmlutil.safe_minidom_parse_string(string)
     vol = self._extract_volume(dom)
     return {"body": {"volume": vol}}
Example #27
0
    def default(self, string):
        """Deserialize an xml-formatted cell create request."""
        node = xmlutil.safe_minidom_parse_string(string)

        return {'body': {'cell': self._extract_cell(node)}}