Merge "Updating {add,remove}_fixed_ip_from_instance in compute.api and compute.manager to use instance uuid instead of instance id. blueprint internal-uuids"
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -1196,15 +1196,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',
|
||||
@@ -1214,15 +1215,16 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
self.reset_network(context, instance_ref['uuid'])
|
||||
|
||||
@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',
|
||||
|
||||
@@ -462,12 +462,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)
|
||||
@@ -483,12 +483,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)
|
||||
|
||||
Reference in New Issue
Block a user