コード例 #1
0
ファイル: test_aggregate.py プロジェクト: wenlongwljs/nova
 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)
コード例 #2
0
ファイル: test_aggregate.py プロジェクト: liunian0o0/nova-1
 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)
コード例 #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
                                })
コード例 #4
0
ファイル: test_db_api.py プロジェクト: NewpTone/stacklab-nova
 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])
コード例 #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)
コード例 #6
0
ファイル: test_db_api.py プロジェクト: NewpTone/stacklab-nova
 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])
コード例 #7
0
ファイル: driver.py プロジェクト: nitishb/nova
 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)
コード例 #8
0
ファイル: test_db_api.py プロジェクト: bhuvan/nova
 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])
コード例 #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)
コード例 #10
0
ファイル: xenapi_conn.py プロジェクト: sagar-r-nikam/nova
 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)
コード例 #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)
コード例 #12
0
ファイル: host.py プロジェクト: chemikadze/nova
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})
コード例 #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
コード例 #14
0
ファイル: fake.py プロジェクト: gajen/nova
 def aggregate_get_by_host(self, context, host, key=None):
     return db.aggregate_get_by_host(context, host, key)
コード例 #15
0
ファイル: aggregate.py プロジェクト: gilmeir/nova
 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)
コード例 #16
0
 def aggregate_get_by_host(self, context, host, key=None):
     return db.aggregate_get_by_host(context, host, key=key)
コード例 #17
0
ファイル: aggregate.py プロジェクト: bopopescu/nova-23
 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)
コード例 #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)
コード例 #19
0
ファイル: aggregate.py プロジェクト: dnguyenutsa/nova
 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)
コード例 #20
0
ファイル: test_db_api.py プロジェクト: matiu2/nova
 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)
コード例 #21
0
ファイル: test_db_api.py プロジェクト: bhuvan/nova
 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'))
コード例 #22
0
ファイル: aggregate.py プロジェクト: allinhtml/nova
 def get_by_host(cls, context, host):
     db_aggregates = db.aggregate_get_by_host(context, host)
     return _make_list(context, AggregateList(), Aggregate, db_aggregates)
コード例 #23
0
ファイル: aggregate.py プロジェクト: 4everming/nova
 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)