Browse Source

Add VM instance create time property for all providers

Rodrigo Antunes 3 years ago
parent
commit
98fc6456d3

+ 11 - 0
cloudbridge/interfaces/resources.py

@@ -562,6 +562,17 @@ class Instance(ObjectLifeCycleMixin, LabeledCloudResource):
         """
         pass
 
+    @abstractproperty
+    def create_time(self):
+        """
+        Get the creation data and time for this instance.
+
+        :rtype: ``DateTime``
+        :return: Creation time for this instance as returned by the cloud
+                 middleware.
+        """
+        pass
+
     @abstractmethod
     def reboot(self):
         """

+ 7 - 0
cloudbridge/providers/aws/resources.py

@@ -301,6 +301,13 @@ class AWSInstance(BaseInstance):
         return self._provider.compute.vm_types.find(
             name=self._ec2_instance.instance_type)[0]
 
+    @property
+    def create_time(self):
+        """
+        Get the instance creation time
+        """
+        return self._ec2_instance.launch_time
+
     def reboot(self):
         self._ec2_instance.reboot()
 

+ 7 - 0
cloudbridge/providers/azure/resources.py

@@ -1125,6 +1125,13 @@ class AzureInstance(BaseInstance):
         return self._provider.compute.vm_types.find(
             name=self.vm_type_id)[0]
 
+    @property
+    def create_time(self):
+        """
+        Get the instance creation time
+        """
+        return self._vm.time_created.strftime("%Y-%m-%dT%H:%M:%S.%f")
+
     def reboot(self):
         """
         Reboot this instance (using the cloud middleware API).

+ 7 - 0
cloudbridge/providers/gcp/resources.py

@@ -882,6 +882,13 @@ class GCPInstance(BaseInstance):
         parsed_uri = self._provider.parse_url(machine_type_uri)
         return GCPVMType(self._provider, parsed_uri.get_resource())
 
+    @property
+    def create_time(self):
+        """
+        Get the instance creation time
+        """
+        return self._gcp_instance.get("creationTimestamp")
+
     @property
     def subnet_id(self):
         """

+ 7 - 0
cloudbridge/providers/openstack/resources.py

@@ -361,6 +361,13 @@ class OpenStackInstance(BaseInstance):
             self._os_instance.flavor.get('id'))
         return OpenStackVMType(self._provider, flavor)
 
+    @property
+    def create_time(self):
+        """
+        Get the instance creation time
+        """
+        return self._os_instance.created
+
     def reboot(self):
         """
         Reboot this instance (using the cloud middleware API).

+ 3 - 0
tests/test_compute_service.py

@@ -168,6 +168,9 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.assertEqual(len(find_zone), 1,
                              "Instance's placement zone could not be "
                              " found in zones list")
+            self.assertIsNotNone(
+                test_instance.create_time,
+                "Instance must have it's creation time")
 
     @helpers.skipIfNoService(['compute.instances', 'compute.images',
                               'compute.vm_types'])