From 13b33c4dee1885cfba90d7c2161bc7e33afd2a8e Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Tue, 8 Mar 2016 18:03:45 +0100 Subject: [PATCH] Reuse VM if a port is attached to an existing one When a VM is booted with several port, the plugin reuses the already created VM instead of creating a new one. Change-Id: I02b050a921fa46206897e7b80b2b78ad4a5d4ebd Closes-Bug: #1554624 --- .../vnc_client/contrail_res_handler.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/neutron_plugin_contrail/plugins/opencontrail/vnc_client/contrail_res_handler.py b/neutron_plugin_contrail/plugins/opencontrail/vnc_client/contrail_res_handler.py index 04a076c..252c49c 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/vnc_client/contrail_res_handler.py +++ b/neutron_plugin_contrail/plugins/opencontrail/vnc_client/contrail_res_handler.py @@ -96,16 +96,27 @@ class ResourceCreateHandler(ContrailResourceHandler): resource_create_method = None def _resource_create(self, obj): + """Create a new resource. + + If the fq_name is already used, the object uuid is added to + the last fq_name element in order to generate a unique fq_name. + + """ create_method = getattr(self._vnc_lib, self.resource_create_method) try: try: obj_uuid = create_method(obj) # To allow several resources with an identical name - except vnc_exc.RefsExistError: - obj.uuid = str(uuid.uuid4()) - obj.name += '-' + obj.uuid - obj.fq_name[-1] += '-' + obj.uuid - obj_uuid = create_method(obj) + # but different uuids. + except vnc_exc.RefsExistError as e: + if obj.uuid is not None: + raise e + else: + # The fq_name is already used, a new one is generated + obj.uuid = str(uuid.uuid4()) + obj.name += '-' + obj.uuid + obj.fq_name[-1] += '-' + obj.uuid + obj_uuid = create_method(obj) except (vnc_exc.BadRequest, vnc_exc.PermissionDenied) as e: res_type = obj.get_type() self._raise_contrail_exception('BadRequest',