libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [1/3] libcloud git commit: Added list images method for OnApp
Date Sat, 01 Apr 2017 22:43:36 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 1a6987da9 -> cab68602c


Added list images method for OnApp


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

Branch: refs/heads/trunk
Commit: 921829658cdf6f87b22f8cff1fb0d43e2b666314
Parents: 1a6987d
Author: Tinu Cleatus <tinupc@gmail.com>
Authored: Fri Mar 17 03:30:31 2017 +0530
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Sun Apr 2 08:42:26 2017 +1000

----------------------------------------------------------------------
 docs/examples/compute/onapp/functionality.py    |  6 +++
 libcloud/compute/drivers/onapp.py               | 29 +++++++++++-
 .../compute/fixtures/onapp/list_images.json     | 47 ++++++++++++++++++++
 libcloud/test/compute/test_onapp.py             | 16 +++++++
 4 files changed, 97 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/92182965/docs/examples/compute/onapp/functionality.py
----------------------------------------------------------------------
diff --git a/docs/examples/compute/onapp/functionality.py b/docs/examples/compute/onapp/functionality.py
index 08c7799..2465114 100644
--- a/docs/examples/compute/onapp/functionality.py
+++ b/docs/examples/compute/onapp/functionality.py
@@ -59,3 +59,9 @@ identifier = 'nodesidentifier'
 node, = [n for n in driver.list_nodes() if n.id == identifier]
 
 driver.destroy_node(node)
+
+#
+# List images
+#
+for image in driver.list_images():
+    print(image)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/92182965/libcloud/compute/drivers/onapp.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/onapp.py b/libcloud/compute/drivers/onapp.py
index 2b0811e..e017381 100644
--- a/libcloud/compute/drivers/onapp.py
+++ b/libcloud/compute/drivers/onapp.py
@@ -1,6 +1,6 @@
 import json
 
-from libcloud.compute.base import Node, NodeDriver
+from libcloud.compute.base import Node, NodeDriver, NodeImage
 from libcloud.common.onapp import OnAppConnection
 from libcloud.utils.networking import is_private_subnet
 from libcloud.compute.providers import Provider
@@ -315,10 +315,37 @@ class OnAppNodeDriver(NodeDriver):
             nodes.append(self._to_node(vm["virtual_machine"]))
         return nodes
 
+    def list_images(self):
+        """
+        List all images
+
+        :rtype: ``list`` of :class:`NodeImage`
+        """
+        response = self.connection.request("/templates.json")
+        # return list(map(self._to_image, data['image_template']))
+        templates = []
+        for template in response.object:
+            templates.append(self._to_image(template["image_template"]))
+        return templates
+
     #
     # Helper methods
     #
 
+    def _to_image(self, template):
+        extra = {'distribution': template['operating_system_distro'],
+                 'operating_system': template['operating_system'],
+                 'operating_system_arch': template['operating_system_arch'],
+                 'allow_resize_without_reboot':
+                 template['allow_resize_without_reboot'],
+                 'allowed_hot_migrate': template['allowed_hot_migrate'],
+                 'allowed_swap': template['allowed_swap'],
+                 'min_disk_size': template['min_disk_size'],
+                 'min_memory_size': template['min_memory_size'],
+                 'created_at': template['created_at']}
+        return NodeImage(id=template['id'], name=template['label'],
+                         driver=self, extra=extra)
+
     def _to_node(self, data):
         identifier = data["identifier"]
         name = data["label"]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/92182965/libcloud/test/compute/fixtures/onapp/list_images.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/onapp/list_images.json b/libcloud/test/compute/fixtures/onapp/list_images.json
new file mode 100644
index 0000000..aa70f32
--- /dev/null
+++ b/libcloud/test/compute/fixtures/onapp/list_images.json
@@ -0,0 +1,47 @@
+[
+  {
+    "image_template": {
+      "allow_resize_without_reboot": true,
+      "allowed_hot_migrate": true,
+      "allowed_swap": true,
+      "application_server": false,
+      "backup_server_id": "",
+      "baremetal_server": true,
+      "cdn": false,
+      "checksum": "f3ea0b39051d9c5fef3f7661c6318111",
+      "created_at": "2015-03-12T19:56:02+05:30",
+      "disk_target_device": "--- xen: sda kvm: hd ",
+      "draas": false,
+      "ext4": false,
+      "file_name": "centos-5.11-x64-1.1-xen.kvm.kvm_virtio.tar.gz",
+      "id": 123456,
+      "initial_password": "Password1",
+      "initial_username": "root",
+      "label": "CentOS 5.11 x64",
+      "manager_id": "",
+      "min_disk_size": 5,
+      "min_memory_size": 256,
+      "operating_system": "linux",
+      "operating_system_arch": "x64",
+      "operating_system_distro": "rhel",
+      "operating_system_edition": "",
+      "operating_system_tail": "",
+      "parent_template_id": "",
+      "properties": "",
+      "remote_id": "",
+      "resize_without_reboot_policy": {},
+      "smart_server": true,
+      "state": "active",
+      "template_size": 323924,
+      "updated_at": "",
+      "user_id": "",
+      "version": "1.1",
+      "virtualization": [
+        "xen",
+        "kvm",
+        "kvm_virtio"
+      ],
+      "type": "ImageTemplate"
+    }
+  }
+]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/92182965/libcloud/test/compute/test_onapp.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_onapp.py b/libcloud/test/compute/test_onapp.py
index fb95b09..6559c3c 100644
--- a/libcloud/test/compute/test_onapp.py
+++ b/libcloud/test/compute/test_onapp.py
@@ -69,6 +69,18 @@ class OnAppNodeTestCase(LibcloudTestCase):
         self.assertEqual(1, len(private_ips))
         self.assertEqual('192.168.15.72', private_ips[0])
 
+    def test_list_images(self):
+        images = self.driver.list_images()
+        extra = images[0].extra
+
+        self.assertEqual(1, len(images))
+        self.assertEqual('CentOS 5.11 x64', images[0].name)
+        self.assertEqual('123456', images[0].id)
+
+        self.assertEqual(True, extra['allowed_swap'])
+        self.assertEqual(256, extra['min_memory_size'])
+        self.assertEqual('rhel', extra['distribution'])
+
 
 class OnAppMockHttp(MockHttpTestCase):
     fixtures = ComputeFileFixtures('onapp')
@@ -88,6 +100,10 @@ class OnAppMockHttp(MockHttpTestCase):
             httplib.responses[httplib.NO_CONTENT]
         )
 
+    def _templates_json(self, method, url, body, headers):
+        body = self.fixtures.load('list_images.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message