Disable the check of the release notes
[osm/RO.git] / RO-VIM-gcp / osm_rovim_gcp / vimconn_gcp.py
index 97acfe7..0109bf1 100644 (file)
@@ -37,7 +37,6 @@ if getenv("OSMRO_PDB_DEBUG"):
 
 
 class vimconnector(vimconn.VimConnector):
-
     # Translate Google Cloud provisioning state to OSM provision state
     # The first three ones are the transitional status once a user initiated action has been requested
     # Once the operation is complete, it will transition into the states Succeeded or Failed
@@ -184,7 +183,9 @@ class vimconnector(vimconn.VimConnector):
 
             try:
                 # Set to client created
-                self.conn_compute = googleapiclient.discovery.build("compute", "v1")
+                self.conn_compute = googleapiclient.discovery.build(
+                    "compute", "v1", credentials=self.credentials
+                )
             except Exception as e:
                 self._format_vimconn_exception(e)
 
@@ -303,7 +304,6 @@ class vimconnector(vimconn.VimConnector):
         self.logger.debug("create network name %s, ip_profile %s", net_name, ip_profile)
 
         try:
-
             self.logger.debug("creating network_name: {}".format(net_name))
 
             network = "projects/{}/global/networks/default".format(self.project)
@@ -372,7 +372,6 @@ class vimconnector(vimconn.VimConnector):
         )
 
         try:
-
             self.logger.debug("creating subnet_name: {}".format(subnet_name))
 
             subnetwork_body = {
@@ -421,7 +420,6 @@ class vimconnector(vimconn.VimConnector):
         )
 
         try:
-
             if self.reload_client:
                 self._reload_connection()
 
@@ -501,7 +499,6 @@ class vimconnector(vimconn.VimConnector):
         self.logger.debug("Deleting network: {}".format(str(net_id)))
 
         try:
-
             net_name = self._get_resource_name_from_resource_id(net_id)
 
             # Check associated VMs
@@ -907,11 +904,14 @@ class vimconnector(vimconn.VimConnector):
                     if not net.get("name"):
                         continue
                     else:
-                        net_iface[
-                            "subnetwork"
-                        ] = "regions/%s/subnetworks/" % self.region + net.get("name")
+                        net_iface["subnetwork"] = (
+                            "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 (
@@ -1100,6 +1100,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
@@ -1194,7 +1208,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,
@@ -1234,6 +1284,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"])