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

Made id and name top level properties of CloudResource

Nuwan Goonasekera 8 лет назад
Родитель
Сommit
2c94213aef
1 измененных файлов с 37 добавлено и 299 удалено
  1. 37 299
      cloudbridge/cloud/interfaces/resources.py

+ 37 - 299
cloudbridge/cloud/interfaces/resources.py

@@ -28,8 +28,11 @@ class CloudResource(object):
 
     """
     Base interface for any Resource supported by a provider. This interface
-    has an  _provider property that can be used to access the provider
+    has a  _provider property that can be used to access the provider
     associated with the resource, which is only intended for use by subclasses.
+    Every cloudbridge resource also has an id and name property. The id
+    property is a unique identifier for the resource. The name property is a
+    display value.
     """
     __metaclass__ = ABCMeta
 
@@ -44,6 +47,36 @@ class CloudResource(object):
         """
         pass
 
+    @abstractproperty
+    def id(self):
+        """
+        Get the resource identifier. The id property is used to uniquely
+        identify the resource, and is an opaque value which should not be
+        interpreted by cloudbridge clients, and is a value meaningful to
+        the underlying cloud provider.
+
+        :rtype: ``str``
+        :return: ID for this resource as returned by the cloud middleware.
+        """
+        pass
+
+    @abstractproperty
+    def name(self):
+        """
+        Get the resource name. The name property is typically a user-friendly
+        display value for the resource. Some resources may allow the resource
+        name to be set.
+
+        The name property adheres to the following restrictions:
+        * Names cannot be longer than 63 characters
+        * May only contain lowercase letters, numeric characters, underscores,
+          and dashes. International characters are allowed.
+
+        :rtype: ``str``
+        :return: Name for this instance as returned by the cloud middleware.
+        """
+        pass
+
     @abstractmethod
     def to_json(self):
         """
@@ -402,27 +435,7 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the instance identifier.
-
-        :rtype: ``str``
-        :return: ID for this instance as returned by the cloud middleware.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the instance name.
-
-        :rtype: ``str``
-        :return: Name for this instance as returned by the cloud middleware.
-        """
-        pass
-
-    @name.setter
+    @CloudResource.name.setter
     @abstractmethod
     def name(self, value):
         """
@@ -731,26 +744,6 @@ class MachineImage(ObjectLifeCycleMixin, CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the image identifier.
-
-        :rtype: ``str``
-        :return: ID for this instance as returned by the cloud middleware.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the image name.
-
-        :rtype: ``str``
-        :return: Name for this image as returned by the cloud middleware.
-        """
-        pass
-
     @abstractproperty
     def description(self):
         """
@@ -808,27 +801,6 @@ class Network(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the network identifier.
-
-        :rtype: ``str``
-        :return: ID for this network. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the network name.
-
-        :rtype: ``str``
-        :return: Name for this network as returned by the cloud middleware.
-        """
-        pass
-
     @abstractproperty
     def external(self):
         """
@@ -912,27 +884,6 @@ class Subnet(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the subnet identifier.
-
-        :rtype: ``str``
-        :return: ID for this network. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the subnet name.
-
-        :rtype: ``str``
-        :return: Name for this subnet as returned by the cloud middleware.
-        """
-        pass
-
     @abstractproperty
     def cidr_block(self):
         """
@@ -982,17 +933,6 @@ class FloatingIP(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the address identifier.
-
-        :rtype: ``str``
-        :return: ID for this network. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
     @abstractproperty
     def public_ip(self):
         """
@@ -1055,27 +995,6 @@ class Router(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the router identifier.
-
-        :rtype: ``str``
-        :return: ID for this router. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the router name, if available.
-
-        :rtype: ``str``
-        :return: Name for this router.
-        """
-        pass
-
     @abstractmethod
     def refresh(self):
         """
@@ -1229,28 +1148,7 @@ class Volume(ObjectLifeCycleMixin, CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the volume identifier.
-
-        :rtype: ``str``
-        :return: ID for this volume. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the volume name.
-
-        :rtype: ``str``
-        :return: Name for this volume as returned by the cloud middleware.
-        """
-        pass
-
-    @name.setter
+    @CloudResource.name.setter
     @abstractmethod
     def name(self, value):
         """
@@ -1425,25 +1323,7 @@ class Snapshot(ObjectLifeCycleMixin, CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the snapshot identifier.
-
-        :rtype: ``str``
-        :return: ID for this snapshot. Will generally correspond to the cloud
-                 middleware's ID, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get the snapshot name.
-        """
-        pass
-
-    @name.setter
+    @CloudResource.name.setter
     @abstractmethod
     def name(self, value):
         """
@@ -1579,27 +1459,6 @@ class KeyPair(CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Return the id of this key pair.
-
-        :rtype: ``str``
-        :return: ID for this snapshot. Will generally correspond to the cloud
-                 middleware's name, but should be treated as an opaque value.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Return the name of this key pair.
-
-        :rtype: ``str``
-        :return: A name of this ssh key pair.
-        """
-        pass
-
     @abstractproperty
     def material(self):
         """
@@ -1629,26 +1488,6 @@ class Region(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        The id for this region
-
-        :rtype: ``str``
-        :return: ID of the region.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Name of the region.
-
-        :rtype: ``str``
-        :return: Name of the region.
-        """
-        pass
-
     @abstractproperty
     def zones(self):
         """
@@ -1667,26 +1506,6 @@ class PlacementZone(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Name of the placement zone.
-
-        :rtype: ``str``
-        :return: Name of the placement zone.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Name of the placement zone.
-
-        :rtype: ``str``
-        :return: Name of the placement zone.
-        """
-        pass
-
     @abstractproperty
     def region_name(self):
         """
@@ -1705,14 +1524,6 @@ class InstanceType(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        pass
-
-    @abstractproperty
-    def name(self):
-        pass
-
     @abstractproperty
     def family(self):
         """
@@ -1803,26 +1614,6 @@ class SecurityGroup(CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get the ID of this security group.
-
-        :rtype: ``str``
-        :return: Security group ID.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Return the name of this security group.
-
-        :rtype: ``str``
-        :return: A name of this security group.
-        """
-        pass
-
     @abstractproperty
     def description(self):
         """
@@ -1934,19 +1725,6 @@ class SecurityGroupRule(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        ID for this rule.
-
-        Note that this may be a CloudBridge-specific ID if the underlying
-        provider does not support rule IDs.
-
-        :rtype: ``str``
-        :return: Role ID.
-        """
-        pass
-
     @abstractproperty
     def ip_protocol(self):
         """
@@ -2012,26 +1790,6 @@ class BucketObject(CloudResource):
     """
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get this object's id.
-
-        :rtype: ``str``
-        :return: id of this object as returned by the cloud middleware.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get this object's name.
-
-        :rtype: ``str``
-        :return: Name of this object as returned by the cloud middleware.
-        """
-        pass
-
     @abstractproperty
     def size(self):
         """
@@ -2123,26 +1881,6 @@ class Bucket(PageableObjectMixin, CloudResource):
 
     __metaclass__ = ABCMeta
 
-    @abstractproperty
-    def id(self):
-        """
-        Get this bucket's id.
-
-        :rtype: ``str``
-        :return: ID of this bucket as returned by the cloud middleware.
-        """
-        pass
-
-    @abstractproperty
-    def name(self):
-        """
-        Get this bucket's name.
-
-        :rtype: ``str``
-        :return: Name of this bucket as returned by the cloud middleware.
-        """
-        pass
-
     @abstractmethod
     def get(self, name):
         """