From b105899f821c62d00fa16f589a283c95df26c954 Mon Sep 17 00:00:00 2001 From: gigimon Date: Wed, 17 Sep 2014 15:57:30 +0400 Subject: [PATCH] * add some methods to cloudstack driver (create_volume_snapshot, list_snapshots, destroy_volume_snapshot, create_snapshot_template, ex_list_os_types) * add test to new cloudstack functions --- libcloud/compute/drivers/cloudstack.py | 109 ++++++++++++++++++++- .../cloudstack/createSnapshot_default.json | 1 + .../cloudstack/createTemplate_default.json | 1 + .../cloudstack/deleteSnapshot_default.json | 1 + .../fixtures/cloudstack/listOsTypes_default.json | 1 + .../fixtures/cloudstack/listSnapshots_default.json | 1 + .../cloudstack/queryAsyncJobResult_1300001.json | 1 + .../cloudstack/queryAsyncJobResult_1300002.json | 1 + .../cloudstack/queryAsyncJobResult_1300003.json | 1 + libcloud/test/compute/test_cloudstack.py | 42 ++++++++ 10 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 libcloud/test/compute/fixtures/cloudstack/createSnapshot_default.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/createTemplate_default.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/deleteSnapshot_default.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/listOsTypes_default.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/listSnapshots_default.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300001.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300002.json create mode 100644 libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300003.json diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py index 21d2fef..39359c4 100644 --- a/libcloud/compute/drivers/cloudstack.py +++ b/libcloud/compute/drivers/cloudstack.py @@ -24,7 +24,7 @@ from libcloud.utils.py3 import urlparse from libcloud.compute.providers import Provider from libcloud.common.cloudstack import CloudStackDriverMixIn from libcloud.compute.base import Node, NodeDriver, NodeImage, NodeLocation -from libcloud.compute.base import NodeSize, StorageVolume +from libcloud.compute.base import NodeSize, StorageVolume, VolumeSnapshot from libcloud.compute.base import KeyPair from libcloud.compute.types import NodeState, LibcloudError from libcloud.compute.types import KeyPairDoesNotExistError @@ -193,6 +193,10 @@ RESOURCE_EXTRA_ATTRIBUTES_MAP = { 'transform_func': int }, 'instance_id': { + 'key_name': 'virtualmachineid', + 'transform_func': str + }, + 'serviceoffering_id': { 'key_name': 'serviceofferingid', 'transform_func': str }, @@ -2253,6 +2257,109 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver): return True + def list_snapshots(self): + """ + Describe all snapshots. + + :rtype: ``list`` of :class:`VolumeSnapshot` + """ + snapshots = self._sync_request('listSnapshots', + method='GET') + list_snapshots = [] + + for snap in snapshots['snapshot']: + list_snapshots.append(self._to_snapshot(snap)) + return list_snapshots + + def create_volume_snapshot(self, volume): + """ + Create snapshot from volume + + :param volume: Instance of ``StorageVolume`` + :type volume: ``StorageVolume`` + + :rtype: :class:`VolumeSnapshot` + """ + snapshot = self._async_request(command='createSnapshot', + params={'volumeid': volume.id}, + method='GET') + return self._to_snapshot(snapshot['snapshot']) + + def destroy_volume_snapshot(self, snapshot): + """ + Destroy snapshot + + :param snapshot: Instance of ``VolumeSnapshot`` + :type volume: ``VolumeSnapshot`` + + :rtype: ``bool`` + """ + self._async_request(command='deleteSnapshot', + params={'id': snapshot.id}, + method='GET') + return True + + def ex_create_snapshot_template(self, snapshot, name, ostypeid, displaytext=None): + """ + Create a template from a snapshot + + :param snapshot: Instance of ``VolumeSnapshot`` + :type volume: ``VolumeSnapshot`` + + :param name: the name of the template + :type name: ``str`` + + :param name: the os type id + :type name: ``str`` + + :param name: the display name of the template + :type name: ``str`` + + :rtype: :class:`NodeImage` + """ + if not displaytext: + displaytext = name + img = self._async_request('createTemplate', + params={ + 'displaytext': displaytext, + 'name': name, + 'ostypeid': ostypeid, + 'snapshotid': snapshot.id + }).get('template') + return NodeImage(id=img['id'], + name=img['name'], + driver=self.connection.driver, + extra={ + 'hypervisor': img['hypervisor'], + 'format': img['format'], + 'os': img['ostypename'], + 'displaytext': img['displaytext']}) + + def ex_list_os_types(self): + """ + List all registered os types (needed for snapshot creation) + + :rtype: ``list`` + """ + ostypes = self._sync_request('listOsTypes') + return ostypes['ostype'] + + def _to_snapshot(self, data): + """ + Create snapshot object from data + + :param data: Node data object. + :type data: ``dict`` + + :rtype: :class:`VolumeSnapshot` + """ + extra = { + 'tags': data.get('tags', None), + 'name': data.get('name', None), + 'volume_id': data.get('volumeid', None), + } + return VolumeSnapshot(data['id'], driver=self, extra=extra) + def _to_node(self, data, public_ips=None): """ :param data: Node data object. diff --git a/libcloud/test/compute/fixtures/cloudstack/createSnapshot_default.json b/libcloud/test/compute/fixtures/cloudstack/createSnapshot_default.json new file mode 100644 index 0000000..4dc70bd --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/createSnapshot_default.json @@ -0,0 +1 @@ +{ "createsnapshotresponse" : {"jobid":1300001,"id":190547} } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/createTemplate_default.json b/libcloud/test/compute/fixtures/cloudstack/createTemplate_default.json new file mode 100644 index 0000000..3314257 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/createTemplate_default.json @@ -0,0 +1 @@ +{ "createtemplateresponse" : {"jobid":1300003,"id":10260} } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/deleteSnapshot_default.json b/libcloud/test/compute/fixtures/cloudstack/deleteSnapshot_default.json new file mode 100644 index 0000000..285e987 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/deleteSnapshot_default.json @@ -0,0 +1 @@ +{ "deletesnapshotresponse" : {"jobid":1300002} } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/listOsTypes_default.json b/libcloud/test/compute/fixtures/cloudstack/listOsTypes_default.json new file mode 100644 index 0000000..e237a33 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/listOsTypes_default.json @@ -0,0 +1 @@ +{ "listostypesresponse" : { "count":146 ,"ostype" : [ {"id":69,"oscategoryid":7,"description":"Asianux 3(32-bit)"}, {"id":70,"oscategoryid":7,"description":"Asianux 3(64-bit)"}, {"id":1,"oscategoryid":1,"description":"CentOS 4.5 (32-bit)"}, {"id":2,"oscategoryid":1,"description":"CentOS 4.6 (32-bit)"}, {"id":3,"oscategoryid":1,"description":"CentOS 4.7 (32-bit)"}, {"id":4,"oscategoryid":1,"description":"CentOS 4.8 (32-bit)"}, {"id":5,"oscategoryid":1,"description":"CentOS 5.0 (32-bit)"}, {"id":6,"oscategoryid":1,"description":"CentOS 5.0 (64-bit)"}, {"id":7,"oscategoryid":1,"description":"CentOS 5.1 (32-bit)"}, {"id":8,"oscategoryid":1,"description":"CentOS 5.1 (64-bit)"}, {"id":9,"oscategoryid":1,"description":"CentOS 5.2 (32-bit)"}, {"id":10,"oscategoryid":1,"description":"CentOS 5.2 (64-bit)"}, {"id":11,"oscategoryid":1,"description":"CentOS 5.3 (32-bit)"}, {"id":12,"oscategoryid":1,"description":"CentOS 5.3 (64-bit)"}, {"id":13,"oscategoryid":1,"description":"CentOS 5.4 (32-bit)"}, {"id":14,"oscategoryid":1,"description":"CentOS 5.4 (64-bit)"}, {"id":111,"oscategoryid":1,"description":"CentOS 5.5 (32-bit)"}, {"id":112,"oscategoryid":1,"description":"CentOS 5.5 (64-bit)"}, {"id":73,"oscategoryid":2,"description":"Debian GNU/Linux 4(32-bit)"}, {"id":74,"oscategoryid":2,"description":"Debian GNU/Linux 4(64-bit)"}, {"id":72,"oscategoryid":2,"description":"Debian GNU/Linux 5(64-bit)"}, {"id":15,"oscategoryid":2,"description":"Debian GNU/Linux 5.0 (32-bit)"}, {"id":132,"oscategoryid":2,"description":"Debian GNU/Linux 6(32-bit)"}, {"id":133,"oscategoryid":2,"description":"Debian GNU/Linux 6(64-bit)"}, {"id":102,"oscategoryid":6,"description":"DOS"}, {"id":118,"oscategoryid":4,"description":"Fedora 10"}, {"id":117,"oscategoryid":4,"description":"Fedora 11"}, {"id":116,"oscategoryid":4,"description":"Fedora 12"}, {"id":115,"oscategoryid":4,"description":"Fedora 13"}, {"id":120,"oscategoryid":4,"description":"Fedora 8"}, {"id":119,"oscategoryid":4,"description":"Fedora 9"}, {"id":83,"oscategoryid":9,"description":"FreeBSD (32-bit)"}, {"id":84,"oscategoryid":9,"description":"FreeBSD (64-bit)"}, {"id":92,"oscategoryid":6,"description":"Microsoft Small Bussiness Server 2003"}, {"id":138,"oscategoryid":7,"description":"None"}, {"id":78,"oscategoryid":8,"description":"Novell Netware 5.1"}, {"id":77,"oscategoryid":8,"description":"Novell Netware 6.x"}, {"id":68,"oscategoryid":7,"description":"Open Enterprise Server"}, {"id":16,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.0 (32-bit)"}, {"id":17,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.0 (64-bit)"}, {"id":18,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.1 (32-bit)"}, {"id":19,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.1 (64-bit)"}, {"id":20,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.2 (32-bit)"}, {"id":21,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.2 (64-bit)"}, {"id":22,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.3 (32-bit)"}, {"id":23,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.3 (64-bit)"}, {"id":24,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.4 (32-bit)"}, {"id":25,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.4 (64-bit)"}, {"id":134,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.5 (32-bit)"}, {"id":135,"oscategoryid":3,"description":"Oracle Enterprise Linux 5.5 (64-bit)"}, {"id":104,"oscategoryid":7,"description":"OS/2"}, {"id":60,"oscategoryid":7,"description":"Other (32-bit)"}, {"id":103,"oscategoryid":7,"description":"Other (64-bit)"}, {"id":75,"oscategoryid":7,"description":"Other 2.6x Linux (32-bit)"}, {"id":76,"oscategoryid":7,"description":"Other 2.6x Linux (64-bit)"}, {"id":200,"oscategoryid":1,"description":"Other CentOS (32-bit)"}, {"id":201,"oscategoryid":1,"description":"Other CentOS (64-bit)"}, {"id":98,"oscategoryid":7,"description":"Other Linux (32-bit)"}, {"id":99,"oscategoryid":7,"description":"Other Linux (64-bit)"}, {"id":139,"oscategoryid":7,"description":"Other PV (32-bit)"}, {"id":140,"oscategoryid":7,"description":"Other PV (64-bit)"}, {"id":202,"oscategoryid":5,"description":"Other SUSE Linux(32-bit)"}, {"id":203,"oscategoryid":5,"description":"Other SUSE Linux(64-bit)"}, {"id":59,"oscategoryid":10,"description":"Other Ubuntu (32-bit)"}, {"id":100,"oscategoryid":10,"description":"Other Ubuntu (64-bit)"}, {"id":131,"oscategoryid":10,"description":"Red Hat Enterprise Linux 2"}, {"id":66,"oscategoryid":4,"description":"Red Hat Enterprise Linux 3(32-bit)"}, {"id":67,"oscategoryid":4,"description":"Red Hat Enterprise Linux 3(64-bit)"}, {"id":106,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4(64-bit)"}, {"id":26,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.5 (32-bit)"}, {"id":27,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.6 (32-bit)"}, {"id":28,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.7 (32-bit)"}, {"id":29,"oscategoryid":4,"description":"Red Hat Enterprise Linux 4.8 (32-bit)"}, {"id":30,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.0 (32-bit)"}, {"id":31,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.0 (64-bit)"}, {"id":32,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.1 (32-bit)"}, {"id":33,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.1 (64-bit)"}, {"id":34,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.2 (32-bit)"}, {"id":35,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.2 (64-bit)"}, {"id":36,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.3 (32-bit)"}, {"id":37,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.3 (64-bit)"}, {"id":38,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.4 (32-bit)"}, {"id":39,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.4 (64-bit)"}, {"id":113,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.5 (32-bit)"}, {"id":114,"oscategoryid":4,"description":"Red Hat Enterprise Linux 5.5 (64-bit)"}, {"id":136,"oscategoryid":4,"description":"Red Hat Enterprise Linux 6.0 (32-bit)"}, {"id":137,"oscategoryid":4,"description":"Red Hat Enterprise Linux 6.0 (64-bit)"}, {"id":85,"oscategoryid":9,"description":"SCO OpenServer 5"}, {"id":86,"oscategoryid":9,"description":"SCO UnixWare 7"}, {"id":79,"oscategoryid":9,"description":"Sun Solaris 10(32-bit)"}, {"id":80,"oscategoryid":9,"description":"Sun Solaris 10(64-bit)"}, {"id":142,"oscategoryid":9,"description":"Sun Solaris 11 (32-bit)"}, {"id":141,"oscategoryid":9,"description":"Sun Solaris 11 (64-bit)"}, {"id":82,"oscategoryid":9,"description":"Sun Solaris 8(Experimental)"}, {"id":81,"oscategoryid":9,"description":"Sun Solaris 9(Experimental)"}, {"id":109,"oscategoryid":5,"description":"SUSE Linux Enterprise 10(32-bit)"}, {"id":110,"oscategoryid":5,"description":"SUSE Linux Enterprise 10(64-bit)"}, {"id":96,"oscategoryid":5,"description":"SUSE Linux Enterprise 8(32-bit)"}, {"id":97,"oscategoryid":5,"description":"SUSE Linux Enterprise 8(64-bit)"}, {"id":107,"oscategoryid":5,"description":"SUSE Linux Enterprise 9(32-bit)"}, {"id":108,"oscategoryid":5,"description":"SUSE Linux Enterprise 9(64-bit)"}, {"id":41,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP1 (32-bit)"}, {"id":42,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP1 (64-bit)"}, {"id":43,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP2 (32-bit)"}, {"id":44,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP2 (64-bit)"}, {"id":45,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 10 SP3 (64-bit)"}, {"id":46,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 11 (32-bit)"}, {"id":47,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 11 (64-bit)"}, {"id":40,"oscategoryid":5,"description":"SUSE Linux Enterprise Server 9 SP4 (32-bit)"}, {"id":121,"oscategoryid":10,"description":"Ubuntu 10.04 (32-bit)"}, {"id":126,"oscategoryid":10,"description":"Ubuntu 10.04 (64-bit)"}, {"id":125,"oscategoryid":10,"description":"Ubuntu 8.04 (32-bit)"}, {"id":130,"oscategoryid":10,"description":"Ubuntu 8.04 (64-bit)"}, {"id":124,"oscategoryid":10,"description":"Ubuntu 8.10 (32-bit)"}, {"id":129,"oscategoryid":10,"description":"Ubuntu 8.10 (64-bit)"}, {"id":123,"oscategoryid":10,"description":"Ubuntu 9.04 (32-bit)"}, {"id":128,"oscategoryid":10,"description":"Ubuntu 9.04 (64-bit)"}, {"id":122,"oscategoryid":10,"description":"Ubuntu 9.10 (32-bit)"}, {"id":127,"oscategoryid":10,"description":"Ubuntu 9.10 (64-bit)"}, {"id":95,"oscategoryid":6,"description":"Windows 2000 Advanced Server"}, {"id":105,"oscategoryid":6,"description":"Windows 2000 Professional"}, {"id":61,"oscategoryid":6,"description":"Windows 2000 Server"}, {"id":55,"oscategoryid":6,"description":"Windows 2000 Server SP4 (32-bit)"}, {"id":65,"oscategoryid":6,"description":"Windows 3.1"}, {"id":48,"oscategoryid":6,"description":"Windows 7 (32-bit)"}, {"id":49,"oscategoryid":6,"description":"Windows 7 (64-bit)"}, {"id":63,"oscategoryid":6,"description":"Windows 95"}, {"id":62,"oscategoryid":6,"description":"Windows 98"}, {"id":64,"oscategoryid":6,"description":"Windows NT 4"}, {"id":204,"oscategoryid":6,"description":"Windows PV"}, {"id":87,"oscategoryid":6,"description":"Windows Server 2003 DataCenter Edition(32-bit)"}, {"id":88,"oscategoryid":6,"description":"Windows Server 2003 DataCenter Edition(64-bit)"}, {"id":50,"oscategoryid":6,"description":"Windows Server 2003 Enterprise Edition(32-bit)"}, {"id":51,"oscategoryid":6,"description":"Windows Server 2003 Enterprise Edition(64-bit)"}, {"id":89,"oscategoryid":6,"description":"Windows Server 2003 Standard Edition(32-bit)"}, {"id":90,"oscategoryid":6,"description":"Windows Server 2003 Standard Edition(64-bit)"}, {"id":91,"oscategoryid":6,"description":"Windows Server 2003 Web Edition"}, {"id":52,"oscategoryid":6,"description":"Windows Server 2008 (32-bit)"}, {"id":53,"oscategoryid":6,"description":"Windows Server 2008 (64-bit)"}, {"id":54,"oscategoryid":6,"description":"Windows Server 2008 R2 (64-bit)"}, {"id":56,"oscategoryid":6,"description":"Windows Vista (32-bit)"}, {"id":101,"oscategoryid":6,"description":"Windows Vista (64-bit)"}, {"id":93,"oscategoryid":6,"description":"Windows XP (32-bit)"}, {"id":94,"oscategoryid":6,"description":"Windows XP (64-bit)"}, {"id":57,"oscategoryid":6,"description":"Windows XP SP2 (32-bit)"}, {"id":58,"oscategoryid":6,"description":"Windows XP SP3 (32-bit)"} ] } } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/listSnapshots_default.json b/libcloud/test/compute/fixtures/cloudstack/listSnapshots_default.json new file mode 100644 index 0000000..d86f22b --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/listSnapshots_default.json @@ -0,0 +1 @@ +{"listsnapshotsresponse" : { "count":3 ,"snapshot" : [ {"id":188402,"account":"User1","domainid":2345,"domain":"70000001000","snapshottype":"MANUAL","volumeid":89341,"volumename":"ROOT-12344","volumetype":"ROOT","created":"2014-09-17T19:55:48+0900","name":"i-123-87654-VM_ROOT-12344_20140917105548","intervaltype":"MANUAL","state":"BackedUp"}, {"id":188401,"account":"User1","domainid":2345,"domain":"70000001100","snapshottype":"MANUAL","volumeid":89342,"volumename":"ROOT-12345","volumetype":"ROOT","created":"2014-09-17T19:44:41+0900","name":"i-123-87654-VM_ROOT-12345_20140917104441","intervaltype":"MANUAL","state":"BackedUp"}, {"id":188400,"account":"User1","domainid":2345,"domain":"70000001100","snapshottype":"MANUAL","volumeid":89343,"volumename":"ROOT-71128","volumetype":"ROOT","created":"2014-09-17T19:34:58+0900","name":"i-882-71128-VM_ROOT-71128_20140917103458","intervaltype":"MANUAL","state":"BackedUp"}]}} \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300001.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300001.json new file mode 100644 index 0000000..076fd61 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300001.json @@ -0,0 +1 @@ +{ "queryasyncjobresultresponse" : {"jobid":1300001,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"snapshot":{"id":190547,"account":"User1","domainid":2345,"domain":"70000001000","snapshottype":"MANUAL","volumeid":"fe1ada16-57a0-40ae-b577-01a153690fb4","volumename":"ROOT-12345","volumetype":"ROOT","created":"2014-09-22T19:09:47+0900","name":"i-123-87654-VM_ROOT-23456_20140917105548","intervaltype":"MANUAL","state":"CreatedOnPrimary"}}} } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300002.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300002.json new file mode 100644 index 0000000..c812b7b --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300002.json @@ -0,0 +1 @@ +{ "queryasyncjobresultresponse" : {"jobid":1300002,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"success":true}} } \ No newline at end of file diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300003.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300003.json new file mode 100644 index 0000000..2ae1199 --- /dev/null +++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_1300003.json @@ -0,0 +1 @@ +{ "queryasyncjobresultresponse" : {"jobid":1300003,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"template":{"id":10260,"name":"test-libcloud-template","displaytext":"test-libcloud-template","ispublic":false,"created":"2014-09-22T19:14:28+0900","isready":true,"passwordenabled":false,"format":"OVA","isfeatured":false,"crossZones":false,"ostypeid":99,"ostypename":"Other Linux (64-bit)","account":"User1","zoneid":2,"zonename":"zone1","status":"Download Complete","size":16106127360,"templatetype":"USER","hypervisor":"VMware","domain":"70000001100","domainid":1105,"isextractable":true,"checksum":"d8fc299515d138b13680014d05031d8b","sourcetemplateid":10259}}} } \ No newline at end of file diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py index 3393c0c..00ba306 100644 --- a/libcloud/test/compute/test_cloudstack.py +++ b/libcloud/test/compute/test_cloudstack.py @@ -706,6 +706,48 @@ class CloudStackCommonTestCase(TestCaseMixin): resp = self.driver.ex_delete_tags([node.id], 'UserVm', tag_keys) self.assertTrue(resp) + def test_list_snapshots(self): + snapshots = self.driver.list_snapshots() + self.assertEqual(len(snapshots), 3) + + snap = snapshots[0] + self.assertEqual(snap.id, 188402) + self.assertEqual(snap.extra['name'], "i-123-87654-VM_ROOT-12344_20140917105548") + self.assertEqual(snap.extra['volume_id'], 89341) + + def test_create_volume_snapshot(self): + volume = self.driver.list_volumes()[0] + snapshot = self.driver.create_volume_snapshot(volume) + + self.assertEqual(snapshot.id, 190547) + self.assertEqual(snapshot.extra['name'], "i-123-87654-VM_ROOT-23456_20140917105548") + self.assertEqual(snapshot.extra['volume_id'], "fe1ada16-57a0-40ae-b577-01a153690fb4") + + def test_destroy_volume_snapshot(self): + snapshot = self.driver.list_snapshots()[0] + resp = self.driver.destroy_volume_snapshot(snapshot) + self.assertTrue(resp) + + def test_ex_create_snapshot_template(self): + snapshot = self.driver.list_snapshots()[0] + + template = self.driver.ex_create_snapshot_template(snapshot, "test-libcloud-template", 99) + + self.assertEqual(template.id, '10260') + self.assertEqual(template.name, "test-libcloud-template") + self.assertEqual(template.extra['displaytext'], "test-libcloud-template") + self.assertEqual(template.extra['hypervisor'], "VMware") + self.assertEqual(template.extra['os'], "Other Linux (64-bit)") + + def test_ex_list_os_types(self): + os_types = self.driver.ex_list_os_types() + + self.assertEqual(len(os_types), 146) + + self.assertEqual(os_types[0]['id'], 69) + self.assertEqual(os_types[0]['oscategoryid'], 7) + self.assertEqual(os_types[0]['description'], "Asianux 3(32-bit)") + class CloudStackTestCase(CloudStackCommonTestCase, unittest.TestCase): def test_driver_instantiation(self): -- 1.8.5.2 (Apple Git-48)