libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/2] git commit: Add utility get_service_types method to OpenStackServiceCatalog class.
Date Thu, 07 Aug 2014 15:56:01 GMT
Add utility get_service_types method to OpenStackServiceCatalog class.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/13fe413d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/13fe413d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/13fe413d

Branch: refs/heads/trunk
Commit: 13fe413d7af4c11b836cbda0a3aa2a2f94ee03d5
Parents: 1e28abe
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Thu Aug 7 17:48:29 2014 +0200
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Thu Aug 7 17:49:15 2014 +0200

----------------------------------------------------------------------
 libcloud/common/openstack.py            | 21 +++++++++++++++++++++
 libcloud/test/compute/test_openstack.py |  8 ++++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/13fe413d/libcloud/common/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack.py b/libcloud/common/openstack.py
index 3d4786b..61d16c1 100644
--- a/libcloud/common/openstack.py
+++ b/libcloud/common/openstack.py
@@ -506,10 +506,31 @@ class OpenStackServiceCatalog(object):
 
         return list(regions)
 
+    def get_service_types(self, region=None):
+        """
+        Retrieve all the available service types.
+
+        :param region: Optional region to retrieve service types for.
+        :type region: ``str``
+
+        :rtype: ``list`` of ``str``
+        """
+        service_types = set()
+
+        for service_type, values in self._service_catalog.items():
+            regions = values.keys()
+            if not region or region in regions:
+                service_types.add(service_type)
+
+        return list(service_types)
+
     def get_service_names(self, service_type, region=None):
         """
         Retrieve list of service names that match service type and region
 
+        :type service_type: ``str``
+        :type region: ``str``
+
         :rtype: ``list`` of ``str``
         """
         names = set()

http://git-wip-us.apache.org/repos/asf/libcloud/blob/13fe413d/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index 06e79ba..77a38e9 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -117,6 +117,14 @@ class OpenStackServiceCatalogTests(unittest.TestCase):
         regions = self.service_catalog.get_regions()
         self.assertEqual(sorted(regions), ['LON', 'ORD'])
 
+    def test_get_service_types(self):
+        service_types = self.service_catalog.get_service_types()
+        self.assertEqual(sorted(service_types), ['compute', 'object-store',
+                                                 'rax:object-cdn'])
+
+        service_types = self.service_catalog.get_service_types(region='invalid')
+        self.assertEqual(sorted(service_types), [])
+
     def test_get_service_names(self):
         OpenStackBaseConnection.conn_classes = (OpenStack_2_0_MockHttp,
                                                 OpenStack_2_0_MockHttp)


Mime
View raw message