コード例 #1
0
ファイル: host.py プロジェクト: hsluoyz/patron
 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.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")
         )
         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(_LE('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()
         self._stats = data
コード例 #2
0
 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.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"))
         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(
                 _LE('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()
         self._stats = data
コード例 #3
0
    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('patron_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')
コード例 #4
0
ファイル: host.py プロジェクト: hsluoyz/patron
    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('patron_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')