From bfea4c320495efd610eed279dac135a91ead96c6 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Sun, 3 May 2015 23:52:36 -0700 Subject: [PATCH] fill mgmt_url Change-Id: I04b66107380c98411c70b663a9c845345df9bb07 --- tacker/db/vm/vm_db.py | 16 +++++----- tacker/extensions/servicevm.py | 2 +- tacker/tests/unit/services/vm/drivers/noop.py | 2 +- .../unit/services/vm/mgmt_drivers/noop.py | 6 ++-- tacker/vm/drivers/abstract_driver.py | 2 +- tacker/vm/drivers/heat/heat.py | 29 ++++++++++++++++--- tacker/vm/drivers/nova/nova.py | 2 +- tacker/vm/mgmt_drivers/abstract_driver.py | 24 +++++++-------- tacker/vm/mgmt_drivers/rpc/rpc.py | 6 ++-- tacker/vm/plugin.py | 26 +++++++++-------- 10 files changed, 69 insertions(+), 46 deletions(-) diff --git a/tacker/db/vm/vm_db.py b/tacker/db/vm/vm_db.py index b6df80b6f..028f991f3 100644 --- a/tacker/db/vm/vm_db.py +++ b/tacker/db/vm/vm_db.py @@ -182,7 +182,7 @@ class ServiceInstance(model_base.BASE, models_v1.HasId, models_v1.HasTenant): # For a management tool to talk to manage this service instance. # opaque string. mgmt_driver interprets it. - mgmt_address = sa.Column(sa.String(255), nullable=True) + mgmt_url = sa.Column(sa.String(255), nullable=True) service_context = orm.relationship('ServiceContext') devices = orm.relationship('ServiceDeviceBinding') @@ -348,7 +348,7 @@ class ServiceResourcePluginDb(servicevm.ServiceVMPluginBase, self._make_service_device_list(instance_db.devices) } key_list = ('id', 'tenant_id', 'name', 'service_type_id', - 'service_table_id', 'mgmt_driver', 'mgmt_address', + 'service_table_id', 'mgmt_driver', 'mgmt_url', 'status') res.update((key, instance_db[key]) for key in key_list) return self._fields(res, fields) @@ -659,14 +659,14 @@ class ServiceResourcePluginDb(servicevm.ServiceVMPluginBase, """ :param service_instance_param: dictionary to create instance of ServiceInstance. The following keys are used. - name, service_type_id, service_table_id, mgmt_driver, mgmt_address - mgmt_driver, mgmt_address can be determined later. + name, service_type_id, service_table_id, mgmt_driver, mgmt_url + mgmt_driver, mgmt_url can be determined later. """ name = service_instance_param['name'] service_type_id = service_instance_param['service_type_id'] service_table_id = service_instance_param['service_table_id'] mgmt_driver = service_instance_param.get('mgmt_driver') - mgmt_address = service_instance_param.get('mgmt_address') + mgmt_url = service_instance_param.get('mgmt_url') service_instance_id = str(uuid.uuid4()) LOG.debug('service_instance_id %s device_id %s', @@ -686,7 +686,7 @@ class ServiceResourcePluginDb(servicevm.ServiceVMPluginBase, managed_by_user=managed_by_user, status=constants.PENDING_CREATE, mgmt_driver=mgmt_driver, - mgmt_address=mgmt_address) + mgmt_url=mgmt_url) context.session.add(instance_db) context.session.flush() @@ -702,14 +702,14 @@ class ServiceResourcePluginDb(servicevm.ServiceVMPluginBase, context, service_instance['service_instance'], True) def _update_service_instance_mgmt(self, context, service_instance_id, - mgmt_driver, mgmt_address): + mgmt_driver, mgmt_url): with context.session.begin(subtransactions=True): (self._model_query(context, ServiceInstance). filter(ServiceInstance.id == service_instance_id). filter(ServiceInstance.status == constants.PENDING_CREATE). one(). update({'mgmt_driver': mgmt_driver, - 'mgmt_address': mgmt_address})) + 'mgmt_url': mgmt_url})) def _update_service_instance_pre(self, context, service_instance_id, service_instance): diff --git a/tacker/extensions/servicevm.py b/tacker/extensions/servicevm.py index 99f5d4ce4..8f1cf3f25 100644 --- a/tacker/extensions/servicevm.py +++ b/tacker/extensions/servicevm.py @@ -313,7 +313,7 @@ RESOURCE_ATTRIBUTE_MAP = { # 'validate': {'type:string': None}, # 'is_visible': True, # }, - # 'mgmt_address': { + # 'mgmt_url': { # 'allow_post': True, # 'allow_put': False, # 'validate': {'type:string': None}, diff --git a/tacker/tests/unit/services/vm/drivers/noop.py b/tacker/tests/unit/services/vm/drivers/noop.py index d056f0c26..be6a4ff42 100644 --- a/tacker/tests/unit/services/vm/drivers/noop.py +++ b/tacker/tests/unit/services/vm/drivers/noop.py @@ -52,7 +52,7 @@ class DeviceNoop(abstract_driver.DeviceAbstractDriver): self._instances.add(instance_id) return instance_id - def create_wait(self, plugin, context, device_id): + def create_wait(self, plugin, context, device_dict, device_id): LOG.debug(_('create_wait %s'), device_id) def update(self, plugin, context, device_id, **kwargs): diff --git a/tacker/tests/unit/services/vm/mgmt_drivers/noop.py b/tacker/tests/unit/services/vm/mgmt_drivers/noop.py index b3acefa6f..7051e07d0 100644 --- a/tacker/tests/unit/services/vm/mgmt_drivers/noop.py +++ b/tacker/tests/unit/services/vm/mgmt_drivers/noop.py @@ -37,9 +37,9 @@ class DeviceMgmtNoop(abstract_driver.DeviceMGMTAbstractDriver): def get_description(self): return 'Tacker DeviceMgmt Noop Driver' - def mgmt_address(self, plugin, context, device): - LOG.debug(_('mgmt_address %s'), device) - return 'noop-mgmt-address' + def mgmt_url(self, plugin, context, device): + LOG.debug(_('mgmt_url %s'), device) + return 'noop-mgmt-url' def mgmt_call(self, plugin, context, device, kwargs): LOG.debug(_('mgmt_device_call %(device)s %(kwargs)s'), diff --git a/tacker/vm/drivers/abstract_driver.py b/tacker/vm/drivers/abstract_driver.py index dee593d3c..ef8c3020a 100644 --- a/tacker/vm/drivers/abstract_driver.py +++ b/tacker/vm/drivers/abstract_driver.py @@ -49,7 +49,7 @@ class DeviceAbstractDriver(extensions.PluginInterface): """Create device and return its id.""" @abc.abstractmethod - def create_wait(self, plugin, context, device_id): + def create_wait(self, plugin, context, device_dict, device_id): """wait for device creation to complete.""" @abc.abstractmethod diff --git a/tacker/vm/drivers/heat/heat.py b/tacker/vm/drivers/heat/heat.py index 8de0348e0..3c98e2714 100644 --- a/tacker/vm/drivers/heat/heat.py +++ b/tacker/vm/drivers/heat/heat.py @@ -103,6 +103,8 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver): assert 'template' not in fields assert 'template_url' not in fields template_dict = yaml.load(HEAT_TEMPLATE_BASE) + outputs_dict = {} + template_dict['outputs'] = outputs_dict vnfd_dict = yaml.load(vnfd_yaml) LOG.debug('vnfd_dict %s', vnfd_dict) @@ -124,8 +126,20 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver): for (key, vdu_key) in KEY_LIST: properties[key] = vdu_dict[vdu_key] if 'network_interfaces' in vdu_dict: - properties['networks'] = ( - vdu_dict['network_interfaces'].values()) + # properties['networks'] = ( + # vdu_dict['network_interfaces'].values()) + networks_list = [] + properties['networks'] = networks_list + for network_param in vdu_dict[ + 'network_interfaces'].values(): + if network_param.pop('management', False): + outputs_dict['mgmt_ip'] = { + 'description': 'management ip address', + 'value': { + 'get_attr': [vdu_id, 'networks', + network_param.values()[0], 0]} + } + networks_list.append(network_param) if ('placement_policy' in vdu_dict and 'availability_zone' in vdu_dict['placement_policy']): properties['availability_zone'] = vdu_dict[ @@ -166,7 +180,7 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver): stack = heatclient_.create(fields) return stack['stack']['id'] - def create_wait(self, plugin, context, device_id): + def create_wait(self, plugin, context, device_dict, device_id): heatclient_ = HeatClient(context) stack = heatclient_.get(device_id) @@ -186,7 +200,8 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver): LOG.debug(_('status: %s'), status) stack_retries = stack_retries - 1 - LOG.debug(_('status: %s'), status) + LOG.debug(_('stack status: %(stack)s %(status)s'), + {'stack': stack, 'status': status}) if stack_retries == 0: LOG.warn(_("Resource creation is" " not completed within %(wait)s seconds as " @@ -195,6 +210,12 @@ class DeviceHeat(abstract_driver.DeviceAbstractDriver): 'stack': device_id}) if status != 'CREATE_COMPLETE': raise RuntimeError(_("creation of server %s faild") % device_id) + outputs = stack.outputs + LOG.debug(_('outputs %s'), outputs) + mgmt_ip = [output['output_value'] for output in outputs if + output.get('output_key', None) == 'mgmt_ip'] + if mgmt_ip: + device_dict['mgmt_url'] = mgmt_ip[0] def update(self, plugin, context, device): # do nothing but checking if the stack exists at the moment diff --git a/tacker/vm/drivers/nova/nova.py b/tacker/vm/drivers/nova/nova.py index 18da5b3a3..27da07c84 100644 --- a/tacker/vm/drivers/nova/nova.py +++ b/tacker/vm/drivers/nova/nova.py @@ -225,7 +225,7 @@ class DeviceNova(abstract_driver.DeviceAbstractDriver): instance = nova.servers.create(name, image, flavor, **attributes) return instance.id - def create_wait(self, plugin, context, device_id): + def create_wait(self, plugin, context, device_dict, device_id): nova = self._nova_client() instance = nova.servers.get(device_id) status = instance.status diff --git a/tacker/vm/mgmt_drivers/abstract_driver.py b/tacker/vm/mgmt_drivers/abstract_driver.py index 3411d0896..a41dab6bd 100644 --- a/tacker/vm/mgmt_drivers/abstract_driver.py +++ b/tacker/vm/mgmt_drivers/abstract_driver.py @@ -80,7 +80,7 @@ class DeviceMGMTAbstractDriver(extensions.PluginInterface): return {} @abc.abstractmethod - def mgmt_address(self, plugin, context, device): + def mgmt_url(self, plugin, context, device): pass @abc.abstractmethod @@ -126,7 +126,7 @@ class DeviceMGMTAbstractDriver(extensions.PluginInterface): class DeviceMGMTByNetwork(DeviceMGMTAbstractDriver): - def mgmt_address(self, plugin, context, device): + def mgmt_url(self, plugin, context, device): mgmt_entries = [sc_entry for sc_entry in device.service_context if (sc_entry.role == constants.ROLE_MGMT and sc_entry.port_id)] @@ -135,11 +135,11 @@ class DeviceMGMTByNetwork(DeviceMGMTAbstractDriver): port = plugin._core_plugin.get_port(context, mgmt_entries[0].port_id) if not port: return - mgmt_address = port['fixed_ips'][0] # subnet_id and ip_address - mgmt_address['network_id'] = port['network_id'] - mgmt_address['port_id'] = port['id'] - mgmt_address['mac_address'] = port['mac_address'] - return jsonutils.dumps(mgmt_address) + mgmt_url = port['fixed_ips'][0] # subnet_id and ip_address + mgmt_url['network_id'] = port['network_id'] + mgmt_url['port_id'] = port['id'] + mgmt_url['mac_address'] = port['mac_address'] + return jsonutils.dumps(mgmt_url) def mgmt_service_address(self, plugin, context, device, service_instance): mgmt_entries = [sc_entry for sc_entry @@ -151,8 +151,8 @@ class DeviceMGMTByNetwork(DeviceMGMTAbstractDriver): port = plugin._core_plugin.get_port(context, mgmt_entries[0].port_id) if not port: return - mgmt_address = port['fixed_ips'][0] # subnet_id and ip_address - mgmt_address['network_id'] = port['network_id'] - mgmt_address['port_id'] = port['id'] - mgmt_address['mac_address'] = port['mac_address'] - return jsonutils.dumps(mgmt_address) + mgmt_url = port['fixed_ips'][0] # subnet_id and ip_address + mgmt_url['network_id'] = port['network_id'] + mgmt_url['port_id'] = port['id'] + mgmt_url['mac_address'] = port['mac_address'] + return jsonutils.dumps(mgmt_url) diff --git a/tacker/vm/mgmt_drivers/rpc/rpc.py b/tacker/vm/mgmt_drivers/rpc/rpc.py index 1e79ae184..c9c9d2eb1 100644 --- a/tacker/vm/mgmt_drivers/rpc/rpc.py +++ b/tacker/vm/mgmt_drivers/rpc/rpc.py @@ -77,12 +77,12 @@ class AgentRpcMGMTDriver(abstract_driver.DeviceMGMTAbstractDriver): def _mgmt_topic(self, device): return '%s-%s' % (self._TOPIC, self._mgmt_server(device)) - def mgmt_address(self, plugin, context, device): + def mgmt_url(self, plugin, context, device): return self._address(self._mgmt_topic(device), self._mgmt_server(device)) def mgmt_call(self, plugin, context, device, kwargs): - topic = device['mgmt_address'] + topic = device['mgmt_url'] method = kwargs[constants.KEY_ACTION] kwargs_ = kwargs[constants.KEY_KWARGS] self._rpc_api.rpc_cast(context, method, kwargs_, topic) @@ -103,5 +103,5 @@ class AgentRpcMGMTDriver(abstract_driver.DeviceMGMTAbstractDriver): service_instance, kwargs): method = kwargs[constants.KEY_ACTION] kwargs_ = kwargs[constants.KEY_KWARGS] - topic = service_instance['mgmt_address'] + topic = service_instance['mgmt_url'] self._rpc_api.rpc_cast(context, method, kwargs_, topic) diff --git a/tacker/vm/plugin.py b/tacker/vm/plugin.py index bc75c66db..2697e3721 100644 --- a/tacker/vm/plugin.py +++ b/tacker/vm/plugin.py @@ -169,7 +169,7 @@ class ServiceVMMgmtMixin(object): return self._invoke( device_dict, plugin=self, context=context, device=device_dict) - def mgmt_address(self, context, device_dict): + def mgmt_url(self, context, device_dict): return self._invoke( device_dict, plugin=self, context=context, device=device_dict) @@ -295,26 +295,28 @@ class ServiceVMPlugin(vm_db.ServiceResourcePluginDb, ServiceVMMgmtMixin): try: self._device_manager.invoke( - driver_name, 'create_wait', plugin=self, - context=context, device_id=instance_id) + driver_name, 'create_wait', plugin=self, context=context, + device_dict=device_dict, device_id=instance_id) except servicevm.DeviceCreateWaitFailed: instance_id = None del device_dict['instance_id'] if instance_id is None: - mgmt_address = None + mgmt_url = None else: - mgmt_address = self.mgmt_address(context, device_dict) + # mgmt_url = self.mgmt_url(context, device_dict) + # FIXME(yamahata): + mgmt_url = device_dict['mgmt_url'] self._create_device_post( - context, device_id, instance_id, mgmt_address, + context, device_id, instance_id, mgmt_url, device_dict['service_context']) if instance_id is None: self.mgmt_create_post(context, device_dict) return self.mgmt_create_post(context, device_dict) - device_dict['mgmt_address'] = mgmt_address + device_dict['mgmt_url'] = mgmt_url kwargs = { mgmt_constants.KEY_ACTION: mgmt_constants.ACTION_CREATE_DEVICE, @@ -488,18 +490,18 @@ class ServiceVMPlugin(vm_db.ServiceResourcePluginDb, ServiceVMMgmtMixin): mgmt_driver = self.mgmt_service_driver( context, device_dict, service_instance_dict) service_instance_dict['mgmt_driver'] = mgmt_driver - mgmt_address = self.mgmt_service_address( + mgmt_url = self.mgmt_service_address( context, device_dict, service_instance_dict) - service_instance_dict['mgmt_address'] = mgmt_address + service_instance_dict['mgmt_url'] = mgmt_url LOG.debug(_('service_instance_dict ' '%(service_instance_dict)s ' 'mgmt_driver %(mgmt_driver)s ' - 'mgmt_address %(mgmt_address)s'), + 'mgmt_url %(mgmt_url)s'), {'service_instance_dict': service_instance_dict, - 'mgmt_driver': mgmt_driver, 'mgmt_address': mgmt_address}) + 'mgmt_driver': mgmt_driver, 'mgmt_url': mgmt_url}) self._update_service_instance_mgmt( - context, service_instance_dict['id'], mgmt_driver, mgmt_address) + context, service_instance_dict['id'], mgmt_driver, mgmt_url) self.mgmt_service_create_pre( context, device_dict, service_instance_dict)