def get_info(self, instance): """Get the current status of an instance, by name (not ID!) :param instance: nova.objects.instance.Instance object Returns a InstanceInfo object """ LOG.debug('get_info called for instance', instance=instance) try: if not self.session.container_defined(instance.name, instance): return hardware.InstanceInfo(state=power_state.NOSTATE) container_state = self.session.container_state(instance) return hardware.InstanceInfo(state=container_state['state'], max_mem_kb=container_state['max_mem'], mem_kb=container_state['mem'], num_cpu=instance.flavor.vcpus, cpu_time_ns=0) except Exception as ex: with excutils.save_and_reraise_exception(): LOG.error(_LE('Failed to get container info' ' for %(instance)s: %(ex)s'), { 'instance': instance.name, 'ex': ex }, instance=instance)
def get_info(self, instance): """Get the current state and resource usage for this instance. If the instance is not found this method returns (a dictionary with) NOSTATE and all resources == 0. :param instance: the instance object. :returns: a InstanceInfo object """ try: node = _validate_instance_and_node(self.ironicclient, instance) except exception.InstanceNotFound: return hardware.InstanceInfo( state=map_power_state(ironic_states.NOSTATE)) memory_kib = int(node.properties.get('memory_mb', 0)) * 1024 if memory_kib == 0: LOG.warning(_LW("Warning, memory usage is 0 for " "%(instance)s on baremetal node %(node)s."), {'instance': instance.uuid, 'node': instance.node}) num_cpu = node.properties.get('cpus', 0) if num_cpu == 0: LOG.warning(_LW("Warning, number of cpus is 0 for " "%(instance)s on baremetal node %(node)s."), {'instance': instance.uuid, 'node': instance.node}) return hardware.InstanceInfo(state=map_power_state(node.power_state), max_mem_kb=memory_kib, mem_kb=memory_kib, num_cpu=num_cpu)
def get_info(self, instance): azure_name = self._get_omni_name_from_instance(instance) azure_instance = utils.get_instance(self.compute_client, drv_conf.resource_group, azure_name) state = self._get_power_state(azure_instance) return hardware.InstanceInfo(state=state)
def get_info(self, host): """Retrieve information from libvirt for a specific instance name. If a libvirt error is encountered during lookup, we might raise a NotFound exception or Error exception depending on how severe the libvirt error is. :returns hardware.InstanceInfo: """ try: dom_info = self._get_domain_info() except libvirt.libvirtError as ex: error_code = ex.get_error_code() if error_code == libvirt.VIR_ERR_NO_DOMAIN: raise exception.InstanceNotFound(instance_id=self.uuid) msg = (_('Error from libvirt while getting domain info for ' '%(instance_name)s: [Error Code %(error_code)s] %(ex)s') % { 'instance_name': self.name, 'error_code': error_code, 'ex': ex }) raise exception.InternalError(msg) return hardware.InstanceInfo(state=LIBVIRT_POWER_STATE[dom_info[0]], internal_id=self.id)
def get_info(self, instance): """Get the current status of an instance, by name (not ID!) :param instance: nova.objects.instance.Instance object Returns a dict containing: :state: the running state, one of the power_state codes :max_mem: (int) the maximum memory in KBytes allowed :mem: (int) the memory in KBytes used by the domain :num_cpu: (int) the number of virtual CPUs for the domain :cpu_time: (int) the CPU time used in nanoseconds """ compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone gce_id = self._get_gce_id_from_instance(instance) gce_instance = gceutils.get_instance(compute, project, zone, gce_id) power_state = GCE_STATE_MAP[gce_instance['status']] gce_flavor = self.gce_flavor_info[instance.flavor.name] memory_mb = gce_flavor['memory_mb'] vcpus = gce_flavor['vcpus'] return hardware.InstanceInfo(state=power_state, max_mem_kb=memory_mb * 1024, mem_kb=memory_mb * 1024, num_cpu=vcpus, cpu_time_ns=0, id=instance.id)
def get_info(self, instance): container = self._find_container_by_uuid(instance['uuid']) if not container: raise exception.InstanceNotFound(instance_id=instance['name']) running = container['State'].get('Running') mem = container['Config'].get('Memory', 0) # NOTE(ewindisch): cgroups/lxc defaults to 1024 multiplier. # see: _get_cpu_shares for further explaination num_cpu = container['Config'].get('CpuShares', 0) / 1024 # FIXME(ewindisch): Improve use of statistics: # For 'mem', we should expose memory.stat.rss, and # for cpu_time we should expose cpuacct.stat.system, # but these aren't yet exposed by Docker. # # Also see: # docker/docs/sources/articles/runmetrics.md info = hardware.InstanceInfo( max_mem_kb=mem, mem_kb=mem, num_cpu=num_cpu, cpu_time_ns=0, state=(power_state.RUNNING if running else power_state.SHUTDOWN)) return info
def _test_get_info(self, vm_exists): mock_instance = fake_instance.fake_instance_obj(self.context) mock_info = mock.MagicMock(spec_set=dict) fake_info = { 'EnabledState': 2, 'MemoryUsage': mock.sentinel.FAKE_MEM_KB, 'NumberOfProcessors': mock.sentinel.FAKE_NUM_CPU, 'UpTime': mock.sentinel.FAKE_CPU_NS } def getitem(key): return fake_info[key] mock_info.__getitem__.side_effect = getitem expected = hardware.InstanceInfo(state=constants.HYPERV_POWER_STATE[2], max_mem_kb=mock.sentinel.FAKE_MEM_KB, mem_kb=mock.sentinel.FAKE_MEM_KB, num_cpu=mock.sentinel.FAKE_NUM_CPU, cpu_time_ns=mock.sentinel.FAKE_CPU_NS) self._vmops._vmutils.vm_exists.return_value = vm_exists self._vmops._vmutils.get_vm_summary_info.return_value = mock_info if not vm_exists: self.assertRaises(exception.InstanceNotFound, self._vmops.get_info, mock_instance) else: response = self._vmops.get_info(mock_instance) self._vmops._vmutils.vm_exists.assert_called_once_with( mock_instance.name) self._vmops._vmutils.get_vm_summary_info.assert_called_once_with( mock_instance.name) self.assertEqual(response, expected)
def test_get_info(self, mock_tx_state, mock_qp, mock_uuid): mock_tx_state.return_value = 'fake-state' self.assertEqual(hardware.InstanceInfo('fake-state'), self.drv.get_info('inst')) mock_uuid.assert_called_once_with('inst') mock_qp.assert_called_once_with( self.drv.adapter, mock_uuid.return_value, 'PartitionState') mock_tx_state.assert_called_once_with(mock_qp.return_value)
def get_info(self, instance): if instance.uuid not in self.instances: raise exception.InstanceNotFound(instance_id=instance.uuid) i = self.instances[instance.uuid] return hardware.InstanceInfo(state=i.state, max_mem_kb=0, mem_kb=0, num_cpu=2, cpu_time_ns=0)
def test_get_info(self, tag, side_effect, expected): instance = stubs._fake_instance() with mock.patch.object(session.LXDAPISession, "container_state", ) as state: state.return_value = side_effect info = self.connection.get_info(instance) self.assertEqual(dir(hardware.InstanceInfo(state=expected, num_cpu=2)), dir(info))
def get_info(self, instance): container_state = self.container_client.client('state', instance=instance.name, host=instance.host) return hardware.InstanceInfo(state=container_state, max_mem_kb=0, mem_kb=0, num_cpu=2, cpu_time_ns=0)
def get_info(self, instance): """Return an InstanceInfo object for the instance.""" try: container = self.client.containers.get(instance.name) except lxd_exceptions.NotFound: raise exception.InstanceNotFound(instance_id=instance.uuid) state = container.state() return hardware.InstanceInfo( state=_get_power_state(state.status_code))
def get_vm_info(adapter, instance): """Get the InstanceInfo for an instance. :param adapter: The pypowervm.adapter.Adapter for the PowerVM REST API. :param instance: nova.objects.instance.Instance object :returns: An InstanceInfo object. """ pvm_uuid = get_pvm_uuid(instance) pvm_state = get_vm_qp(adapter, pvm_uuid, 'PartitionState') nova_state = _translate_vm_state(pvm_state) return hardware.InstanceInfo(nova_state)
def get_info(self, instance): if not self._storage.hasItem(instance.uuid): raise exception.InstanceNotFound(instance_id=instance.uuid) i = self._storage.getItem(instance.uuid) LOG.info("Periodic instance check: %s state: %s" % (instance.uuid, i.serialize())) return hardware.InstanceInfo(state=i.state, max_mem_kb=0, mem_kb=0, num_cpu=2, cpu_time_ns=0)
def get_info(self, instance): """Return an InstanceInfo object for the instance.""" container = self.client.containers.get(instance.name) state = container.state() mem_kb = state.memory['usage'] >> 10 max_mem_kb = state.memory['usage_peak'] >> 10 return hardware.InstanceInfo(state=_get_power_state(state.status_code), max_mem_kb=max_mem_kb, mem_kb=mem_kb, num_cpu=instance.flavor.vcpus, cpu_time_ns=0)
def get_info(self, instance): """Get information about the VM.""" LOG.debug("get_info called for instance", instance=instance) instance_name = instance.name if not self._vmutils.vm_exists(instance_name): raise exception.InstanceNotFound(instance_id=instance.uuid) info = self._vmutils.get_vm_summary_info(instance_name) state = constants.HYPERV_POWER_STATE[info['EnabledState']] return hardware.InstanceInfo(state=state)
def get_info(self, instance): """Get the current status of an instance, by name.""" vm_info = self._vbox_manage.show_vm_info(instance) state = vm_info.get(constants.VM_POWER_STATE) cpu_count = vm_info.get(constants.VM_CPUS, 0) memory = vm_info.get(constants.VM_MEMORY, 0) state = constants.POWER_STATE.get(state, 0) return hardware.InstanceInfo(state=state, max_mem_kb=memory, mem_kb=memory, num_cpu=cpu_count, cpu_time_ns=0)
def get_info(self, instance): if instance.uuid not in self.instances: raise exception.InstanceNotFound(instance_id=instance.uuid) i = self.instances[instance.uuid] power_state = i.state if isfile('/'.join([data_dir, instance.uuid])): with open('/'.join([data_dir, instance.uuid])) as handle: obj = json.load(handle) power_state = obj['power_state'] return hardware.InstanceInfo(state=power_state, max_mem_kb=0, mem_kb=0, num_cpu=2, cpu_time_ns=0)
def test_get_info(self, _get_instance_info): _fake_inst_info = hardware.InstanceInfo(state=0x01, mem_kb=131072, num_cpu=4, cpu_time_ns=330528353, max_mem_kb=1048576) _get_instance_info.return_value = _fake_inst_info fake_inst = fake_instance.fake_instance_obj(self._context, name='fake', power_state=power_state.RUNNING, memory_mb='1024', vcpus='4') inst_info = self.driver.get_info(fake_inst) self.assertEqual(0x01, inst_info.state) self.assertEqual(131072, inst_info.mem_kb) self.assertEqual(4, inst_info.num_cpu) self.assertEqual(330528353, inst_info.cpu_time_ns) self.assertEqual(1048576, inst_info.max_mem_kb)
def get_info(self, instance): """Get information about the VM.""" LOG.debug("get_info called for instance", instance=instance) instance_name = instance.name if not self._vmutils.vm_exists(instance_name): raise exception.InstanceNotFound(instance_id=instance.uuid) info = self._vmutils.get_vm_summary_info(instance_name) state = constants.HYPERV_POWER_STATE[info['EnabledState']] return hardware.InstanceInfo(state=state, max_mem_kb=info['MemoryUsage'], mem_kb=info['MemoryUsage'], num_cpu=info['NumberOfProcessors'], cpu_time_ns=info['UpTime'])
def get_info(self, instance): """Return an InstanceInfo object for the instance.""" try: container = self.client.containers.get(instance.name) except lxd_exceptions.NotFound: raise exception.InstanceNotFound(instance_id=instance.uuid) state = container.state() mem_kb = state.memory['usage'] >> 10 max_mem_kb = state.memory['usage_peak'] >> 10 return hardware.InstanceInfo( state=_get_power_state(state.status_code), max_mem_kb=max_mem_kb, mem_kb=mem_kb, num_cpu=instance.flavor.vcpus, cpu_time_ns=0)
def get_info(self, instance): """Get the current status of an instance.""" power_stat = '' try: power_stat = self._reqh.call('guest_get_power_state', instance['name']) except exception.NovaException as err: if err.kwargs['results']['overallRC'] == 404: # instance not exists LOG.warning("Get power state of non-exist instance: %s", instance['name']) raise exception.InstanceNotFound(instance_id=instance['name']) else: raise power_stat = self._mapping_power_stat(power_stat) _instance_info = hardware.InstanceInfo(power_stat) return _instance_info
def _get_instance_info(self, instance): inst_name = instance['name'] vm_info = self._sdk_api.guest_get_info(inst_name) _instance_info = hardware.InstanceInfo() power_stat = zvmutils.mapping_power_stat(vm_info['power_state']) if ((power_stat == power_state.RUNNING) and (instance['power_state'] == power_state.PAUSED)): # return paused state only previous power state is paused _instance_info.state = power_state.PAUSED else: _instance_info.state = power_stat _instance_info.max_mem_kb = vm_info['max_mem_kb'] _instance_info.mem_kb = vm_info['mem_kb'] _instance_info.num_cpu = vm_info['num_cpu'] _instance_info.cpu_time_ns = vm_info['cpu_time_us'] * 1000 return _instance_info
def get_info(self, instance): if instance.uuid in self._uuid_to_ec2_instance: ec2_instance = self._uuid_to_ec2_instance[instance.uuid] elif 'metadata' in instance and 'ec2_id' in instance['metadata']: ec2_id = instance['metadata']['ec2_id'] ec2_instances = self.ec2_conn.get_only_instances( instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None) if len(ec2_instances) == 0: LOG.warning(_("EC2 instance with ID %s not found") % ec2_id, instance=instance) raise exception.InstanceNotFound(instance_id=instance['name']) ec2_instance = ec2_instances[0] else: raise exception.InstanceNotFound(instance_id=instance['name']) power_state = EC2_STATE_MAP.get(ec2_instance.state) return hardware.InstanceInfo(state=power_state)
def get_info(self, instance): """Get the current status of an instance, by name (not ID!) :param instance: nova.objects.instance.Instance object Returns a dict containing: :state: the running state, one of the power_state codes :max_mem: (int) the maximum memory in KBytes allowed :mem: (int) the memory in KBytes used by the domain :num_cpu: (int) the number of virtual CPUs for the domain :cpu_time: (int) the CPU time used in nanoseconds """ if instance.uuid in self._uuid_to_ec2_instance: ec2_instance = self._uuid_to_ec2_instance[instance.uuid] elif 'metadata' in instance and 'ec2_id' in instance['metadata']: ec2_id = instance['metadata']['ec2_id'] ec2_instances = self.ec2_conn.get_only_instances( instance_ids=[ec2_id], filters=None, dry_run=False, max_results=None) if len(ec2_instances) == 0: LOG.warning(_("EC2 instance with ID %s not found") % ec2_id, instance=instance) raise exception.InstanceNotFound(instance_id=instance['name']) ec2_instance = ec2_instances[0] else: raise exception.InstanceNotFound(instance_id=instance['name']) power_state = EC2_STATE_MAP.get(ec2_instance.state) ec2_flavor = self.ec2_flavor_info.get(ec2_instance.instance_type) memory_mb = ec2_flavor['memory_mb'] vcpus = ec2_flavor['vcpus'] return hardware.InstanceInfo(state=power_state, max_mem_kb=memory_mb, mem_kb=memory_mb, num_cpu=vcpus, cpu_time_ns=0, id=instance.id)
def get_info(self): """Get the current status of an instance.""" power_state = self._mapping_power_state( self._hypervisor.guest_get_power_state( self._instance.name)) return hardware.InstanceInfo(power_state)
def get_info(self, instance): if instance.uuid not in self.instances: raise exception.InstanceNotFound(instance_id=instance.uuid) i = self.instances[instance.uuid] return hardware.InstanceInfo(state=i.state)
def get_info(self, instance): """Get instance info including power state.""" if instance.uuid not in self.instances: raise exception.InstanceNotFound(instance_id=instance.uuid) i = self.instances[instance.uuid] return hardware.InstanceInfo(state=i.power_state)
def get_info(self, instance): compute, project, zone = self.gce_svc, self.gce_project, self.gce_zone gce_id = self._get_gce_name_from_instance(instance) gce_instance = gceutils.get_instance(compute, project, zone, gce_id) power_state = GCE_STATE_MAP[gce_instance['status']] return hardware.InstanceInfo(state=power_state)