diff options
| author | Eldar Nugaev <enugaev@griddynamics.com> | 2011-04-22 06:46:28 +0000 |
|---|---|---|
| committer | Tarmac <> | 2011-04-22 06:46:28 +0000 |
| commit | fdab470f28a2cb8ef0c4d174241e5a6dc362a21d (patch) | |
| tree | ae40fd91c27313fcd31ab4d040ae0a3edd55d679 /nova/compute | |
| parent | c028a791c8434a3c58ff1c7e0cd02b2f9f5b8417 (diff) | |
| parent | 5904cba617038600f3d8e7f65c71485abb163927 (diff) | |
Provide option of auto assigning floating ip to each instance. Depend on auto_assign_floating_ip boolean flag value. False by default.
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/manager.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 86a9e87b0..307e0a2ff 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -37,8 +37,6 @@ terminating it. import datetime import os -import random -import string import socket import sys import tempfile @@ -50,6 +48,7 @@ from nova import exception from nova import flags from nova import log as logging from nova import manager +from nova import network from nova import rpc from nova import utils from nova import volume @@ -75,6 +74,8 @@ flags.DEFINE_integer('live_migration_retry_count', 30, flags.DEFINE_integer("rescue_timeout", 0, "Automatically unrescue an instance after N seconds." " Set to 0 to disable.") +flags.DEFINE_bool('auto_assign_floating_ip', False, + 'Autoassigning floating ip to VM') LOG = logging.getLogger('nova.compute.manager') @@ -128,6 +129,7 @@ class ComputeManager(manager.SchedulerDependentManager): self.network_manager = utils.import_object(FLAGS.network_manager) self.volume_manager = utils.import_object(FLAGS.volume_manager) + self.network_api = network.API() super(ComputeManager, self).__init__(service_name="compute", *args, **kwargs) @@ -248,6 +250,18 @@ class ComputeManager(manager.SchedulerDependentManager): instance_id, power_state.SHUTDOWN) + if not FLAGS.stub_network and FLAGS.auto_assign_floating_ip: + public_ip = self.network_api.allocate_floating_ip(context) + + self.db.floating_ip_set_auto_assigned(context, public_ip) + fixed_ip = self.db.fixed_ip_get_by_address(context, address) + floating_ip = self.db.floating_ip_get_by_address(context, + public_ip) + + self.network_api.associate_floating_ip(context, + floating_ip, + fixed_ip, + affect_auto_assigned=True) self._update_state(context, instance_id) @exception.wrap_exception @@ -268,13 +282,17 @@ class ComputeManager(manager.SchedulerDependentManager): # NOTE(vish): Right now we don't really care if the ip is # disassociated. We may need to worry about # checking this later. - network_topic = self.db.queue_get_for(context, - FLAGS.network_topic, - floating_ip['host']) - rpc.cast(context, - network_topic, - {"method": "disassociate_floating_ip", - "args": {"floating_address": address}}) + self.network_api.disassociate_floating_ip(context, + address, + True) + if (FLAGS.auto_assign_floating_ip + and floating_ip.get('auto_assigned')): + LOG.debug(_("Deallocating floating ip %s"), + floating_ip['address'], + context=context) + self.network_api.release_floating_ip(context, + address, + True) address = fixed_ip['address'] if address: |
