def _build_detail(self, inst): """Returns a detailed model of a server.""" vm_state = inst.get('vm_state', vm_states.BUILDING) task_state = inst.get('task_state') inst_dict = { 'id': inst['id'], 'name': inst['display_name'], 'user_id': inst.get('user_id', ''), 'tenant_id': inst.get('project_id', ''), 'status': common.status_from_state(vm_state, task_state)} # Return the metadata as a dictionary metadata = {} for item in inst.get('metadata', []): metadata[item['key']] = str(item['value']) inst_dict['metadata'] = metadata inst_dict['hostId'] = '' if inst.get('host'): inst_dict['hostId'] = hashlib.sha224(inst['host']).hexdigest() self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) self._build_addresses(inst_dict, inst) return dict(server=inst_dict)
def _build_detail(self, inst, networks): """Returns a detailed model of a server.""" vm_state = inst.get('vm_state', vm_states.BUILDING) task_state = inst.get('task_state') inst_dict = { 'id': inst['id'], 'name': inst['display_name'], 'user_id': inst.get('user_id', ''), 'tenant_id': inst.get('project_id', ''), 'status': common.status_from_state(vm_state, task_state)} # Return the metadata as a dictionary metadata = {} for item in inst.get('metadata', []): metadata[item['key']] = str(item['value']) inst_dict['metadata'] = metadata inst_dict['hostId'] = '' if inst.get('host'): inst_dict['hostId'] = hashlib.sha224(inst['host']).hexdigest() self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) self._build_addresses(inst_dict, networks) return dict(server=inst_dict)
def _build_detail(self, inst): """Returns a detailed model of a server.""" vm_state = inst.get("vm_state", vm_states.BUILDING) task_state = inst.get("task_state") inst_dict = { "id": inst["id"], "name": inst["display_name"], "user_id": inst.get("user_id", ""), "tenant_id": inst.get("project_id", ""), "status": common.status_from_state(vm_state, task_state), } # Return the metadata as a dictionary metadata = {} for item in inst.get("metadata", []): metadata[item["key"]] = str(item["value"]) inst_dict["metadata"] = metadata inst_dict["hostId"] = "" if inst.get("host"): inst_dict["hostId"] = hashlib.sha224(inst["host"]).hexdigest() self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) self._build_addresses(inst_dict, inst) return dict(server=inst_dict)
def test_status_rebuild_from_state(self): for vm_state in (vm_states.ACTIVE, vm_states.STOPPED, vm_states.ERROR): for task_state in (task_states.REBUILDING, task_states.REBUILD_BLOCK_DEVICE_MAPPING, task_states.REBUILD_SPAWNING): actual = common.status_from_state(vm_state, task_state) expected = 'REBUILD' self.assertEqual(expected, actual)
def test_status_from_state(self): for vm_state in (vm_states.ACTIVE, vm_states.STOPPED): for task_state in (task_states.RESIZE_PREP, task_states.RESIZE_MIGRATING, task_states.RESIZE_MIGRATED, task_states.RESIZE_FINISH): actual = common.status_from_state(vm_state, task_state) expected = 'RESIZE' self.assertEqual(expected, actual)
def _build_detail(self, inst): """Returns a detailed model of a server.""" vm_state = inst.get("vm_state", vm_states.BUILDING) task_state = inst.get("task_state") inst_dict = { "id": inst["id"], "name": inst["display_name"], "user_id": inst.get("user_id", ""), "tenant_id": inst.get("project_id", ""), "status": common.status_from_state(vm_state, task_state), } # Return the metadata as a dictionary metadata = {} for item in inst.get("metadata", []): metadata[item["key"]] = str(item["value"]) inst_dict["metadata"] = metadata inst_dict["hostId"] = "" if inst.get("host"): inst_dict["hostId"] = hashlib.sha224(inst["host"]).hexdigest() self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) networks = common.get_networks_for_instance(self.context, inst) self._build_addresses(inst_dict, networks) inst_dict["created"] = utils.isotime(inst["created_at"]) inst_dict["updated"] = utils.isotime(inst["updated_at"]) status = inst_dict.get("status") if status in ("ACTIVE", "BUILD", "REBUILD", "RESIZE", "VERIFY_RESIZE"): inst_dict["progress"] = inst["progress"] or 0 inst_dict["accessIPv4"] = inst.get("access_ip_v4") or "" inst_dict["accessIPv6"] = inst.get("access_ip_v6") or "" inst_dict["key_name"] = inst.get("key_name", "") inst_dict["config_drive"] = inst.get("config_drive") return dict(server=inst_dict)
def _build_detail(self, inst): """Returns a detailed model of a server.""" vm_state = inst.get('vm_state', vm_states.BUILDING) task_state = inst.get('task_state') inst_dict = { 'id': inst['uuid'], 'name': inst['display_name'], 'user_id': inst.get('user_id', ''), 'tenant_id': inst.get('project_id', ''), 'status': common.status_from_state(vm_state, task_state)} # Return the metadata as a dictionary metadata = {} for item in inst.get('metadata', []): metadata[item['key']] = str(item['value']) inst_dict['metadata'] = metadata inst_dict['hostId'] = '' if inst.get('host'): inst_dict['hostId'] = hashlib.sha224(inst['host']).hexdigest() self._build_image(inst_dict, inst) self._build_flavor(inst_dict, inst) networks = common.get_networks_for_instance(self.context, inst) self._build_addresses(inst_dict, networks) inst_dict['created'] = utils.isotime(inst['created_at']) inst_dict['updated'] = utils.isotime(inst['updated_at']) status = inst_dict.get('status') if status in ('ACTIVE', 'BUILD', 'REBUILD', 'RESIZE', 'VERIFY_RESIZE'): inst_dict['progress'] = inst['progress'] or 0 inst_dict['accessIPv4'] = inst.get('access_ip_v4') or "" inst_dict['accessIPv6'] = inst.get('access_ip_v6') or "" inst_dict['key_name'] = inst.get('key_name', '') inst_dict['config_drive'] = inst.get('config_drive') return dict(server=inst_dict)
def _get_vm_status(instance): # If the instance is deleted the vm and task states don't really matter if instance.get("deleted"): return "DELETED" return common.status_from_state(instance.get("vm_state"), instance.get("task_state"))
def _get_vm_state(instance): return common.status_from_state(instance.get("vm_state"), instance.get("task_state"))
def test_status_migrating_from_state(self): for vm_state in (vm_states.ACTIVE, vm_states.PAUSED): task_state = task_states.MIGRATING actual = common.status_from_state(vm_state, task_state) expected = 'MIGRATING' self.assertEqual(expected, actual)