Esempio n. 1
0
 def test_by_host(self):
     self.mox.StubOutWithMock(db, "aggregate_get_by_host")
     db.aggregate_get_by_host(self.context, "fake-host", key=None).AndReturn([fake_aggregate])
     self.mox.ReplayAll()
     aggs = aggregate.AggregateList.get_by_host(self.context, "fake-host")
     self.assertEqual(1, len(aggs))
     self.compare_obj(aggs[0], fake_aggregate, subs=SUBS)
Esempio n. 2
0
 def test_by_host(self):
     self.mox.StubOutWithMock(db, 'aggregate_get_by_host')
     db.aggregate_get_by_host(self.context, 'fake-host', key=None,
                              ).AndReturn([fake_aggregate])
     self.mox.ReplayAll()
     aggs = aggregate.AggregateList.get_by_host(self.context, 'fake-host')
     self.assertEqual(1, len(aggs))
     self.compare_obj(aggs[0], fake_aggregate, subs=SUBS)
Esempio n. 3
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
                                })
Esempio n. 4
0
 def test_aggregate_get_by_host(self):
     """Ensure we can get aggregates by host."""
     ctxt = context.get_admin_context()
     values = {"name": "fake_aggregate2", "availability_zone": "fake_avail_zone"}
     a1 = _create_aggregate_with_hosts(context=ctxt)
     a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
     r1 = db.aggregate_get_by_host(ctxt, "foo.openstack.org")
     self.assertEqual([a1.id, a2.id], [x.id for x in r1])
Esempio n. 5
0
 def get_by_host(cls, context, host, key=None):
     api_db_aggregates = [
         cls._fill_deprecated(agg)
         for agg in _get_by_host_from_db(context, host, key=key)
     ]
     db_aggregates = db.aggregate_get_by_host(context, host, key=key)
     return base.obj_make_list(context, cls(context), objects.Aggregate,
                               db_aggregates + api_db_aggregates)
Esempio n. 6
0
 def test_aggregate_get_by_host_with_key(self):
     """Ensure we can get aggregates by host."""
     ctxt = context.get_admin_context()
     values = {"name": "fake_aggregate2", "availability_zone": "fake_avail_zone"}
     a1 = _create_aggregate_with_hosts(context=ctxt, metadata={"goodkey": "good"})
     a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
     # filter result by key
     r1 = db.aggregate_get_by_host(ctxt, "foo.openstack.org", key="goodkey")
     self.assertEqual([a1.id], [x.id for x in r1])
Esempio n. 7
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)
Esempio n. 8
0
 def test_aggregate_get_by_host_with_key(self):
     """Ensure we can get aggregates by host."""
     ctxt = context.get_admin_context()
     values = {'name': 'fake_aggregate2',
         'availability_zone': 'fake_avail_zone', }
     a1 = _create_aggregate_with_hosts(context=ctxt,
                                       metadata={'goodkey': 'good'})
     a2 = _create_aggregate_with_hosts(context=ctxt, values=values)
     # filter result by key
     r1 = db.aggregate_get_by_host(ctxt, 'foo.openstack.org', key='goodkey')
     self.assertEqual([a1.id], [x.id for x in r1])
Esempio n. 9
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)
Esempio n. 10
0
 def _populate_host_uuid(self):
     if self.is_slave:
         try:
             aggr = db.aggregate_get_by_host(context.get_admin_context(),
                                             FLAGS.host)
             self.host_uuid = aggr.metadetails[FLAGS.host]
         except exception.AggregateHostNotFound:
             LOG.exception(_('Host is member of a pool, but DB '
                             'says otherwise'))
             raise
     else:
         with self._get_session() as session:
             host_ref = session.xenapi.session.get_this_host(session.handle)
             self.host_uuid = session.xenapi.host.get_uuid(host_ref)
Esempio n. 11
0
 def _populate_host_uuid(self):
     if self.is_subordinate:
         try:
             aggr = db.aggregate_get_by_host(context.get_admin_context(),
                                             FLAGS.host)
             self.host_uuid = aggr.metadetails[FLAGS.host]
         except exception.AggregateHostNotFound:
             LOG.exception(
                 _('Host is member of a pool, but DB '
                   'says otherwise'))
             raise
     else:
         with self._get_session() as session:
             host_ref = session.xenapi.session.get_this_host(session.handle)
             self.host_uuid = session.xenapi.host.get_uuid(host_ref)
Esempio n. 12
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)
    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})
Esempio n. 13
0
class XenAPISession(object):
    """The session to invoke XenAPI SDK calls"""
    def __init__(self, url, user, pw):
        self.XenAPI = self.get_imported_xenapi()
        self._sessions = queue.Queue()
        self.host_uuid = None
        exception = self.XenAPI.Failure(
            _("Unable to log in to XenAPI "
              "(is the Dom0 disk full?)"))
        is_slave = False
        for i in xrange(FLAGS.xenapi_connection_concurrent):
            try:
                session = self._create_session(url)
                with timeout.Timeout(FLAGS.xenapi_login_timeout, exception):
                    session.login_with_password(user, pw)
            except self.XenAPI.Failure, e:
                # if user and pw of the master are different, we're doomed!
                if e.details[0] == 'HOST_IS_SLAVE':
                    master = e.details[1]
                    session = self.XenAPI.Session(
                        pool.swap_xapi_host(url, master))
                    session.login_with_password(user, pw)
                    is_slave = True
                else:
                    raise
            self._sessions.put(session)

        if is_slave:
            try:
                aggr = db.aggregate_get_by_host(context.get_admin_context(),
                                                FLAGS.host)
                self.host_uuid = aggr.metadetails[FLAGS.host]
            except exception.AggregateHostNotFound:
                LOG.exception(
                    _('Host is member of a pool, but DB '
                      'says otherwise'))
                raise
Esempio n. 14
0
File: fake.py Progetto: gajen/nova
 def aggregate_get_by_host(self, context, host, key=None):
     return db.aggregate_get_by_host(context, host, key)
Esempio n. 15
0
 def get_by_host(cls, context, host, key=None):
     db_aggregates = db.aggregate_get_by_host(context, host, key=key)
     return base.obj_make_list(context, cls(context), objects.Aggregate, db_aggregates)
Esempio n. 16
0
 def aggregate_get_by_host(self, context, host, key=None):
     return db.aggregate_get_by_host(context, host, key=key)
Esempio n. 17
0
 def get_by_host(cls, context, host, key=None):
     db_aggregates = db.aggregate_get_by_host(context, host, key=key)
     return base.obj_make_list(context, AggregateList(), Aggregate,
                               db_aggregates)
Esempio n. 18
0
 def test_aggregate_get_by_host(self):
     """Ensure we can get an aggregate by host."""
     ctxt = context.get_admin_context()
     r1 = _create_aggregate_with_hosts(context=ctxt)
     r2 = db.aggregate_get_by_host(ctxt, 'foo.openstack.org')
     self.assertEqual(r1.id, r2.id)
Esempio n. 19
0
 def get_by_host(cls, context, host):
     db_aggregates = db.aggregate_get_by_host(context, host)
     return base.obj_make_list(context, AggregateList(), Aggregate,
                               db_aggregates)
Esempio n. 20
0
 def test_aggregate_get_by_host(self):
     """Ensure we can get an aggregate by host."""
     ctxt = context.get_admin_context()
     r1 = _create_aggregate_with_hosts(context=ctxt)
     r2 = db.aggregate_get_by_host(ctxt, 'foo.openstack.org')
     self.assertEqual(r1.id, r2.id)
Esempio n. 21
0
 def test_aggregate_get_by_host_not_found(self):
     """Ensure AggregateHostNotFound is raised with unknown host."""
     ctxt = context.get_admin_context()
     _create_aggregate_with_hosts(context=ctxt)
     self.assertEqual([], db.aggregate_get_by_host(ctxt, 'unknown_host'))
Esempio n. 22
0
 def get_by_host(cls, context, host):
     db_aggregates = db.aggregate_get_by_host(context, host)
     return _make_list(context, AggregateList(), Aggregate, db_aggregates)
Esempio n. 23
0
 def get_by_host(cls, context, host, key=None):
     api_db_aggregates = [cls._fill_deprecated(agg) for agg in
                         _get_by_host_from_db(context, host, key=key)]
     db_aggregates = db.aggregate_get_by_host(context, host, key=key)
     return base.obj_make_list(context, cls(context), objects.Aggregate,
                               db_aggregates + api_db_aggregates)