Преглед на файлове

Added missing base class file

nuwan_ag преди 10 години
родител
ревизия
cca41c51af
променени са 2 файла, в които са добавени 26 реда и са изтрити 6 реда
  1. 24 0
      cloudbridge/providers/base.py
  2. 2 6
      cloudbridge/providers/interfaces.py

+ 24 - 0
cloudbridge/providers/base.py

@@ -0,0 +1,24 @@
+from cloudbridge.providers.interfaces import CloudProvider
+
+
+class BaseCloudProvider(CloudProvider):
+
+    def name(self):
+        return str(self.__class__.__name__)
+
+    def has_service(self, service_type):
+        """
+        Checks whether this provider supports a given service.
+
+        :type service_type: str or :class:``.CloudProviderServiceType``
+        :param service_type: Type of service the check support for.
+
+        :rtype: bool
+        :return: ``True`` if the service type is supported.
+        """
+        try:
+            if getattr(self, service_type):
+                return True
+        except AttributeError:
+            pass  # Undefined service type
+        return False

+ 2 - 6
cloudbridge/providers/interfaces.py

@@ -50,12 +50,8 @@ class CloudProvider():
         :rtype: bool
         :return: ``True`` if the service type is supported.
         """
-        try:
-            if getattr(self, service_type):
-                return True
-        except AttributeError:
-            pass  # Undefined service type
-        return False
+        raise NotImplementedError(
+            'CloudProvider.has_service not implemented by this provider')
 
     def account(self):
         """