示例#1
0
def _host_find(context, session, src, dst):
    """Return the host from the xenapi host reference.

    :param src: the compute host being put in maintenance (source of VMs)
    :param dst: the hypervisor host reference (destination of VMs)

    :return: the compute host that manages dst
    """
    # NOTE: this would be a lot simpler if nova-compute stored
    # FLAGS.host in the XenServer host's other-config map.
    # TODO(armando-migliaccio): improve according the note above
    aggregate = db.aggregate_get_by_host(context,
                                         src,
                                         key=pool_states.POOL_FLAG)[0]
    if not aggregate:
        raise exception.AggregateHostNotFound(host=src)
    uuid = session.call_xenapi('host.get_record', dst)['uuid']
    for compute_host, host_uuid in aggregate.metadetails.iteritems():
        if host_uuid == uuid:
            return compute_host
    raise exception.NoValidHost(reason='Host %(host_uuid)s could not be found '
                                'from aggregate metadata: %(metadata)s.' % {
                                    'host_uuid': uuid,
                                    'metadata': aggregate.metadetails
                                })
示例#2
0
 def test_remove_host_with_host_not_in_aggregate(self):
     side_effect = exception.AggregateHostNotFound(aggregate_id="1",
                                                   host="host1")
     with mock.patch.object(self.controller.api,
                            'remove_host_from_aggregate',
                            side_effect=side_effect) as mock_rem:
         self.assertRaises(exc.HTTPNotFound, eval(self.remove_host),
                           self.req, "1",
                           body={"remove_host": {"host": "host1"}})
         mock_rem.assert_called_once_with(self.context, "1", "host1")
示例#3
0
 def _get_host_uuid(self):
     if self.is_slave:
         aggr = db.aggregate_get_by_host(context.get_admin_context(),
                 FLAGS.host, key=pool_states.POOL_FLAG)[0]
         if not aggr:
             LOG.error(_('Host is member of a pool, but DB '
                             'says otherwise'))
             raise exception.AggregateHostNotFound()
         return aggr.metadetails[FLAGS.host]
     else:
         with self._get_session() as session:
             host_ref = session.xenapi.session.get_this_host(session.handle)
             return session.xenapi.host.get_uuid(host_ref)
示例#4
0
def _host_delete_from_db(context, aggregate_id, host):
    count = 0
    with db_api.api_context_manager.writer.using(context):
        # Check to see if the aggregate exists
        _aggregate_get_from_db(context, aggregate_id)

        query = context.session.query(api_models.AggregateHost)
        query = query.filter(
            api_models.AggregateHost.aggregate_id == aggregate_id)
        count = query.filter_by(host=host).delete()

    if count == 0:
        raise exception.AggregateHostNotFound(aggregate_id=aggregate_id,
                                              host=host)
示例#5
0
 def stub_remove_host_from_aggregate(context, aggregate, host):
     raise exception.AggregateHostNotFound(aggregate_id=aggregate,
                                           host=host)