def setUpClass(cls): cls.image_json = \ """ {"image": { "status": "ACTIVE", "updated": "2012-06-29T17:38:26Z", "links": [{"href": "https://127.0.0.1/v2/600/images/1", "rel": "self"}, {"href": "https://127.0.0.1/600/images/1", "rel": "bookmark"}, {"href": "https://127.0.0.1/600/images/1", "type": "application/vnd.openstack.image", "rel": "alternate"}], "minDisk": 10, "id": "1", "name": "Debian 6 (Squeeze)", "created": "2012-06-29T17:38:07Z", "OS-DCF:diskConfig": "AUTO", "progress": 100, "minRam": 256, "metadata": { "meta1": "value1", "meta2": "value2" } } } """ cls.image = Image.deserialize(cls.image_json, 'json')
def _xml_ele_to_obj(cls, element): """Helper method to turn ElementTree instance to Server instance.""" server = element.attrib addresses = None flavor = None image = None metadata = None links = Links._xml_ele_to_obj(element) if element.find("addresses") is not None: addresses = Addresses._xml_ele_to_obj(element.find("addresses")) if element.find("flavor") is not None: flavor = Flavor._xml_ele_to_obj(element.find("flavor")) if element.find("image") is not None: image = Image._xml_ele_to_obj(element.find("image")) if element.find("metadata") is not None: metadata = Metadata._xml_ele_to_obj(element.find("metadata")) if "progress" in server: progress = server.get("progress") and int(server.get("progress")) else: progress = None server = Server( id=server.get("id"), disk_config=server.get("diskConfig"), power_state=server.get("power_state"), progress=progress, task_state=server.get("task_state").lower(), vm_state=server.get("vm_state"), name=server.get("name"), tenant_id=server.get("tenant_id"), status=server.get("status"), updated=server.get("updated"), created=server.get("created"), host_id=server.get("hostId"), user_id=server.get("userId"), accessIPv4=server.get("accessIPv4"), config_drive=server.get("config_drive"), accessIPv6=server.get("accessIPv6"), addresses=addresses, flavor=flavor, image=image, links=links, metadata=metadata, admin_pass=server.get("adminPass"), key_name=server.get("key_name"), host=server.get("host"), instance_name=server.get("instance_name"), hypervisor_name=server.get("hypervisor_hostname"), ) return server
def _xml_ele_to_obj(cls, element): """Helper method to turn ElementTree instance to Server instance.""" server = element.attrib addresses = None flavor = None image = None metadata = None links = Links._xml_ele_to_obj(element) if element.find('addresses') is not None: addresses = Addresses._xml_ele_to_obj(element.find('addresses')) if element.find('flavor') is not None: flavor = Flavor._xml_ele_to_obj(element.find('flavor')) if element.find('image'): image = Image._xml_ele_to_obj(element.find('image')) if element.find('metadata') is not None: metadata = Metadata._xml_ele_to_obj(element.find('metadata')) if 'progress' in server: progress = (server.get('progress') and int(server.get('progress'))) else: progress = None server = Server(id=server.get('id'), disk_config=server.get('diskConfig'), power_state=server.get('power_state'), progress=progress, task_state=server.get('task_state').lower(), vm_state=server.get('vm_state'), name=server.get('name'), tenant_id=server.get('tenant_id'), status=server.get('status'), updated=server.get('updated'), created=server.get('created'), host_id=server.get('hostId'), user_id=server.get('userId'), accessIPv4=server.get('accessIPv4'), config_drive=server.get('config_drive'), accessIPv6=server.get('accessIPv6'), addresses=addresses, flavor=flavor, image=image, links=links, metadata=metadata, admin_pass=server.get('adminPass'), key_name=server.get('key_name'), host=server.get('host'), instance_name=server.get('instance_name'), hypervisor_name=server.get('hypervisor_hostname')) return server
def _xml_ele_to_obj(cls, element): """Helper method to turn ElementTree instance to Server instance.""" server_dict = element.attrib addresses = None flavor = None image = None links = None metadata = None links = Links._xml_ele_to_obj(element) if element.find("addresses") is not None: addresses = Addresses._xml_ele_to_obj(element.find("addresses")) if element.find("flavor") is not None: flavor = Flavor._xml_ele_to_obj(element.find("flavor")) if element.find("image") is not None: image = Image._xml_ele_to_obj(element.find("image")) if element.find("metadata") is not None: metadata = Metadata._xml_ele_to_obj(element) if "progress" in server_dict: progress = server_dict.get("progress") and int(server_dict.get("progress")) if "tenantId" in server_dict: tenant_id = server_dict.get("tenantId") if "userId" in server_dict: user_id = server_dict.get("userId") server = Server( server_dict["id"], server_dict["diskConfig"], server_dict["power_state"], progress, server_dict["task_state"], server_dict["vm_state"], server_dict["name"], tenant_id, server_dict["status"], server_dict["updated"], server_dict["created"], server_dict["hostId"], user_id, server_dict["accessIPv4"], server_dict["accessIPv6"], addresses, flavor, image, links, metadata, ) return server
def _xml_ele_to_obj(cls, element): """Helper method to turn ElementTree instance to Server instance.""" server = element.attrib addresses = None flavor = None image = None metadata = None fault = None links = Links._xml_ele_to_obj(element) if element.find('addresses') is not None: addresses = Addresses._xml_ele_to_obj(element.find('addresses')) if element.find('flavor') is not None: flavor = Flavor._xml_ele_to_obj(element.find('flavor')) if element.find('image'): image = Image._xml_ele_to_obj(element.find('image')) if element.find('metadata') is not None: metadata = Metadata._xml_ele_to_obj(element.find('metadata')) if element.find('fault') is not None: fault = Fault._xml_ele_to_obj(element.find('fault')) if 'progress' in server: progress = (server.get('progress') and int(server.get('progress'))) else: progress = None server = Server( id=server.get('id'), disk_config=server.get('diskConfig'), power_state=server.get('power_state'), progress=progress, task_state=server.get('task_state').lower(), vm_state=server.get('vm_state'), name=server.get('name'), tenant_id=server.get('tenant_id'), status=server.get('status'), updated=server.get('updated'), created=server.get('created'), host_id=server.get('hostId'), user_id=server.get('userId'), accessIPv4=server.get('accessIPv4'), config_drive=server.get('config_drive'), accessIPv6=server.get('accessIPv6'), addresses=addresses, flavor=flavor, image=image, links=links, metadata=metadata, admin_pass=server.get('adminPass'), key_name=server.get('key_name'), host=server.get('host'), instance_name=server.get('instance_name'), hypervisor_name=server.get('hypervisor_hostname'), security_groups=server.get('security_groups'), fault=fault) return server
def _xml_ele_to_obj(cls, element): '''Helper method to turn ElementTree instance to Server instance.''' server = element.attrib addresses = None flavor = None image = None metadata = None links = Links._xml_ele_to_obj(element) if element.find('addresses') is not None: addresses = Addresses._xml_ele_to_obj(element.find('addresses')) if element.find('flavor') is not None: flavor = Flavor._xml_ele_to_obj(element.find('flavor')) if element.find('image') is not None: image = Image._xml_ele_to_obj(element.find('image')) if element.find('metadata') is not None: metadata = Metadata._xml_ele_to_obj(element) if 'progress' in server: progress = server.get('progress') \ and int(server.get('progress')) else: progress = None server = Server( id=server.get('id'), disk_config=server.get('diskConfig'), power_state=server.get('power_state'), progress=progress, task_state=server.get('task_state'), vm_state=server.get('vm_state'), name=server.get('name'), tenant_id=server.get('tenant_id'), status=server.get('status'), updated=server.get('updated'), created=server.get('created'), host_id=server.get('hostId'), user_id=server.get('user_id'), accessIPv4=server.get('accessIPv4'), accessIPv6=server.get('accessIPv6'), addresses=addresses, flavor=flavor, image=image, links=links, metadata=metadata, admin_pass=server.get('adminPass')) return server
def _xml_ele_to_obj(cls, element): '''Helper method to turn ElementTree instance to Server instance.''' server_dict = element.attrib addresses = None flavor = None image = None links = None metadata = None links = Links._xml_ele_to_obj(element) if element.find('addresses') is not None: addresses = Addresses._xml_ele_to_obj(element.find('addresses')) if element.find('flavor') is not None: flavor = Flavor._xml_ele_to_obj(element.find('flavor')) if element.find('image') is not None: image = Image._xml_ele_to_obj(element.find('image')) if element.find('metadata') is not None: metadata = Metadata._xml_ele_to_obj(element) if 'progress' in server_dict: progress = server_dict.get('progress') \ and int(server_dict.get('progress')) if 'tenantId' in server_dict: tenant_id = server_dict.get('tenantId') if 'userId' in server_dict: user_id = server_dict.get('userId') server = Server(server_dict['id'], server_dict['diskConfig'], server_dict['power_state'], progress, server_dict['task_state'], server_dict['vm_state'], server_dict['name'], tenant_id, server_dict['status'], server_dict['updated'], server_dict['created'], server_dict['hostId'], user_id, server_dict['accessIPv4'], server_dict['accessIPv6'], addresses, flavor, image, links, metadata) return server
def setUpClass(cls): url = 'http://docs.openstack.org' cls.image_xml = \ """ <image xmlns:OS-DCF="{url}/compute/ext/disk_config/api/v1.1" xmlns:atom="http://www.w3.org/2005/Atom" xmlns="http://docs.openstack.org/compute/api/v1.1" status="ACTIVE" updated="2012-06-29T17:38:26Z" name="Debian 6 (Squeeze)" created="2012-06-29T17:38:07Z" minDisk="10" progress="100" minRam="256" id="1" OS-DCF:diskConfig="AUTO"> <metadata> <meta key="meta1">value1</meta> <meta key="meta2">value2</meta> </metadata> <atom:link href="https://127.0.0.1/v2/600/images/1" rel="self"/> <atom:link href="https://127.0.0.1/600/images/1" rel="bookmark"/> <atom:link href="https://127.0.0.1/600/images/1" type="application/vnd.openstack.image" rel="alternate"/> </image> """.format(url=url) cls.image = Image.deserialize(cls.image_xml, 'xml')