diff options
| author | Joe Gordon <jogo@cloudscaling.com> | 2012-07-24 17:03:56 -0700 |
|---|---|---|
| committer | Joe Gordon <jogo@cloudscaling.com> | 2012-08-07 14:24:53 -0700 |
| commit | 861efe3aa7ce6af7b5c548e5a555625fa53a3d86 (patch) | |
| tree | e156cec40e58e25767a193d453298e1f3b53e30b /nova/virt | |
| parent | ce4b2e27be45a85b310237615c47eb53f37bb5f3 (diff) | |
General host aggregates part 2
Partially implements blueprint general-host-aggregates: Scheduler Filter
* Add AggregateInstanceExtraSpecsFilter
* change db.aggregate_get_by_host to return a list of aggregates
instead of the first aggregate
* Add optional key filter to db.aggregate_get_by_host along with test
* Add db.aggregate_metadata_get_by_host to get host aggregate metadata
* add optional key filter to db.aggregate_metadata_get_by_host
* Add AggregateTypeAffinityFilter
Change-Id: I4a3061276cc3b0c5c695eaf973b773183b3c4f4b
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/driver.py | 13 | ||||
| -rw-r--r-- | nova/virt/xenapi/host.py | 6 | ||||
| -rw-r--r-- | nova/virt/xenapi/pool.py | 9 | ||||
| -rw-r--r-- | nova/virt/xenapi/pool_states.py | 7 | ||||
| -rw-r--r-- | nova/virt/xenapi/vmops.py | 6 |
5 files changed, 25 insertions, 16 deletions
diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index ac4547166..28beffc80 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 = [ @@ -621,13 +621,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 8d443f498..abac03d57 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -44,6 +44,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 @@ -1450,7 +1451,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: |
