Explorar el Código

Optimisation for image retrieval by owner id

Nuwan Goonasekera hace 8 años
padre
commit
caf9e7f55b

+ 6 - 3
cloudbridge/cloud/providers/aws/helpers.py

@@ -198,8 +198,8 @@ class BotoGenericService(object):
             # Do not limit, let the ClientPagedResultList enforce limit
             # Do not limit, let the ClientPagedResultList enforce limit
             return (None, collection)
             return (None, collection)
 
 
-    def list(self, limit=None, marker=None, collection=None):
-        collection = collection or self.boto_collection.filter()
+    def list(self, limit=None, marker=None, collection=None, **kwargs):
+        collection = collection or self.boto_collection.filter(**kwargs)
         resume_token, boto_objs = self._make_query(collection, limit, marker)
         resume_token, boto_objs = self._make_query(collection, limit, marker)
 
 
         # Wrap in CB objects.
         # Wrap in CB objects.
@@ -217,7 +217,8 @@ class BotoGenericService(object):
             return ClientPagedResultList(self.provider, results,
             return ClientPagedResultList(self.provider, results,
                                          limit=limit, marker=marker)
                                          limit=limit, marker=marker)
 
 
-    def find(self, filter_name, filter_value, limit=None, marker=None):
+    def find(self, filter_name, filter_value, limit=None, marker=None,
+             **kwargs):
         """
         """
         Returns a list of resources by filter
         Returns a list of resources by filter
 
 
@@ -232,6 +233,8 @@ class BotoGenericService(object):
             'Name': filter_name,
             'Name': filter_name,
             'Values': [filter_value]
             'Values': [filter_value]
             }])
             }])
+        if kwargs:
+            collection = collection.filter(**kwargs)
         return self.list(limit=limit, marker=marker, collection=collection)
         return self.list(limit=limit, marker=marker, collection=collection)
 
 
     def create(self, boto_method, **kwargs):
     def create(self, boto_method, **kwargs):

+ 0 - 4
cloudbridge/cloud/providers/aws/provider.py

@@ -102,10 +102,6 @@ class AWSCloudProvider(BaseCloudProvider):
     def storage(self):
     def storage(self):
         return self._storage
         return self._storage
 
 
-    @property
-    def account_id(self):
-        return self.session.client('sts').get_caller_identity()['Account']
-
     def _connect_ec2(self):
     def _connect_ec2(self):
         """
         """
         Get a boto ec2 connection object.
         Get a boto ec2 connection object.

+ 1 - 1
cloudbridge/cloud/providers/aws/services.py

@@ -296,7 +296,7 @@ class AWSImageService(BaseImageService):
     def list(self, limit=None, marker=None):
     def list(self, limit=None, marker=None):
         # Filter images by current account owner; otherwise, the call is
         # Filter images by current account owner; otherwise, the call is
         # very slow
         # very slow
-        return self.svc.find('owner-id', self.provider.account_id,
+        return self.svc.list(Owners=['self'],
                              limit=limit, marker=marker)
                              limit=limit, marker=marker)