'Start/Stop host maintenance window. On start, it triggers
guest VMs evacuation.'

def host_maintenance_mode(self, host, mode):

    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:
                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('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(_('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'))
