summaryrefslogtreecommitdiffstats
path: root/nova/virt
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-08-10 23:01:29 +0000
committerGerrit Code Review <review@openstack.org>2012-08-10 23:01:29 +0000
commit4e596a171f7dc1a4140726b1cfab85976f98243a (patch)
tree8a7912bae5ae360728cae26f2151ba359ac1956f /nova/virt
parent2ef345534afe2d1640dd1d7ad42454d477ca2a94 (diff)
parent861efe3aa7ce6af7b5c548e5a555625fa53a3d86 (diff)
Merge "General host aggregates part 2"
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/xenapi/driver.py13
-rw-r--r--nova/virt/xenapi/host.py6
-rw-r--r--nova/virt/xenapi/pool.py9
-rw-r--r--nova/virt/xenapi/pool_states.py7
-rw-r--r--nova/virt/xenapi/vmops.py6
5 files changed, 25 insertions, 16 deletions
diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py
index 8891e9106..b3e7b6b75 100644
--- a/nova/virt/xenapi/driver.py
+++ b/nova/virt/xenapi/driver.py
@@ -54,11 +54,11 @@ from nova.openstack.common import log as logging
from nova.virt import driver
from nova.virt.xenapi import host
from nova.virt.xenapi import pool
+from nova.virt.xenapi import pool_states
from nova.virt.xenapi import vm_utils
from nova.virt.xenapi import vmops
from nova.virt.xenapi import volumeops
-
LOG = logging.getLogger(__name__)
xenapi_opts = [
@@ -628,13 +628,12 @@ class XenAPISession(object):
def _get_host_uuid(self):
if self.is_slave:
- try:
- aggr = db.aggregate_get_by_host(context.get_admin_context(),
- FLAGS.host)
- except exception.AggregateHostNotFound:
- LOG.exception(_('Host is member of a pool, but DB '
+ 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
+ raise exception.AggregateHostNotFound()
return aggr.metadetails[FLAGS.host]
else:
with self._get_session() as session:
diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py
index df6b4f85d..b45a9106c 100644
--- a/nova/virt/xenapi/host.py
+++ b/nova/virt/xenapi/host.py
@@ -28,6 +28,7 @@ from nova import db
from nova import exception
from nova import notifications
from nova.openstack.common import jsonutils
+from nova.virt.xenapi import pool_states
from nova.virt.xenapi import vm_utils
LOG = logging.getLogger(__name__)
@@ -210,7 +211,10 @@ def _host_find(context, session, src, 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)
+ 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:
diff --git a/nova/virt/xenapi/pool.py b/nova/virt/xenapi/pool.py
index 05592f978..d7204d372 100644
--- a/nova/virt/xenapi/pool.py
+++ b/nova/virt/xenapi/pool.py
@@ -67,14 +67,9 @@ class ResourcePool(object):
LOG.exception(_('Aggregate %(aggregate_id)s: unrecoverable state '
'during operation on %(host)s') % locals())
- def _is_hv_pool(self, context, aggregate_id):
- """Checks if aggregate is a hypervisor_pool"""
- metadata = db.aggregate_metadata_get(context, aggregate_id)
- return pool_states.POOL_FLAG in metadata.keys()
-
def add_to_aggregate(self, context, aggregate, host, **kwargs):
"""Add a compute host to an aggregate."""
- if not self._is_hv_pool(context, aggregate.id):
+ if not pool_states.is_hv_pool(context, aggregate.id):
return
invalid = {pool_states.CHANGING: 'setup in progress',
@@ -126,7 +121,7 @@ class ResourcePool(object):
def remove_from_aggregate(self, context, aggregate, host, **kwargs):
"""Remove a compute host from an aggregate."""
- if not self._is_hv_pool(context, aggregate.id):
+ if not pool_states.is_hv_pool(context, aggregate.id):
return
invalid = {pool_states.CREATED: 'no hosts to remove',
diff --git a/nova/virt/xenapi/pool_states.py b/nova/virt/xenapi/pool_states.py
index 5b3765cfc..82a85ce14 100644
--- a/nova/virt/xenapi/pool_states.py
+++ b/nova/virt/xenapi/pool_states.py
@@ -36,6 +36,7 @@ an 'active' pool goes into an 'error' state. To recover from such a state,
admin intervention is required. Currently an error state is irreversible,
that is, in order to recover from it an pool must be deleted.
"""
+from nova import db
CREATED = 'created'
CHANGING = 'changing'
@@ -46,3 +47,9 @@ DISMISSED = 'dismissed'
# Metadata keys
KEY = 'operational_state'
POOL_FLAG = 'hypervisor_pool'
+
+
+def is_hv_pool(context, aggregate_id):
+ """Checks if aggregate is a hypervisor_pool"""
+ metadata = db.aggregate_metadata_get(context, aggregate_id)
+ return POOL_FLAG in metadata.keys()
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 9f00dc75e..e0bbc5493 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -45,6 +45,7 @@ from nova import utils
from nova.virt import driver
from nova.virt.xenapi import agent
from nova.virt.xenapi import firewall
+from nova.virt.xenapi import pool_states
from nova.virt.xenapi import vm_utils
from nova.virt.xenapi import volume_utils
@@ -1469,7 +1470,10 @@ class VMOps(object):
network_info=network_info)
def _get_host_uuid_from_aggregate(self, context, hostname):
- current_aggregate = db.aggregate_get_by_host(context, FLAGS.host)
+ current_aggregate = db.aggregate_get_by_host(context, FLAGS.host,
+ key=pool_states.POOL_FLAG)[0]
+ if not current_aggregate:
+ raise exception.AggregateHostNotFound(host=FLAGS.host)
try:
return current_aggregate.metadetails[hostname]
except KeyError: