Просмотр исходного кода

Renamed property names for consistency
Instance.instance_type_id property added.
Instance.placement_zone renamed to instance.zone_id

Nuwan Goonasekera 10 лет назад
Родитель
Сommit
1da0a04b12

+ 17 - 4
cloudbridge/cloud/interfaces/resources.py

@@ -477,13 +477,26 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
         """
         pass
 
+    @abstractproperty
+    def instance_type_id(self):
+        """
+        Get the instance type id for this instance. This will typically be a
+        string value like 'm1.large'. On OpenStack, this may be a number or
+        UUID. To get the full :class:``.InstanceType``
+        object, you can use the instance.instance_type property instead.
+
+        :rtype: :class:``str``
+        :return: Instance type name for this instance (e.g., ``m1.large``)
+        """
+        pass
+
     @abstractproperty
     def instance_type(self):
         """
-        Get the instance type.
+        Retrieve full instance type information for this instance.
 
         :rtype: :class:``.InstanceType``
-        :return: API type of this instance (e.g., ``m1.large``)
+        :return: Instance type for this instance
         """
         pass
 
@@ -519,9 +532,9 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
         pass
 
     @abstractproperty
-    def placement_zone(self):
+    def zone_id(self):
         """
-        Get the placement zone where this instance is running.
+        Get the placement zone ID where this instance is running.
 
         :rtype: str
         :return: Region/zone/placement where this instance is running.

+ 9 - 2
cloudbridge/cloud/providers/aws/resources.py

@@ -253,6 +253,13 @@ class AWSInstance(BaseInstance):
         """
         return [self._ec2_instance.private_ip_address]
 
+    @property
+    def instance_type_id(self):
+        """
+        Get the instance type name.
+        """
+        return self._ec2_instance.instance_type
+
     @property
     def instance_type(self):
         """
@@ -281,9 +288,9 @@ class AWSInstance(BaseInstance):
         return self._ec2_instance.image_id
 
     @property
-    def placement_zone(self):
+    def zone_id(self):
         """
-        Get the placement zone where this instance is running.
+        Get the placement zone id where this instance is running.
         """
         return self._ec2_instance.placement
 

+ 9 - 2
cloudbridge/cloud/providers/openstack/resources.py

@@ -268,10 +268,17 @@ class OpenStackInstance(BaseInstance):
                 for address in addresses
                 if ipaddress.ip_address(address).is_private]
 
+    @property
+    def instance_type_id(self):
+        """
+        Get the instance type name.
+        """
+        return self._os_instance.flavor.get('id')
+
     @property
     def instance_type(self):
         """
-        Get the instance type.
+        Get the instance type object.
         """
         flavor = self._provider.nova.flavors.get(
             self._os_instance.flavor.get('id'))
@@ -301,7 +308,7 @@ class OpenStackInstance(BaseInstance):
                 if self._os_instance.image else "")
 
     @property
-    def placement_zone(self):
+    def zone_id(self):
         """
         Get the placement zone where this instance is running.
         """

+ 2 - 2
test/test_block_store_service.py

@@ -102,7 +102,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         with helpers.cleanup_action(lambda: test_instance.terminate()):
             name = "CBUnitTestAttachVol-{0}".format(uuid.uuid4())
             test_vol = self.provider.block_store.volumes.create(
-                name, 1, test_instance.placement_zone)
+                name, 1, test_instance.zone_id)
             with helpers.cleanup_action(lambda: test_vol.delete()):
                 test_vol.wait_till_ready()
                 test_vol.attach(test_instance, '/dev/sda2')
@@ -126,7 +126,7 @@ class CloudBlockStoreServiceTestCase(ProviderTestBase):
         with helpers.cleanup_action(lambda: test_instance.terminate()):
             name = "CBUnitTestVolProps-{0}".format(uuid.uuid4())
             test_vol = self.provider.block_store.volumes.create(
-                name, 1, test_instance.placement_zone, description=vol_desc)
+                name, 1, test_instance.zone_id, description=vol_desc)
             with helpers.cleanup_action(lambda: test_vol.delete()):
                 test_vol.wait_till_ready()
                 self.assertTrue(

+ 13 - 5
test/test_compute_service.py

@@ -126,12 +126,12 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.assertEqual(test_instance.image_id, image_id,
                              "Image id {0} is not equal to the expected id"
                              " {1}".format(test_instance.image_id, image_id))
-            self.assertIsInstance(test_instance.placement_zone,
+            self.assertIsInstance(test_instance.zone_id,
                                   six.string_types)
             # FIXME: Moto is not returning the instance's placement zone
 #             find_zone = [zone for zone in
 #                          self.provider.compute.regions.current.zones
-#                          if zone.id == test_instance.placement_zone]
+#                          if zone.id == test_instance.zone_id]
 #             self.assertEqual(len(find_zone), 1,
 #                              "Instance's placement zone could not be "
 #                              " found in zones list")
@@ -158,13 +158,21 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.assertTrue(
                 self._is_valid_ip(ip_address),
                 "Instance must have a valid IP address")
-            self.assertIsInstance(test_instance.instance_type, InstanceType)
+            self.assertIsInstance(test_instance.instance_type_id,
+                                  six.string_types)
+            itype = self.provider.compute.instance_types.get(
+                test_instance.instance_type_id)
+            self.assertEqual(
+                itype, test_instance.instance_type,
+                "Instance type {0} does not match expected type {1}".format(
+                    itype.name, test_instance.instance_type))
+            self.assertIsInstance(itype, InstanceType)
             expected_type = helpers.get_provider_test_data(self.provider,
                                                            'instance_type')
             self.assertEqual(
-                test_instance.instance_type.name, expected_type,
+                itype.name, expected_type,
                 "Instance type {0} does not match expected type {1}".format(
-                    test_instance.instance_type.name, expected_type))
+                    itype.name, expected_type))
 
     def test_block_device_mapping_launch_config(self):
         lc = self.provider.compute.instances.create_launch_config()