Fix bug in healing on GCP 73/13973/1
authoraguilard <e.dah.tid@telefonica.com>
Wed, 11 Oct 2023 08:43:17 +0000 (08:43 +0000)
committeraguilard <e.dah.tid@telefonica.com>
Wed, 18 Oct 2023 08:00:33 +0000 (10:00 +0200)
Change-Id: Ie847cd9aee788b164e003633f7b3b5134fe80537
Signed-off-by: aguilard <e.dah.tid@telefonica.com>
(cherry picked from commit db612f0c3bc4554bfeeba6a03348a0f9b83919c4)

RO-VIM-gcp/osm_rovim_gcp/vimconn_gcp.py
releasenotes/notes/fix_healing_gcp-b0cf1e8e6db37fb3.yaml [new file with mode: 0644]

index 7e7f606..6532be3 100644 (file)
@@ -907,6 +907,9 @@ class vimconnector(vimconn.VimConnector):
                         ] = "regions/%s/subnetworks/" % self.region + net.get("name")
                 else:
                     net_iface["subnetwork"] = net.get("net_id")
+                if net.get("ip_address"):
+                    net_iface["networkIP"] = net.get("ip_address")
+
                 # In order to get an external IP address, the key "accessConfigs" must be used
                 # in the interace. It has to be of type "ONE_TO_ONE_NAT" and name "External NAT"
                 if net.get("floating_ip", False) or (
@@ -1095,6 +1098,20 @@ class vimconnector(vimconn.VimConnector):
                 )
             )
 
+    def _get_id_from_image(self, image):
+        """
+        Obtains image_id from the google cloud complete image identifier: image_id will be the last five items
+        """
+        self.logger.debug(f"_get_id_from_image begin: image {image}")
+        try:
+            image_id = "/".join(image.split("/")[-5:])
+            self.logger.debug(f"_get_id_from_image Return: image_id {image_id}")
+            return image_id
+        except Exception as e:
+            raise vimconn.VimConnException(
+                f"Unable to get image_id from image '{image}' Error: '{e}'"
+            )
+
     def refresh_nets_status(self, net_list):
         """Get the status of the networks
         Params: the list of network identifiers
@@ -1189,7 +1206,43 @@ class vimconnector(vimconn.VimConnector):
                     .execute()
                 )
 
-                out_vm["vim_info"] = str(vm["name"])
+                disk_source = vm["disks"][0]["source"]
+                self.logger.debug("getting disk information")
+                disk = (
+                    self.conn_compute.disks()
+                    .get(
+                        project=self.project,
+                        zone=self.zone,
+                        disk=self._get_resource_name_from_resource_id(disk_source),
+                    )
+                    .execute()
+                )
+                image = {}
+                if disk is not None:
+                    self.logger.debug(f"disk: {disk}")
+                    image = {
+                        "id": self._get_id_from_image(disk["sourceImage"]),
+                        "source": disk_source,
+                    }
+
+                vim_info = {
+                    "id": vm_id,
+                    "name": vm["name"],
+                    "creationTimestamp": vm["creationTimestamp"],
+                    "lastStartTimestamp": vm["lastStartTimestamp"],
+                    "vm_id": vm["id"],
+                    "kind": vm["kind"],
+                    "cpuPlatform": vm["cpuPlatform"],
+                    "zone": self._get_resource_name_from_resource_id(vm["zone"]),
+                    "machineType": vm["machineType"],
+                    "flavor": {
+                        "id": self._get_resource_name_from_resource_id(
+                            vm["machineType"]
+                        )
+                    },
+                    "image": image,
+                }
+                out_vm["vim_info"] = str(vim_info)
                 out_vm["status"] = self.provision_state2osm.get(vm["status"], "OTHER")
 
                 # In Google Cloud the there is no difference between provision or power status,
@@ -1229,6 +1282,7 @@ class vimconnector(vimconn.VimConnector):
             for network_interface in interfaces:
                 interface_dict = {}
                 interface_dict["vim_interface_id"] = network_interface["name"]
+                interface_dict["vim_net_id"] = network_interface["subnetwork"]
 
                 ips = []
                 ips.append(network_interface["networkIP"])
diff --git a/releasenotes/notes/fix_healing_gcp-b0cf1e8e6db37fb3.yaml b/releasenotes/notes/fix_healing_gcp-b0cf1e8e6db37fb3.yaml
new file mode 100644 (file)
index 0000000..789f5e6
--- /dev/null
@@ -0,0 +1,23 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+---
+fixes:
+  - |
+    Fix a healing bug when a NS is deployed on GCP.
+    Healing operation doesn't work with VMs deployed on GCP due to lack of
+    information in vnfrs required for the operation. That data must be
+    provided by the 'refresh_vms_status' method in the connector.