Ejemplo n.º 1
0
    def _xml_to_obj(cls, serialized_str):
        """
        @summary: Returns an instance of a Hypervisor
        based on the xml serialized_str
        passed in.
        @param serialized_str: XML serialized string
        @type serialized_str: String
        @return: List of Hypervisors
        @rtype: List
        """
        element = ET.fromstring(serialized_str)
        hypervisors = []
        for hypervisor in element.findall('hypervisor'):
            if "servers" in [elem.tag for elem in hypervisor.iter()]:
                for server in hypervisor.iter('server'):
                    servers = [Server._dict_to_obj(server.attrib)]
            else:
                servers = None
                hypervisor.attrib.update({"servers": servers})

            hypervisor_dict = hypervisor.attrib
            id = hypervisor_dict['id']
            hypervisor_hostname = hypervisor_dict['hypervisor_hostname']
            hypervisors.append(Hypervisor(id, hypervisor_hostname, servers))

        return hypervisors
Ejemplo n.º 2
0
 def _xml_to_obj(cls, serialized_str):
     """
     @summary: Returns an instance of a Hypervisor
     based on the xml serialized_str
     passed in.
     @param serialized_str: XML serialized string
     @type serialized_str: String
     @return: List of Hypervisors
     @rtype: List
     """
     element = ET.fromstring(serialized_str)
     hypervisors = []
     for hypervisor in element.findall('hypervisor'):
         hypervisor_dict = hypervisor.attrib
         id = hypervisor_dict['id']
         hypervisor_hostname = hypervisor_dict['hypervisor_hostname']
         if "servers" in [elem.tag for elem in hypervisor.iter()]:
             servers = []
             for server in hypervisor.iter('server'):
                 servers.append(Server._dict_to_obj(server.attrib))
             return Hypervisor(id, hypervisor_hostname, servers)
         else:
             servers = None
             hypervisor.attrib.update({"servers": servers})
             hypervisors.append(Hypervisor(id, hypervisor_hostname,
                                           servers))
             return hypervisors
Ejemplo n.º 3
0
 def _json_to_obj(cls, serialized_str):
     """
     @summary: Returns an instance of a Hypervisor
     based on the json serialized_str
     passed in.
     @param serialized_str: JSON serialized string
     @type serialized_str: String
     @return: List of Hypervisors
     @rtype: List
     """
     json_dict = json.loads(serialized_str)
     hypervisors = []
     for hypervisor_dict in json_dict['hypervisors']:
         id = hypervisor_dict['id']
         hypervisor_hostname = hypervisor_dict['hypervisor_hostname']
         if 'servers' in hypervisor_dict.keys():
             servers = []
             for server_dict in hypervisor_dict['servers']:
                 servers.append(Server._dict_to_obj(server_dict))
             return Hypervisor(id, hypervisor_hostname, servers)
         else:
             servers = None
             hypervisor_dict.update({"servers": servers})
             hypervisors.append(Hypervisor(id, hypervisor_hostname,
                                           servers))
             return hypervisors
Ejemplo n.º 4
0
 def setUpClass(cls):
     docs_url = "http://docs.openstack.org"
     ext = "compute/ext/extended_status"
     cls.server_xml = """
         <server
         xmlns:OS-DCF="{docs_url}/compute/ext/disk_config/api/v1.1"
         xmlns:OS-EXT-STS="{docs_url}/{ext}/api/v1.1"
         xmlns:OS-EXT-SRV-ATTR="{docs_url}/{ext}/api/v1.1"
         xmlns:atom="http://www.w3.org/2005/Atom"
         xmlns="{docs_url}/compute/api/v1.1"
         status="ACTIVE" updated="2012-12-03T19:04:06Z"
         hostId="123"
         tenant_id="660"
         name="testserver47476" created="2012-12-03T18:59:16Z"
         userId="199835" tenantId="660" accessIPv4="192.168.1.10"
         accessIPv6="2001:11:7811:69:cf10:c02d:ff10:fa"
         progress="100" id="5" OS-EXT-STS:vm_state="active"
         key_name="ssh_key"
         OS-EXT-STS:task_state="None" OS-EXT-STS:power_state="1"
         OS-DCF:diskConfig="AUTO"
         OS-EXT-SRV-ATTR:instance_name="instance-test"
         OS-EXT-SRV-ATTR:host="host123"
         OS-EXT-SRV-ATTR:hypervisor_hostname="hyper-host">
         <image id="1">
             <atom:link href="https://127.0.0.1/660/images/1"
             rel="bookmark"/>
         </image>
         <flavor id="2">
             <atom:link href="https://127.0.0.1/660/flavors/2"
             rel="bookmark"/>
         </flavor>
         <metadata>
             <meta key="meta1">value1</meta>
         </metadata>
         <addresses>
             <network id="public">
                 <ip version="4" addr="198.61.236.10"/>
                 <ip version="6" addr="2001:11:7811:69:cf10:c02d:ff10:fa"/>
             </network>
             <network id="private">
                 <ip version="4" addr="10.176.99.109"/>
             </network>
         </addresses>
         <atom:link href="https://127.0.0.1/v2/660/servers/5" rel="self"/>
         <atom:link href="https://127.0.0.1/660/servers/5" rel="bookmark"/>
         </server>
         """.format(
         docs_url=docs_url, ext=ext
     )
     cls.server = Server.deserialize(cls.server_xml, "xml")
Ejemplo n.º 5
0
 def setUpClass(cls):
     docs_url = 'http://docs.openstack.org'
     ext = 'compute/ext/extended_status'
     cls.server_xml = \
         """
         <server
         xmlns:OS-DCF="{docs_url}/compute/ext/disk_config/api/v1.1"
         xmlns:OS-EXT-STS="{docs_url}/{ext}/api/v1.1"
         xmlns:OS-EXT-SRV-ATTR="{docs_url}/{ext}/api/v1.1"
         xmlns:atom="http://www.w3.org/2005/Atom"
         xmlns="{docs_url}/compute/api/v1.1"
         status="ACTIVE" updated="2012-12-03T19:04:06Z"
         hostId="123"
         tenant_id="660"
         name="testserver47476" created="2012-12-03T18:59:16Z"
         userId="199835" tenantId="660" accessIPv4="192.168.1.10"
         accessIPv6="2001:11:7811:69:cf10:c02d:ff10:fa"
         progress="100" id="5" OS-EXT-STS:vm_state="active"
         key_name="ssh_key"
         OS-EXT-STS:task_state="None" OS-EXT-STS:power_state="1"
         OS-DCF:diskConfig="AUTO"
         OS-EXT-SRV-ATTR:instance_name="instance-test"
         OS-EXT-SRV-ATTR:host="host123"
         OS-EXT-SRV-ATTR:hypervisor_hostname="hyper-host">
         <image id="1">
             <atom:link href="https://127.0.0.1/660/images/1"
             rel="bookmark"/>
         </image>
         <flavor id="2">
             <atom:link href="https://127.0.0.1/660/flavors/2"
             rel="bookmark"/>
         </flavor>
         <metadata>
             <meta key="meta1">value1</meta>
         </metadata>
         <addresses>
             <network id="public">
                 <ip version="4" addr="198.61.236.10"/>
                 <ip version="6" addr="2001:11:7811:69:cf10:c02d:ff10:fa"/>
             </network>
             <network id="private">
                 <ip version="4" addr="10.176.99.109"/>
             </network>
         </addresses>
         <atom:link href="https://127.0.0.1/v2/660/servers/5" rel="self"/>
         <atom:link href="https://127.0.0.1/660/servers/5" rel="bookmark"/>
         </server>
         """.format(docs_url=docs_url, ext=ext)
     cls.server = Server.deserialize(cls.server_xml, 'xml')
Ejemplo n.º 6
0
 def setUpClass(cls):
     cls.server_json = \
         """
         {
           "server" : {
             "status" : "ACTIVE",
             "key_name" : "ssh_key",
             "updated" : "2012-12-03T19:04:06Z",
             "hostId" : "123",
             "addresses" : {
               "public" : [
                 {
                   "version" : 4,
                   "addr" : "198.61.236.10"
                 },
                 {
                   "version" : 6,
                   "addr" : "2001:11:7811:69:cf10:c02d:ff10:fa"
                 }
               ],
               "private" : [
                 {
                   "version" : 4,
                   "addr" : "10.176.99.109"
                 }
               ]
             },
             "links" : [
               {
                 "href" : "https://127.0.0.1/v2/660/servers/5",
                 "rel" : "self"
               },
               {
                 "href" : "https://127.0.0.1/660/servers/5",
                 "rel" : "bookmark"
               }
             ],
             "image" : {
               "id" : "1",
               "links" : [
                 {
                   "href" : "https://127.0.0.1/660/images/1",
                   "rel" : "bookmark"
                 }
               ]
             },
             "OS-EXT-STS:task_state" : null,
             "OS-EXT-STS:vm_state" : "active",
             "flavor" : {
               "id" : "2",
               "links" : [
                 {
                   "href" : "https://127.0.0.1/660/flavors/2",
                   "rel" : "bookmark"
                 }
               ]
             },
             "id" : "5",
             "user_id" : "199835",
             "name" : "testserver47476",
             "created" : "2012-12-03T18:59:16Z",
             "tenant_id" : "660",
             "OS-DCF:diskConfig" : "AUTO",
             "accessIPv4" : "192.168.1.10",
             "accessIPv6" : "2001:11:7811:69:cf10:c02d:ff10:fa",
             "progress" : 100,
             "OS-EXT-STS:power_state" : 1,
             "metadata" : {
                 "meta1": "value1"
             }
           }
         }
         """
     cls.server = Server.deserialize(cls.server_json, 'json')
Ejemplo n.º 7
0
 def setUpClass(cls):
     cls.server_json = """
         {
           "server" : {
             "status" : "ACTIVE",
             "key_name" : "ssh_key",
             "updated" : "2012-12-03T19:04:06Z",
             "hostId" : "123",
             "OS-EXT-SRV-ATTR:host" : "host123",
             "addresses" : {
               "public" : [
                 {
                   "version" : 4,
                   "addr" : "198.61.236.10"
                 },
                 {
                   "version" : 6,
                   "addr" : "2001:11:7811:69:cf10:c02d:ff10:fa"
                 }
               ],
               "private" : [
                 {
                   "version" : 4,
                   "addr" : "10.176.99.109"
                 }
               ]
             },
             "links" : [
               {
                 "href" : "https://127.0.0.1/v2/660/servers/5",
                 "rel" : "self"
               },
               {
                 "href" : "https://127.0.0.1/660/servers/5",
                 "rel" : "bookmark"
               }
             ],
             "image" : "",
             "OS-EXT-STS:task_state" : null,
             "OS-EXT-STS:vm_state" : "active",
             "OS-EXT-SRV-ATTR:instance_name" : "instance-test",
             "OS-EXT-SRV-ATTR:hypervisor_hostname" : "hyper-host",
             "flavor" : {
               "id" : "2",
               "links" : [
                 {
                   "href" : "https://127.0.0.1/660/flavors/2",
                   "rel" : "bookmark"
                 }
               ]
             },
             "id" : "5",
             "user_id" : "199835",
             "name" : "testserver47476",
             "created" : "2012-12-03T18:59:16Z",
             "tenant_id" : "660",
             "OS-DCF:diskConfig" : "AUTO",
             "accessIPv4" : "192.168.1.10",
             "accessIPv6" : "2001:11:7811:69:cf10:c02d:ff10:fa",
             "progress" : 100,
             "OS-EXT-STS:power_state" : 1,
             "metadata" : {
                 "meta1": "value1"
             }
           }
         }
         """
     cls.server = Server.deserialize(cls.server_json, "json")