Nuwan Goonasekera пре 7 година
родитељ
комит
e63db838b3

+ 10 - 8
cloudbridge/cloud/base/resources.py

@@ -16,6 +16,7 @@ import cloudbridge.cloud.base.helpers as cb_helpers
 from cloudbridge.cloud.interfaces.exceptions \
     import InvalidConfigurationException
 from cloudbridge.cloud.interfaces.exceptions import InvalidLabelException
+from cloudbridge.cloud.interfaces.exceptions import InvalidNameException
 from cloudbridge.cloud.interfaces.exceptions import WaitStateException
 from cloudbridge.cloud.interfaces.resources import AttachmentInfo
 from cloudbridge.cloud.interfaces.resources import Bucket
@@ -83,18 +84,19 @@ class BaseCloudResource(CloudResource):
         if not BaseCloudResource.is_valid_resource_name(name):
             log.debug("InvalidLabelException raised on %s", name)
             raise InvalidLabelException(
-                u"Invalid label: %s. Label must be at most 63 characters "
-                "long and consist of lowercase letters, numbers, or dashes. "
-                "The label must not start or end with a dash." % name)
+                u"Invalid label: %s. Label must be at least 3 characters long"
+                " and at most 63 characters. It must consist of lowercase"
+                " letters, numbers, or dashes. The label must not start or"
+                " end with a dash." % name)
 
     @staticmethod
     def assert_valid_resource_name(name):
         if not BaseCloudResource.is_valid_resource_name(name):
             log.debug("InvalidLabelException raised on %s", name)
-            raise InvalidLabelException(
+            raise InvalidNameException(
                 u"Invalid name: %s. Name must be at least 3 characters long"
                 " and at most 63 characters. It must consist of lowercase"
-                " letters, numbers, or dashes. The label must not start or"
+                " letters, numbers, or dashes. The name must not start or"
                 " end with a dash." % name)
 
     @staticmethod
@@ -716,7 +718,7 @@ class BaseBucketObject(BaseCloudResource, BucketObject):
             log.debug("InvalidLabelException raised on %s", name,
                       exc_info=True)
             raise InvalidLabelException(
-                u"Invalid object label: %s. Label must match criteria defined "
+                u"Invalid object name: %s. Name must match criteria defined "
                 "in: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMeta"
                 "data.html#object-key-guidelines" % name)
 
@@ -881,8 +883,8 @@ class BaseRouter(BaseCloudResource, Router):
 class BaseInternetGateway(BaseCloudResource, BaseObjectLifeCycleMixin,
                           InternetGateway):
 
-    CB_DEFAULT_INET_GATEWAY_LABEL = os.environ.get(
-        'CB_DEFAULT_INET_GATEWAY_LABEL', 'cloudbridge-inetgateway')
+    CB_DEFAULT_INET_GATEWAY_NAME = os.environ.get(
+        'CB_DEFAULT_INET_GATEWAY_NAME', 'cloudbridge-inetgateway')
 
     def __init__(self, provider):
         super(BaseInternetGateway, self).__init__(provider)

+ 16 - 2
cloudbridge/cloud/interfaces/exceptions.py

@@ -47,11 +47,25 @@ class ProviderConnectionException(CloudBridgeBaseException):
     pass
 
 
-class InvalidLabelException(CloudBridgeBaseException):
+class InvalidNameException(CloudBridgeBaseException):
+    """
+    Marker interface for any attempt to set an invalid name on
+    a CloudBridge resource. An example would be setting uppercase
+    letters, which are not allowed in a resource name.
+    """
+
+    def __init__(self, msg):
+        super(InvalidNameException, self).__init__(msg)
+
+
+class InvalidLabelException(InvalidNameException):
     """
     Marker interface for any attempt to set an invalid label on
-    a CloudBridge resource.An example would be setting uppercase
+    a CloudBridge resource. An example would be setting uppercase
     letters, which are not allowed in a resource label.
+    InvalidLabelExceptions inherit from, and are a special case
+    of InvalidNameExceptions. At present, these restrictions are
+    identical.
     """
 
     def __init__(self, msg):

+ 10 - 5
cloudbridge/cloud/interfaces/resources.py

@@ -119,12 +119,12 @@ class LabeledCloudResource(CloudResource):
         in the underlying cloud provider, or be simulated through tags/labels.
 
         The label property adheres to the following restrictions:
-        * Labels cannot be longer than 63 characters.
-        * May only contain ascii characters comprising of lowercase letters,
+        * Must be at least 3 characters in length.
+        * Cannot be longer than 63 characters.
+        * May only contain ASCII characters comprising of lowercase letters,
           numeric characters, and dashes.
         * Must begin with an alphanumeric character and end with one
           (i.e. cannot begin or end with a dash)
-        * Must be at least 3 characters in length.
 
         Some resources may not support labels, in which case, a
         NotImplementedError will be thrown.
@@ -731,7 +731,7 @@ class LaunchConfig(object):
         lc.add_block_device(...)
 
         inst = provider.compute.instances.create(
-            'MyVM', image, vm_type, network, launch_config=lc)
+            'MyVM', image, vm_type, subnet, launch_config=lc)
     """
 
     @abstractmethod
@@ -2233,6 +2233,11 @@ class BucketObject(CloudResource):
         """
         Retrieve the name of the current object.
 
+        The bucket object name adheres to a naming requirement that is more
+        relaxed than the naming requirement enforced across CloudBridge. More
+        details are available here: http://docs.aws.amazon.com/AmazonS3/latest/
+        dev/UsingMetadata.html#object-key-guidelines
+
         :rtype: ``str``
         :return: Name for this object as returned by the cloud middleware.
         """
@@ -2363,7 +2368,7 @@ class Bucket(CloudResource):
             # Show all objects in bucket
             print(list(bucket.objects))
 
-            # Find an object by label
+            # Find an object by name
             print(bucket.objects.find(name='my_obj.txt'))
 
             # Get first page of bucket list

+ 7 - 1
cloudbridge/cloud/providers/aws/resources.py

@@ -1235,7 +1235,13 @@ class AWSGatewayContainer(BaseGatewayContainer):
         cb_gateway = self.svc.create('create_internet_gateway')
         if name:
             AWSInternetGateway.assert_valid_resource_name(name)
-            cb_gateway.label = name
+            cb_gateway._gateway.create_tags(
+                Tags=[{'Key': 'Name', 'Value': name}])
+        else:
+            cb_gateway._gateway.create_tags(
+                Tags=[{'Key': 'Name',
+                       'Value': AWSInternetGateway.CB_DEFAULT_INET_GATEWAY_NAME
+                       }])
         cb_gateway._gateway.attach_to_vpc(VpcId=network_id)
         return cb_gateway
 

+ 19 - 19
test/helpers/standard_interface_tests.py

@@ -8,7 +8,7 @@ This includes:
 import uuid
 
 from cloudbridge.cloud.interfaces.exceptions \
-    import InvalidLabelException
+    import InvalidNameException
 from cloudbridge.cloud.interfaces.resources import LabeledCloudResource
 from cloudbridge.cloud.interfaces.resources import ObjectLifeCycleMixin
 from cloudbridge.cloud.interfaces.resources import ResultList
@@ -148,28 +148,28 @@ def check_obj_label(test, obj):
         VALID_LABEL = u"hello-world-123"
         obj.label = VALID_LABEL
         # Two character labels should not be allowed
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "ab"
         # A none value should not be allowed
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = None
         # setting spaces should raise an exception
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "hello world"
         # setting upper case characters should raise an exception
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "helloWorld"
         # setting special characters should raise an exception
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "hello.world:how_goes_it"
         # Starting with a dash should raise an exception
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "-hello"
         # Ending with a dash should raise an exception
-        with test.assertRaises(InvalidLabelException):
+        with test.assertRaises(InvalidNameException):
             obj.label = "hello-"
         # setting a length > 63 should result in an exception
-        with test.assertRaises(InvalidLabelException,
+        with test.assertRaises(InvalidNameException,
                                msg="Label of length > 64 is not allowed"):
             obj.label = "a" * 64
         # refreshing should yield the last successfully set label
@@ -223,38 +223,38 @@ def check_standard_behaviour(test, service, obj):
 def check_create(test, service, iface, name_prefix,
                  create_func, cleanup_func):
     # check create with invalid label
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         # spaces should raise an exception
         create_func("hello world")
     # check create with invalid label
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         # uppercase characters should raise an exception
         create_func("helloWorld")
     # setting special characters should raise an exception
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("hello.world:how_goes_it")
     # Starting with a dash should raise an exception
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("-hello")
     # Ending with a dash should raise an exception
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("hello-")
     # underscores are not allowed
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("hello_bucket")
     # setting a length > 63 should result in an exception
-    with test.assertRaises(InvalidLabelException,
+    with test.assertRaises(InvalidNameException,
                            msg="Label of length > 63 should be disallowed"):
         create_func("a" * 64)
     #  name cannot be an IP address
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("197.10.100.42")
 
     # empty name are not allowed
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func(None)
     # names of length less than 3 should raise an exception
-    with test.assertRaises(InvalidLabelException):
+    with test.assertRaises(InvalidNameException):
         create_func("cb")