summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNaveed Massjouni <naveedm9@gmail.com>2011-11-22 16:50:29 -0500
committerNaveed Massjouni <naveedm9@gmail.com>2011-11-28 13:56:32 -0500
commitdd44abb728e592fbd020af7fa362886b1436b968 (patch)
tree035077345750fe94d5209e1d2d84165bd6d09c67
parentc873d2a27891ab9863e7fd64bbc8a6fe7e31bfdf (diff)
downloadnova-dd44abb728e592fbd020af7fa362886b1436b968.tar.gz
nova-dd44abb728e592fbd020af7fa362886b1436b968.tar.xz
nova-dd44abb728e592fbd020af7fa362886b1436b968.zip
Updating {add,remove}_fixed_ip_from_instance in compute.api and compute.manager
to use instance uuid instead of instance id. blueprint internal-uuids Change-Id: I0db18fcbfce24d0cf1b8b9e7c8d10f657ceded0f
-rw-r--r--nova/compute/api.py12
-rw-r--r--nova/compute/manager.py14
-rw-r--r--nova/tests/test_compute.py16
3 files changed, 21 insertions, 21 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 3b8944c6f..418f9e48a 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1307,23 +1307,19 @@ class API(base.Base):
@scheduler_api.reroute_compute("add_fixed_ip")
def add_fixed_ip(self, context, instance, network_id):
"""Add fixed_ip from specified network to given instance."""
- #NOTE(bcwaldon): We need to use the integer id since the
- # network manager doesn't support uuids
- instance_id = instance['id']
+ instance_uuid = instance['uuid']
self._cast_compute_message('add_fixed_ip_to_instance',
context,
- instance_id,
+ instance_uuid,
params=dict(network_id=network_id))
@scheduler_api.reroute_compute("remove_fixed_ip")
def remove_fixed_ip(self, context, instance, address):
"""Remove fixed_ip from specified network to given instance."""
- #NOTE(bcwaldon): We need to use the integer id since the
- # network manager doesn't support uuids
- instance_id = instance['id']
+ instance_uuid = instance['uuid']
self._cast_compute_message('remove_fixed_ip_from_instance',
context,
- instance_id,
+ instance_uuid,
params=dict(address=address))
#TODO(tr3buchet): how to run this in the correct zone?
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index e924c9f9b..b1f32ccda 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1182,15 +1182,16 @@ class ComputeManager(manager.SchedulerDependentManager):
{'status': 'finished', })
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
- @checks_instance_lock
- def add_fixed_ip_to_instance(self, context, instance_id, network_id):
+ @checks_instance_lock_uuid
+ def add_fixed_ip_to_instance(self, context, instance_uuid, network_id):
"""Calls network_api to add new fixed_ip to instance
then injects the new network info and resets instance networking.
"""
+ instance_ref = self.db.instance_get_by_uuid(context, instance_uuid)
+ instance_id = instance_ref['id']
self.network_api.add_fixed_ip_to_instance(context, instance_id,
self.host, network_id)
- instance_ref = self.db.instance_get(context, instance_id)
usage = utils.usage_from_instance(instance_ref)
notifier.notify('compute.%s' % self.host,
'compute.instance.create_ip',
@@ -1200,15 +1201,16 @@ class ComputeManager(manager.SchedulerDependentManager):
self.reset_network(context, instance_id)
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
- @checks_instance_lock
- def remove_fixed_ip_from_instance(self, context, instance_id, address):
+ @checks_instance_lock_uuid
+ def remove_fixed_ip_from_instance(self, context, instance_uuid, address):
"""Calls network_api to remove existing fixed_ip from instance
by injecting the altered network info and resetting
instance networking.
"""
+ instance_ref = self.db.instance_get_by_uuid(context, instance_uuid)
+ instance_id = instance_ref['id']
self.network_api.remove_fixed_ip_from_instance(context, instance_id,
address)
- instance_ref = self.db.instance_get(context, instance_id)
usage = utils.usage_from_instance(instance_ref)
notifier.notify('compute.%s' % self.host,
'compute.instance.delete_ip',
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index a67d16e40..26adae2e3 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -422,12 +422,12 @@ class ComputeTestCase(BaseTestCase):
self.stubs.Set(nova.compute.manager.ComputeManager,
'reset_network', dummy)
- instance_id = self._create_instance()
+ instance = self._create_fake_instance()
+ instance_id = instance['id']
+ instance_uuid = instance['uuid']
self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
- self.compute.add_fixed_ip_to_instance(self.context,
- instance_id,
- 1)
+ self.compute.add_fixed_ip_to_instance(self.context, instance_uuid, 1)
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
self.compute.terminate_instance(self.context, instance_id)
@@ -443,12 +443,14 @@ class ComputeTestCase(BaseTestCase):
self.stubs.Set(nova.compute.manager.ComputeManager,
'reset_network', dummy)
- instance_id = self._create_instance()
+ instance = self._create_fake_instance()
+ instance_id = instance['id']
+ instance_uuid = instance['uuid']
self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
self.compute.remove_fixed_ip_from_instance(self.context,
- instance_id,
- 1)
+ instance_uuid,
+ 1)
self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
self.compute.terminate_instance(self.context, instance_id)