def get_available_resource(self, nodename): if not hasattr(self, '_nodename'): self._nodename = nodename if nodename != self._nodename: LOG.error(_('Hostname has changed from %(old)s to %(new)s. ' 'A restart is required to take effect.' ), {'old': self._nodename, 'new': nodename}) memory = hostinfo.get_memory_usage() disk = hostinfo.get_disk_usage() stats = { 'vcpus': hostinfo.get_total_vcpus(), 'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)), 'memory_mb': memory['total'] / units.Mi, 'memory_mb_used': memory['used'] / units.Mi, 'local_gb': disk['total'] / units.Gi, 'local_gb_used': disk['used'] / units.Gi, 'disk_available_least': disk['available'] / units.Gi, 'hypervisor_type': 'docker', 'hypervisor_version': utils.convert_version_to_int('1.0'), 'hypervisor_hostname': self._nodename, 'cpu_info': '?', 'supported_instances': jsonutils.dumps([ ('i686', 'docker', 'lxc'), ('x86_64', 'docker', 'lxc') ]) } return stats
def get_available_resource(self, nodename): if not hasattr(self, '_nodename'): self._nodename = nodename if nodename != self._nodename: LOG.error(_('Hostname has changed from %(old)s to %(new)s. ' 'A restart is required to take effect.' ), {'old': self._nodename, 'new': nodename}) memory = hostinfo.get_memory_usage() disk = hostinfo.get_disk_usage() stats = { 'vcpus': hostinfo.get_total_vcpus(), 'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)), 'memory_mb': memory['total'] / units.Mi, 'memory_mb_used': memory['used'] / units.Mi, 'local_gb': disk['total'] / units.Gi, 'local_gb_used': disk['used'] / units.Gi, 'disk_available_least': disk['available'] / units.Gi, 'hypervisor_type': 'docker', 'hypervisor_version': utils.convert_version_to_int('1.0'), 'hypervisor_hostname': self._nodename, 'cpu_info': '?', 'supported_instances': jsonutils.dumps([ (arch.I686, hv_type.DOCKER, vm_mode.EXE), (arch.X86_64, hv_type.DOCKER, vm_mode.EXE) ]) } return stats
def get_available_resource(self, nodename): if not hasattr(self, '_nodename'): self._nodename = nodename if nodename != self._nodename: LOG.error( _('Hostname has changed from %(old)s to %(new)s. ' 'A restart is required to take effect.'), { 'old': self._nodename, 'new': nodename }) memory = hostinfo.get_memory_usage() disk = hostinfo.get_disk_usage() stats = { 'vcpus': hostinfo.get_total_vcpus(), 'vcpus_used': hostinfo.get_vcpus_used(self.list_instances(True)), 'memory_mb': memory['total'] / units.Mi, 'memory_mb_used': memory['used'] / units.Mi, 'local_gb': disk['total'] / units.Gi, 'local_gb_used': disk['used'] / units.Gi, 'disk_available_least': disk['available'] / units.Gi, 'hypervisor_type': 'docker', 'hypervisor_version': versionutils.convert_version_to_int('1.0'), 'hypervisor_hostname': self._nodename, 'cpu_info': '?', 'numa_topology': None, # zy: pay attention that if you do not define supported_instance,you won't start an container from this node # zy: add new architectures 'supported_instances': [(arch.I686, hv_type.DOCKER, vm_mode.EXE), (arch.X86_64, hv_type.DOCKER, vm_mode.EXE), (arch.ARMV7, hv_type.DOCKER, vm_mode.EXE), (arch.AARCH64, hv_type.DOCKER, vm_mode.EXE), (arch.PPC64LE, hv_type.DOCKER, vm_mode.EXE)] } return stats
def test_get_total_vcpus(self, mock_cpu_count): mock_cpu_count.return_value = 1 cpu_count = hostinfo.get_total_vcpus() self.assertEqual(mock_cpu_count.return_value, cpu_count)