diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-11-02 22:47:46 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-11-02 22:47:46 +0000 |
| commit | c68833a6d99d4f69abb7a7f2bf0401044a252a6f (patch) | |
| tree | 1ea212197c6ed6432b0bd00a54df95088a10cbb8 /nova | |
| parent | 29568d0be0b4cad99a21a53438a2c95540f9ea87 (diff) | |
| parent | 8a134759982a497118acbee328a01b00e9cb2a44 (diff) | |
| download | nova-c68833a6d99d4f69abb7a7f2bf0401044a252a6f.tar.gz nova-c68833a6d99d4f69abb7a7f2bf0401044a252a6f.tar.xz nova-c68833a6d99d4f69abb7a7f2bf0401044a252a6f.zip | |
Merge "Remove db.instance_get* from nova/virt"
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/compute/manager.py | 6 | ||||
| -rw-r--r-- | nova/virt/fake.py | 6 | ||||
| -rw-r--r-- | nova/virt/virtapi.py | 14 | ||||
| -rw-r--r-- | nova/virt/xenapi/driver.py | 2 | ||||
| -rw-r--r-- | nova/virt/xenapi/host.py | 17 |
5 files changed, 36 insertions, 9 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f45f4e28f..74f8aade2 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -220,6 +220,12 @@ class ComputeVirtAPI(virtapi.VirtAPI): instance_uuid, updates) + def instance_get_by_uuid(self, context, instance_uuid): + return self._compute.db.instance_get_by_uuid(context, instance_uuid) + + def instance_get_all_by_host(self, context, host): + return self._compute.db.instance_get_all_by_host(context, host) + class ComputeManager(manager.SchedulerDependentManager): """Manages the running instances from creation to destruction.""" diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 53bfd398c..03711fe98 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -344,3 +344,9 @@ class FakeVirtAPI(virtapi.VirtAPI): return db.instance_update_and_get_original(context, instance_uuid, updates) + + def instance_get_by_uuid(self, context, instance_uuid): + return db.instance_get_by_uuid(context, instance_uuid) + + def instance_get_all_by_host(self, context, host): + return db.instance_get_all_by_host(context, host) diff --git a/nova/virt/virtapi.py b/nova/virt/virtapi.py index 15a45b7d9..13aaa7e4d 100644 --- a/nova/virt/virtapi.py +++ b/nova/virt/virtapi.py @@ -28,3 +28,17 @@ class VirtAPI(object): Returns: orig_instance, new_instance """ raise NotImplementedError() + + def instance_get_by_uuid(self, context, instance_uuid): + """Look up an instance by uuid + :param context: security context + :param instance_uuid: uuid of the instance to be fetched + """ + raise NotImplementedError() + + def instance_get_all_by_host(self, context, host): + """Find all instances on a given host + :param context: security context + :param host: host running instances to be returned + """ + raise NotImplementedError() diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index 3be1ba260..e4c4150a8 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -140,7 +140,7 @@ class XenAPIDriver(driver.ComputeDriver): self._session = XenAPISession(url, username, password) self._volumeops = volumeops.VolumeOps(self._session) self._host_state = None - self._host = host.Host(self._session) + self._host = host.Host(self._session, self.virtapi) self._vmops = vmops.VMOps(self._session, self.virtapi) self._initiator = None self._hypervisor_hostname = None diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 5186a40ce..8a69f7c54 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -38,8 +38,9 @@ class Host(object): """ Implements host related operations. """ - def __init__(self, session): + def __init__(self, session, virtapi): self._session = session + self._virtapi = virtapi def host_power_action(self, _host, action): """Reboots or shuts down the host.""" @@ -65,7 +66,7 @@ class Host(object): uuid = vm_rec['other_config'].get('nova_uuid') if not uuid: name = vm_rec['name_label'] - uuid = _uuid_find(ctxt, host, name) + uuid = _uuid_find(self._virtapi, ctxt, host, name) if not uuid: msg = _('Instance %(name)s running on %(host)s' ' could not be found in the database:' @@ -73,11 +74,11 @@ class Host(object): ' ping migration to a new host') LOG.info(msg % locals()) continue - instance = db.instance_get_by_uuid(ctxt, uuid) + instance = self._virtapi.instance_get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 dest = _host_find(ctxt, self._session, host, host_ref) - (old_ref, new_ref) = db.instance_update_and_get_original( + (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], {'host': dest, @@ -88,7 +89,7 @@ class Host(object): vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 - (old_ref, new_ref) = db.instance_update_and_get_original( + (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], {'vm_state': vm_states.ACTIVE}) @@ -98,7 +99,7 @@ class Host(object): except self._session.XenAPI.Failure: LOG.exception('Unable to migrate VM %(vm_ref)s' 'from %(host)s' % locals()) - (old_ref, new_ref) = db.instance_update_and_get_original( + (old_ref, new_ref) = self._virtapi.instance_update( ctxt, instance['uuid'], {'host': host, @@ -212,9 +213,9 @@ def call_xenhost(session, method, arg_dict): return e.details[1] -def _uuid_find(context, host, name_label): +def _uuid_find(virtapi, context, host, name_label): """Return instance uuid by name_label.""" - for i in db.instance_get_all_by_host(context, host): + for i in virtapi.instance_get_all_by_host(context, host): if i.name == name_label: return i['uuid'] return None |
