Pārlūkot izejas kodu

Follow up updates to PR 28

Enis Afgan 9 gadi atpakaļ
vecāks
revīzija
77f3679e14

+ 31 - 22
cloudbridge/cloud/interfaces/resources.py

@@ -2057,20 +2057,10 @@ class BucketObject(CloudResource):
     @abstractmethod
     def upload_from_file(self, path):
         """
-        Stores the contents of the file pointed by the "path" variable.
-        :param path: Absolute path to the file to be uploaded to S3.
-        :return: void
-        """
-        pass
+        Store the contents of the file pointed by the "path" variable.
 
-    @abstractmethod
-    def upload_from_large_file(self, path):
-        """
-        Stores the contents of the large file pointed by the "path" variable.
-        This function split the file in smaller chunks, and uploads chunks
-        in turn.
-        :param path: Absolute path to the large file to be uploaded to S3.
-        :return: void
+        :type path: ``str``
+        :param path: Absolute path to the file to be uploaded to S3.
         """
         pass
 
@@ -2085,12 +2075,18 @@ class BucketObject(CloudResource):
         pass
 
     @abstractmethod
-    def generate_url(self, expires_in):
+    def generate_url(self, expires_in=0):
         """
-        Generates a URL to this object. If the object is public, `expires_in`
-        argument is not necessary, but if the object is private, the life time
-        of URL is set using `expires_in` argument.
-        :param expires_in: time to live of the generated URL in seconds.
+        Generate a URL to this object.
+
+        If the object is public, `expires_in` argument is not necessary, but if
+        the object is private, the lifetime of URL is set using `expires_in`
+        argument.
+
+        :type expires_in: ``int``
+        :param expires_in: Time to live of the generated URL in seconds.
+
+        :rtype: ``str``
         :return: A URL to access the object.
         """
         pass
@@ -2136,7 +2132,16 @@ class Bucket(PageableObjectMixin, CloudResource):
     @abstractmethod
     def list(self, limit=None, marker=None, prefix=None):
         """
-        List all objects, or those adhere to the prefix criterion, within this bucket.
+        List objects in this bucket.
+
+        :type limit: ``int``
+        :param limit: Maximum number of elements to return.
+
+        :type marker: ``int``
+        :param marker: Fetch results after this offset.
+
+        :type prefix: ``str``
+        :param prefix: Prefix criteria by which to filter listed objects.
 
         :rtype: :class:``.BucketObject``
         :return: List of all available BucketObjects within this bucket.
@@ -2168,10 +2173,14 @@ class Bucket(PageableObjectMixin, CloudResource):
         pass
 
     @abstractmethod
-    def exists(self, key):
+    def exists(self, name):
         """
         Determines if an object with given key exists in this bucket.
-        :param key: The key to be searched in the bucket.
-        :return: Boolean: True if the key exists, False, if it does not.
+
+        :type name: ``str``
+        :param name: The name of an object to search for in the bucket.
+
+        :rtype: ``bool``
+        :return: True if the object exists, False, if it does not.
         """
         pass

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

@@ -674,9 +674,9 @@ class AWSSecurityGroup(BaseSecurityGroup):
                  cidr_ip=None, src_group=None):
         for rule in self._security_group.rules:
             if (rule.ip_protocol == ip_protocol and
-                        rule.from_port == from_port and
-                        rule.to_port == to_port and
-                        rule.grants[0].cidr_ip == cidr_ip) or \
+                rule.from_port == from_port and
+                rule.to_port == to_port and
+                rule.grants[0].cidr_ip == cidr_ip) or \
                     (rule.grants[0].group_id == src_group.id if src_group and
                         hasattr(rule.grants[0], 'group_id') else False):
                 return AWSSecurityGroupRule(self._provider, rule, self)
@@ -811,22 +811,10 @@ class AWSBucketObject(BaseBucketObject):
 
     def upload_from_file(self, path):
         """
-        Stores the contents of the file pointed by the "path" variable.
-        :param path: Absolute path to the file to be uploaded to S3.
-        :return: void
+        Store the contents of the file pointed by the "path" variable.
         """
         self._key.set_contents_from_filename(path)
 
-    def upload_from_large_file(self, path):
-        """
-        Stores the contents of the large file pointed by the "path" variable.
-        This function split the file in smaller chunks, and uploads chunks
-        in turn.
-        :param path: Absolute path to the large file to be uploaded to S3.
-        :return: void
-        """
-        raise NotImplementedError("This functionality is not implemented yet.")
-
     def delete(self):
         """
         Delete this object.
@@ -838,11 +826,7 @@ class AWSBucketObject(BaseBucketObject):
 
     def generate_url(self, expires_in=0):
         """
-        Generates a URL to this object. If the object is public, `expires_in`
-        argument is not necessary, but if the object is private, the life time
-        of URL is set using `expires_in` argument.
-        :param expires_in: time to live of the generated URL in seconds.
-        :return: The URL to access the object.
+        Generate a URL to this object.
         """
         return self._key.generate_url(expires_in=expires_in)
 
@@ -896,13 +880,11 @@ class AWSBucket(BaseBucket):
         key = Key(self._bucket, name)
         return AWSBucketObject(self._provider, key)
 
-    def exists(self, key):
+    def exists(self, name):
         """
-        Determines if an object with given key exists in this bucket.
-        :param key: The key to be searched in the bucket.
-        :return: Boolean: True if the key exists, False, if it does not.
+        Determines if an object with given name key exists in this bucket.
         """
-        key = Key(self._bucket, key)
+        key = Key(self._bucket, name)
         if key and key.exists():
             return True
         return False
@@ -1140,7 +1122,7 @@ class AWSRouter(BaseRouter):
     def state(self):
         self.refresh()  # Explicitly refresh the local object
         if self._router.attachments and \
-                        self._router.attachments[0].state == 'available':
+           self._router.attachments[0].state == 'available':
             return RouterState.ATTACHED
         return RouterState.DETACHED
 

+ 8 - 6
cloudbridge/cloud/providers/openstack/resources.py

@@ -26,13 +26,16 @@ from cloudbridge.cloud.interfaces.resources import SnapshotState
 from cloudbridge.cloud.interfaces.resources import VolumeState
 from cloudbridge.cloud.interfaces.resources import SecurityGroup
 from cloudbridge.cloud.providers.openstack import helpers as oshelpers
+
 import inspect
 import json
 
 import ipaddress
 
 from keystoneclient.v3.regions import Region
+
 import novaclient.exceptions as novaex
+
 import swiftclient.exceptions as swiftex
 
 
@@ -1143,7 +1146,8 @@ class OpenStackBucket(BaseBucket):
         :return: List of all available BucketObjects within this bucket.
         """
         if prefix is not None:
-            raise NotImplementedError("This functionality is not implemented yet.")
+            raise NotImplementedError("Prefix functionality is not "
+                                      "implemented yet.")
 
         _, object_list = self._provider.swift.get_container(
             self.name, limit=oshelpers.os_result_limit(self._provider, limit),
@@ -1166,10 +1170,8 @@ class OpenStackBucket(BaseBucket):
         self._provider.swift.put_object(self.name, object_name, None)
         return self.get(object_name)
 
-    def exists(self, key):
+    def exists(self, name):
         """
-        Determines if an object with given key exists in this bucket.
-        :param key: The key to be searched in the bucket.
-        :return: Boolean: True if the key exists, False, if it does not.
+        Determines if an object with given name exists in this bucket.
         """
-        raise NotImplementedError("This functionality is not implemented yet.")
+        raise NotImplementedError("This functionality is not implemented yet.")

+ 7 - 2
cloudbridge/cloud/providers/openstack/services.py

@@ -29,6 +29,7 @@ from cloudbridge.cloud.interfaces.resources import MachineImage
 from cloudbridge.cloud.interfaces.resources import PlacementZone
 from cloudbridge.cloud.interfaces.resources import SecurityGroup
 from cloudbridge.cloud.interfaces.resources import Snapshot
+from cloudbridge.cloud.interfaces.resources import Subnet
 from cloudbridge.cloud.interfaces.resources import Volume
 from cloudbridge.cloud.providers.openstack import helpers as oshelpers
 
@@ -571,8 +572,10 @@ class OpenStackInstanceService(BaseInstanceService):
             isinstance(instance_type, InstanceType) else \
             self.provider.compute.instance_types.find(
                 name=instance_type)[0].id
-        network_id = (self.provider.network.subnets.get(subnet).network_id
-                      if isinstance(subnet, str) else subnet.network_id)
+        network_id = subnet.network_id if isinstance(subnet, Subnet) else None
+        if not network_id and subnet:
+            network_id = (self.provider.network.subnets.get(subnet).network_id
+                          if isinstance(subnet, str) else None)
         zone_id = zone.id if isinstance(zone, PlacementZone) else zone
         key_pair_name = key_pair.name if \
             isinstance(key_pair, KeyPair) else key_pair
@@ -589,6 +592,8 @@ class OpenStackInstanceService(BaseInstanceService):
             bdm = self._to_block_device_mapping(launch_config)
         net = self._get_network(network_id)
 
+        log.debug("Launching with net %s" % net)
+        print("(PR) Launching with net %s" % net)
         os_instance = self.provider.nova.servers.create(
             name,
             None if self._has_root_device(launch_config) else image_id,

+ 2 - 1
test/test_object_store_service.py

@@ -5,6 +5,7 @@ import urllib
 import os
 
 from cloudbridge.cloud.interfaces.resources import BucketObject
+
 from test.helpers import ProviderTestBase
 import test.helpers as helpers
 
@@ -189,4 +190,4 @@ class CloudObjectStoreServiceTestCase(ProviderTestBase):
                     target_stream2 = BytesIO()
                     for data in obj.iter_content():
                         target_stream2.write(data)
-                    self.assertEqual(target_stream2.getvalue(), content)
+                    self.assertEqual(target_stream2.getvalue(), content)