diff options
author | Lingxian Kong <anlin.kong@gmail.com> | 2020-06-09 11:09:22 +1200 |
---|---|---|
committer | Lingxian Kong <anlin.kong@gmail.com> | 2020-06-10 22:41:35 +1200 |
commit | 535417240709694080255c064c9d84a5ab1d5372 (patch) | |
tree | 6fa52ed747e4fb83dc974a2627b344fd69c7a202 /trove/taskmanager | |
parent | b77f7b9fe764f519a7dbfd9026b15db320d4aebd (diff) | |
download | trove-535417240709694080255c064c9d84a5ab1d5372.tar.gz |
Support subnet and IP for instance creation
Support ``subnet_id`` and ``ip_address`` for creating instance. When
creating instance, trove will check the network conflicts between user's
network and the management network, additionally, the cloud admin is
able to define other reserved networks by configuring
``reserved_network_cidrs``.
Change-Id: Icc4eece2f265cb5a5c48c4f1024a9189d11b4687
Diffstat (limited to 'trove/taskmanager')
-rwxr-xr-x | trove/taskmanager/models.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/trove/taskmanager/models.py b/trove/taskmanager/models.py index 104e15fb..afbac20d 100755 --- a/trove/taskmanager/models.py +++ b/trove/taskmanager/models.py @@ -461,7 +461,7 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): skip_delta=CONF.usage_sleep_time + 1 ) - def _create_port(self, network, security_groups, is_mgmt=False, + def _create_port(self, network_info, security_groups, is_mgmt=False, is_public=False): name = 'trove-%s' % self.id type = 'Management' if is_mgmt else 'User' @@ -470,9 +470,11 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): try: port_id = neutron.create_port( self.neutron_client, name, - description, network, + description, network_info.get('network_id'), security_groups, - is_public=is_public + is_public=is_public, + subnet_id=network_info.get('subnet_id'), + ip=network_info.get('ip_address') ) except Exception: error = ("Failed to create %s port for instance %s" @@ -491,6 +493,8 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): 'nics' contains the networks that management network always comes at last. + + returns a list of dicts which only contains port-id. """ LOG.info("Preparing networks for the instance %s", self.id) security_group = None @@ -515,7 +519,7 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): # The management network is always the last one networks.pop(-1) port_id = self._create_port( - CONF.management_networks[-1], + {'network_id': CONF.management_networks[-1]}, port_sgs, is_mgmt=True ) @@ -526,10 +530,10 @@ class FreshInstanceTasks(FreshInstance, NotifyMixin, ConfigurationMixin): # Create port in the user defined network, associate floating IP if # needed if len(networks) > 1 or not CONF.management_networks: - network = networks.pop(0).get("net-id") + network_info = networks.pop(0) port_sgs = [security_group] if security_group else [] port_id = self._create_port( - network, + network_info, port_sgs, is_mgmt=False, is_public=access.get('is_public', False) |