libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [02/10] libcloud git commit: added doc example and test
Date Sun, 09 Oct 2016 08:50:48 GMT
added doc example and test


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

Branch: refs/heads/trunk
Commit: 93d387006d0eb5a1a194098aa480809d2d7baa03
Parents: f33df13
Author: Anthony Shaw <anthonyshaw@apache.org>
Authored: Fri Jun 24 15:53:31 2016 +1000
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Jun 24 15:53:31 2016 +1000

----------------------------------------------------------------------
 docs/getting_started.rst                        | 14 +++++------
 libcloud/__init__.py                            | 26 +++++++++++++++++---
 .../fixtures/docker/mac_124/create_image.json   |  1 +
 libcloud/test/test_init.py                      |  4 +++
 4 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/93d38700/docs/getting_started.rst
----------------------------------------------------------------------
diff --git a/docs/getting_started.rst b/docs/getting_started.rst
index 29ddb4b..c407e9c 100644
--- a/docs/getting_started.rst
+++ b/docs/getting_started.rst
@@ -40,10 +40,10 @@ with any of the Libcloud drivers.
 
     from pprint import pprint
 
-    from libcloud.compute.types import Provider
-    from libcloud.compute.providers import get_driver
+    import libcloud
+    
+    cls = libcloud.get_driver(libcloud.DriverType.COMPUTE, libcloud.DriverType.COMPUTE.RACKSPACE)
 
-    cls = get_driver(Provider.RACKSPACE)
 
 2. Instantiate the driver with your provider credentials
 
@@ -70,10 +70,10 @@ see provider-specific documentation and the driver docstrings.
 
     from pprint import pprint
 
-    from libcloud.compute.types import Provider
-    from libcloud.compute.providers import get_driver
-
-    cls = get_driver(Provider.RACKSPACE)
+    import libcloud
+    
+    cls = libcloud.get_driver(libcloud.DriverType.COMPUTE, libcloud.DriverType.COMPUTE.RACKSPACE)
+    
     driver = cls('my username', 'my api key')
 
     pprint(driver.list_sizes())

http://git-wip-us.apache.org/repos/asf/libcloud/blob/93d38700/libcloud/__init__.py
----------------------------------------------------------------------
diff --git a/libcloud/__init__.py b/libcloud/__init__.py
index 69b2a0a..38ebfcb 100644
--- a/libcloud/__init__.py
+++ b/libcloud/__init__.py
@@ -22,11 +22,22 @@ import os
 import codecs
 
 from libcloud.backup.providers import Provider as BackupProvider
+from libcloud.backup.providers import get_driver as get_backup_driver
+
 from libcloud.compute.providers import Provider as ComputeProvider
+from libcloud.compute.providers import get_driver as get_compute_driver
+
 from libcloud.container.providers import Provider as ContainerProvider
+from libcloud.container.providers import get_driver as get_container_driver
+
 from libcloud.dns.providers import Provider as DnsProvider
+from libcloud.dns.providers import get_driver as get_dns_driver
+
 from libcloud.loadbalancer.providers import Provider as LoadBalancerProvider
+from libcloud.loadbalancer.providers import get_driver as get_loadbalancer_driver
+
 from libcloud.storage.providers import Provider as StorageProvider
+from libcloud.storage.providers import get_driver as get_storage_driver
 
 
 __all__ = ['__version__', 'enable_debug']
@@ -104,9 +115,18 @@ class DriverType:
     STORAGE = StorageProvider
 
 
-def get_driver(provider):
-    """
+DriverTypeFactoryMap = {
+    DriverType.BACKUP: get_backup_driver,
+    DriverType.COMPUTE: get_compute_driver,
+    DriverType.CONTAINER: get_container_driver,
+    DriverType.DNS: get_dns_driver,
+    DriverType.LOADBALANCER: get_loadbalancer_driver,
+    DriverType.STORAGE: get_storage_driver
+}
 
+
+def get_driver(type, provider):
+    """
     Get a driver
     """
-    pass
\ No newline at end of file
+    return DriverTypeFactoryMap[type](provider)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/93d38700/libcloud/test/container/fixtures/docker/mac_124/create_image.json
----------------------------------------------------------------------
diff --git a/libcloud/test/container/fixtures/docker/mac_124/create_image.json b/libcloud/test/container/fixtures/docker/mac_124/create_image.json
new file mode 100644
index 0000000..4509f55
--- /dev/null
+++ b/libcloud/test/container/fixtures/docker/mac_124/create_image.json
@@ -0,0 +1 @@
+{"status":"Download complete","progressDetail":{},"id":"cf55d61f5307b7a18a45980971d6cfd40b737dd661879c4a6b3f2aecc3bc37b0"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/93d38700/libcloud/test/test_init.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_init.py b/libcloud/test/test_init.py
index ad709d7..0276850 100644
--- a/libcloud/test/test_init.py
+++ b/libcloud/test/test_init.py
@@ -24,6 +24,7 @@ try:
 except ImportError:
     have_paramiko = False
 
+import libcloud
 from libcloud import _init_once
 from libcloud.common.base import LoggingHTTPConnection
 from libcloud.common.base import LoggingHTTPSConnection
@@ -56,6 +57,9 @@ class TestUtils(unittest.TestCase):
             paramiko_log_level = logger.getEffectiveLevel()
             self.assertEqual(paramiko_log_level, logging.DEBUG)
 
+    def test_factory(self):
+        driver = libcloud.get_driver(libcloud.DriverType.COMPUTE, libcloud.DriverType.COMPUTE.EC2)
+        self.assertEqual(driver.__name__, 'EC2NodeDriver')
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message