def update_status(self): """Since under Xenserver, a compute node runs on a given host, we can get host status information using xenapi. """ LOG.debug("Updating host stats") data = call_xenhost(self._session, "host_data", {}) def _get_total_network_bandwidth (): ethersOut = os.popen('ls -d /sys/class/net/eth*'); ethers = ethersOut.readlines(); totalSpeed = 0; for ether in ethers: cmd = 'cat ' + ether[:-1] + '/speed'; speed = os.popen(cmd); speedInMB = int (speed.read()); totalSpeed = totalSpeed + speedInMB; speed.close(); ethersOut.close(); return totalSpeed; if data: sr_ref = vm_utils.scan_default_sr(self._session) sr_rec = self._session.SR.get_record(sr_ref) total = int(sr_rec["physical_size"]) used = int(sr_rec["physical_utilisation"]) data["disk_total"] = total data["disk_used"] = used data["disk_allocated"] = int(sr_rec["virtual_allocation"]) data["disk_available"] = total - used data["supported_instances"] = to_supported_instances( data.get("host_capabilities") ) host_memory = data.get('host_memory', None) if host_memory: data["host_memory_total"] = host_memory.get('total', 0) data["host_memory_overhead"] = host_memory.get('overhead', 0) data["host_memory_free"] = host_memory.get('free', 0) data["host_memory_free_computed"] = host_memory.get( 'free-computed', 0) del data['host_memory'] if (data['host_hostname'] != self._stats.get('host_hostname', data['host_hostname'])): LOG.error(_('Hostname has changed from %(old)s ' 'to %(new)s. A restart is required to take effect.' ) % {'old': self._stats['host_hostname'], 'new': data['host_hostname']}) data['host_hostname'] = self._stats['host_hostname'] data['hypervisor_hostname'] = data['host_hostname'] vcpus_used = 0 for vm_ref, vm_rec in vm_utils.list_vms(self._session): vcpus_used = vcpus_used + int(vm_rec['VCPUs_max']) data['vcpus_used'] = vcpus_used data['pci_passthrough_devices'] = self._get_passthrough_devices() data['total_bandwidth'] = _get_total_network_bandwidth (); data['bandwidth_used'] = 0; self._stats = data
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation. """ if not mode: return "off_maintenance" host_list = [ host_ref for host_ref in self._session.call_xenapi("host.get_all") if host_ref != self._session.get_xenapi_host() ] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec["other_config"].get("nova_uuid") if not uuid: name = vm_rec["name_label"] uuid = _uuid_find(ctxt, host, name) if not uuid: msg = _( "Instance %(name)s running on %(host)s" " could not be found in the database:" " assuming it is a worker VM and skip" " ping migration to a new host" ) LOG.info(msg % locals()) continue instance = instance_obj.Instance.get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 aggregate = self._virtapi.aggregate_get_by_host(ctxt, host, key=pool_states.POOL_FLAG) if not aggregate: msg = _("Aggregate for host %(host)s count not be" " found.") % dict(host=host) raise exception.NotFound(msg) dest = _host_find(ctxt, self._session, aggregate[0], host_ref) instance.host = dest instance.task_state = task_states.MIGRATING instance.save() self._session.call_xenapi("VM.pool_migrate", vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 instance.vm_state = vm_states.ACTIVE instance.save() break except self._session.XenAPI.Failure: LOG.exception(_("Unable to migrate VM %(vm_ref)s" "from %(host)s") % locals()) instance.host = host instance.vm_state = vm_states.ACTIVE instance.save() if vm_counter == migrations_counter: return "on_maintenance" else: raise exception.NoValidHost(reason="Unable to find suitable " "host for VMs evacuation")
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation.""" if not mode: return "off_maintenance" host_list = [ host_ref for host_ref in self._session.call_xenapi("host.get_all") if host_ref != self._session.get_xenapi_host() ] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec["other_config"].get("nova_uuid") if not uuid: name = vm_rec["name_label"] uuid = _uuid_find(self._virtapi, ctxt, host, name) if not uuid: msg = _( "Instance %(name)s running on %(host)s" " could not be found in the database:" " assuming it is a worker VM and skip" " ping migration to a new host" ) LOG.info(msg % locals()) continue instance = self._virtapi.instance_get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 dest = _host_find(ctxt, self._session, host, host_ref) (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance["uuid"], {"host": dest, "task_state": task_states.MIGRATING} ) notifications.send_update(ctxt, old_ref, new_ref) self._session.call_xenapi("VM.pool_migrate", vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance["uuid"], {"vm_state": vm_states.ACTIVE} ) notifications.send_update(ctxt, old_ref, new_ref) break except self._session.XenAPI.Failure: LOG.exception("Unable to migrate VM %(vm_ref)s" "from %(host)s" % locals()) (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance["uuid"], {"host": host, "vm_state": vm_states.ACTIVE} ) notifications.send_update(ctxt, old_ref, new_ref) if vm_counter == migrations_counter: return "on_maintenance" else: raise exception.NoValidHost(reason="Unable to find suitable " "host for VMs evacuation")
def update_status(self): """Since under Xenserver, a compute node runs on a given host, we can get host status information using xenapi. """ LOG.debug("Updating host stats") data = _call_host_management(self._session, host_management.get_host_data) if data: sr_ref = vm_utils.scan_default_sr(self._session) sr_rec = self._session.SR.get_record(sr_ref) total = int(sr_rec["physical_size"]) (allocated, used) = self.get_disk_used(sr_ref) data["disk_total"] = total data["disk_used"] = used data["disk_allocated"] = allocated data["disk_available"] = total - used data["supported_instances"] = to_supported_instances( data.get("host_capabilities") ) data["cpu_model"] = to_cpu_model( data.get("host_cpu_info") ) host_memory = data.get('host_memory', None) if host_memory: data["host_memory_total"] = host_memory.get('total', 0) data["host_memory_overhead"] = host_memory.get('overhead', 0) data["host_memory_free"] = host_memory.get('free', 0) data["host_memory_free_computed"] = host_memory.get( 'free-computed', 0) del data['host_memory'] if (data['host_hostname'] != self._stats.get('host_hostname', data['host_hostname'])): LOG.error('Hostname has changed from %(old)s to %(new)s. ' 'A restart is required to take effect.', {'old': self._stats['host_hostname'], 'new': data['host_hostname']}) data['host_hostname'] = self._stats['host_hostname'] data['hypervisor_hostname'] = data['host_hostname'] vcpus_used = 0 for vm_ref, vm_rec in vm_utils.list_vms(self._session): vcpus_used = vcpus_used + int(vm_rec['VCPUs_max']) data['vcpus_used'] = vcpus_used data['pci_passthrough_devices'] = self._get_passthrough_devices() data['vgpu_stats'] = self._get_vgpu_stats() self._stats = data
def update_status(self): """Since under Xenserver, a compute node runs on a given host, we can get host status information using xenapi. """ LOG.debug(_("Updating host stats")) data = call_xenhost(self._session, "host_data", {}) if data: sr_ref = vm_utils.scan_default_sr(self._session) sr_rec = self._session.call_xenapi("SR.get_record", sr_ref) total = int(sr_rec["physical_size"]) used = int(sr_rec["physical_utilisation"]) data["disk_total"] = total data["disk_used"] = used data["disk_available"] = total - used data["supported_instances"] = to_supported_instances( data.get("host_capabilities") ) host_memory = data.get('host_memory', None) if host_memory: data["host_memory_total"] = host_memory.get('total', 0) data["host_memory_overhead"] = host_memory.get('overhead', 0) data["host_memory_free"] = host_memory.get('free', 0) data["host_memory_free_computed"] = host_memory.get( 'free-computed', 0) del data['host_memory'] if (data['host_hostname'] != self._stats.get('host_hostname', data['host_hostname'])): LOG.error(_('Hostname has changed from %(old)s ' 'to %(new)s. A restart is required to take effect.' ) % {'old': self._stats['host_hostname'], 'new': data['host_hostname']}) data['host_hostname'] = self._stats['host_hostname'] data['hypervisor_hostname'] = data['host_hostname'] vcpus_used = 0 for vm_ref, vm_rec in vm_utils.list_vms(self._session): vcpus_used = vcpus_used + int(vm_rec['VCPUs_max']) data['vcpus_used'] = vcpus_used self._stats = data
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation. """ if not mode: return 'off_maintenance' host_list = [host_ref for host_ref in self._session.host.get_all() if host_ref != self._session.host_ref] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] uuid = _uuid_find(ctxt, host, name) if not uuid: LOG.info(_LI('Instance %(name)s running on ' '%(host)s could not be found in ' 'the database: assuming it is a ' 'worker VM and skip ping migration ' 'to a new host'), {'name': name, 'host': host}) continue instance = objects.Instance.get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 aggregate = objects.AggregateList.get_by_host( ctxt, host, key=pool_states.POOL_FLAG) if not aggregate: msg = _('Aggregate for host %(host)s count not be' ' found.') % dict(host=host) raise exception.NotFound(msg) dest = _host_find(ctxt, self._session, aggregate[0], host_ref) instance.host = dest instance.task_state = task_states.MIGRATING instance.save() self._session.VM.pool_migrate(vm_ref, host_ref, {"live": "true"}) migrations_counter = migrations_counter + 1 instance.vm_state = vm_states.ACTIVE instance.save() break except self._session.XenAPI.Failure: LOG.exception(_LE('Unable to migrate VM %(vm_ref)s ' 'from %(host)s'), {'vm_ref': vm_ref, 'host': host}) instance.host = host instance.vm_state = vm_states.ACTIVE instance.save() if vm_counter == migrations_counter: return 'on_maintenance' else: raise exception.NoValidHost(reason='Unable to find suitable ' 'host for VMs evacuation')
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation.""" if not mode: return 'off_maintenance' host_list = [ host_ref for host_ref in self._session.call_xenapi('host.get_all') if host_ref != self._session.get_xenapi_host() ] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] uuid = _uuid_find(self._virtapi, ctxt, host, name) if not uuid: msg = _('Instance %(name)s running on %(host)s' ' could not be found in the database:' ' assuming it is a worker VM and skip' ' ping migration to a new host') LOG.info(msg % locals()) continue instance = self._virtapi.instance_get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 aggregate = self._virtapi.aggregate_get_by_host( ctxt, host, key=pool_states.POOL_FLAG) if not aggregate: msg = _('Aggregate for host %(host)s count not be' ' found.') % dict(host=host) raise exception.NotFound(msg) dest = _host_find(ctxt, self._session, aggregate[0], host_ref) (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], { 'host': dest, 'task_state': task_states.MIGRATING }) notifications.send_update(ctxt, old_ref, new_ref) self._session.call_xenapi('VM.pool_migrate', vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], {'vm_state': vm_states.ACTIVE}) notifications.send_update(ctxt, old_ref, new_ref) break except self._session.XenAPI.Failure: LOG.exception('Unable to migrate VM %(vm_ref)s' 'from %(host)s' % locals()) (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], { 'host': host, 'vm_state': vm_states.ACTIVE }) notifications.send_update(ctxt, old_ref, new_ref) if vm_counter == migrations_counter: return 'on_maintenance' else: raise exception.NoValidHost(reason='Unable to find suitable ' 'host for VMs evacuation')
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation. """ if not mode: return 'off_maintenance' host_list = [ host_ref for host_ref in self._session.host.get_all() if host_ref != self._session.host_ref ] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] uuid = _uuid_find(ctxt, host, name) if not uuid: LOG.info( _LI('Instance %(name)s running on ' '%(host)s could not be found in ' 'the database: assuming it is a ' 'worker VM and skip ping migration ' 'to a new host'), { 'name': name, 'host': host }) continue instance = objects.Instance.get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 aggregate = objects.AggregateList.get_by_host( ctxt, host, key=pool_states.POOL_FLAG) if not aggregate: msg = _('Aggregate for host %(host)s count not be' ' found.') % dict(host=host) raise exception.NotFound(msg) dest = _host_find(ctxt, self._session, aggregate[0], host_ref) instance.host = dest instance.task_state = task_states.MIGRATING instance.save() self._session.VM.pool_migrate(vm_ref, host_ref, {"live": "true"}) migrations_counter = migrations_counter + 1 instance.vm_state = vm_states.ACTIVE instance.save() break except XenAPI.Failure: LOG.exception( _LE('Unable to migrate VM %(vm_ref)s ' 'from %(host)s'), { 'vm_ref': vm_ref, 'host': host }) instance.host = host instance.vm_state = vm_states.ACTIVE instance.save() if vm_counter == migrations_counter: return 'on_maintenance' else: raise exception.NoValidHost(reason=_('Unable to find suitable ' 'host for VMs evacuation'))
def host_maintenance_mode(self, host, mode): """Start/Stop host maintenance window. On start, it triggers guest VMs evacuation.""" if not mode: return 'off_maintenance' host_list = [host_ref for host_ref in self._session.call_xenapi('host.get_all') if host_ref != self._session.get_xenapi_host()] migrations_counter = vm_counter = 0 ctxt = context.get_admin_context() for vm_ref, vm_rec in vm_utils.list_vms(self._session): for host_ref in host_list: try: # Ensure only guest instances are migrated uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] uuid = _uuid_find(ctxt, host, name) if not uuid: msg = _('Instance %(name)s running on %(host)s' ' could not be found in the database:' ' assuming it is a worker VM and skip' ' ping migration to a new host') LOG.info(msg % locals()) continue instance = db.instance_get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 dest = _host_find(ctxt, self._session, host, host_ref) (old_ref, new_ref) = db.instance_update_and_get_original( ctxt, instance['uuid'], {'host': dest, 'task_state': task_states.MIGRATING}) notifications.send_update(ctxt, old_ref, new_ref) self._session.call_xenapi('VM.pool_migrate', vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 (old_ref, new_ref) = db.instance_update_and_get_original( ctxt, instance['uuid'], {'vm_state': vm_states.ACTIVE}) notifications.send_update(ctxt, old_ref, new_ref) break except self._session.XenAPI.Failure: LOG.exception('Unable to migrate VM %(vm_ref)s' 'from %(host)s' % locals()) (old_ref, new_ref) = db.instance_update_and_get_original( ctxt, instance['uuid'], {'hosts': host, 'vm_state': vm_states.ACTIVE}) notifications.send_update(ctxt, old_ref, new_ref) if vm_counter == migrations_counter: return 'on_maintenance' else: raise exception.NoValidHost(reason='Unable to find suitable ' 'host for VMs evacuation')