You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/03/15 22:12:58 UTC

[2/4] libcloud git commit: Adding a new method ex_get_target_by_id with tests

Adding a new method ex_get_target_by_id with tests


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

Branch: refs/heads/trunk
Commit: b6f38b9d5f17a9a5ad148acbbbbcf37aaf5b0ff2
Parents: fd7effb
Author: Jeffrey Dunham <je...@gmail.com>
Authored: Tue Mar 8 21:16:39 2016 -0500
Committer: anthony-shaw <an...@gmail.com>
Committed: Wed Mar 16 08:12:26 2016 +1100

----------------------------------------------------------------------
 libcloud/backup/drivers/dimensiondata.py        | 26 +++++++++++++------
 libcloud/common/dimensiondata.py                |  3 ++-
 ...ver_e75ead52_692f_4314_8725_c8a4f4d13a87.xml | 27 ++++++++++++++++++++
 libcloud/test/backup/test_dimensiondata.py      | 11 ++++++++
 4 files changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6f38b9d/libcloud/backup/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/backup/drivers/dimensiondata.py b/libcloud/backup/drivers/dimensiondata.py
index d47f889..7905b33 100644
--- a/libcloud/backup/drivers/dimensiondata.py
+++ b/libcloud/backup/drivers/dimensiondata.py
@@ -209,14 +209,11 @@ class DimensionDataBackupDriver(BackupDriver):
             'server/%s/backup/modify' % (server_id),
             method='POST',
             data=ET.tostring(request)).object
-        return BackupTarget(
-            id=server_id,
-            name=name,
-            address=address,
-            type=type,
-            extra=extra,
-            driver=self
-        )
+        if isinstance(target, BackupTarget):
+            target.extra = extra
+        else:
+            target = self.ex_get_target_by_id(server_id)
+        return target
 
     def delete_target(self, target):
         """
@@ -379,6 +376,19 @@ class DimensionDataBackupDriver(BackupDriver):
         raise NotImplementedError(
             'cancel_target_job not implemented for this driver')
 
+    def ex_get_target_by_id(self, id):
+        """
+        Get a target by server id
+
+        :param id: The id of the target you want to get
+        :type  id: ``str``
+
+        :rtype: :class:`BackupTarget`
+        """
+        node = self.connection.request_with_orgId_api_2(
+            'server/server/%s' % id).object
+        return self._to_target(node)
+
     def ex_add_client_to_target(self, target, client_type, storage_policy,
                                 schedule_policy, trigger, email):
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6f38b9d/libcloud/common/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/common/dimensiondata.py b/libcloud/common/dimensiondata.py
index 9178599..ee7d831 100644
--- a/libcloud/common/dimensiondata.py
+++ b/libcloud/common/dimensiondata.py
@@ -1089,7 +1089,8 @@ class DimensionDataBackupDetails(object):
         :param service_plan: The service plan for backups. i.e (Essentials)
         :type  service_plan: ``str``
 
-        :param status: The overall status this backup target. i.e. (unregistered)
+        :param status: The overall status this backup target.
+                       i.e. (unregistered)
         :type  status: ``str``
 
         :param clients: Backup clients attached to this target

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6f38b9d/libcloud/test/backup/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml b/libcloud/test/backup/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml
new file mode 100644
index 0000000..c64c530
--- /dev/null
+++ b/libcloud/test/backup/fixtures/dimensiondata/caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<server xmlns="urn:didata.com:api:cloud:types" id="e75ead52-692f-4314-8725-c8a4f4d13a87" datacenterId="NA9">
+        <name>Production Web Server</name>
+        <description>Server to host our main web application.</description>
+        <operatingSystem id="WIN2008S32" displayName="WIN2008S/32" family="WINDOWS" />
+        <cpu count="2" speed="STANDARD" coresPerSocket="1" />
+        <memoryGb>4</memoryGb>
+        <disk id="c2e1f199-116e-4dbc-9960-68720b832b0a" scsiId="0" sizeGb="50" speed="STANDARD" state="NORMAL" />
+        <networkInfo networkDomainId="553f26b6-2a73-42c3-a78b-6116f11291d0">
+            <primaryNic id="5e869800-df7b-4626-bcbf-8643b8be11fd" privateIpv4="10.0.4.8" ipv6="2607:f480:1111:1282:2960:fb72:7154:6160" vlanId="bc529e20-dc6f-42ba-be20-0ffe44d1993f" vlanName="Production VLAN" state="NORMAL" />
+        </networkInfo>
+        <backup assetId="5579f3a7-4c32-4cf5-8a7e-b45c36a35c10" servicePlan="Advanced" state="NORMAL" />
+        <monitoring monitoringId="11049" servicePlan="ESSENTIALS" state="NORMAL" />
+        <softwareLabel>MSSQL2008R2S</softwareLabel>
+        <sourceImageId>3ebf3c0f-90fe-4a8b-8585-6e65b316592c</sourceImageId>
+        <createTime>2015-12-02T10:31:33.000Z</createTime>
+        <deployed>true</deployed>
+        <started>true</started>
+        <state>PENDING_CHANGE</state>
+        <progress>
+            <action>DEPLOY_SERVER</action>
+            <requestTime>2015-12-02T11:07:40.000Z</requestTime>
+            <userName>devuser1</userName>
+        </progress>
+        <vmwareTools versionStatus="CURRENT" runningStatus="RUNNING" apiVersion="9354" />
+        <virtualHardware version="vmx-08" upToDate="false" />
+    </server>

http://git-wip-us.apache.org/repos/asf/libcloud/blob/b6f38b9d/libcloud/test/backup/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/test_dimensiondata.py b/libcloud/test/backup/test_dimensiondata.py
index d7a587b..5411cb4 100644
--- a/libcloud/test/backup/test_dimensiondata.py
+++ b/libcloud/test/backup/test_dimensiondata.py
@@ -75,6 +75,12 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
         new_target = self.driver.update_target(target, extra=extra)
         self.assertEqual(new_target.extra['servicePlan'], 'Enterprise')
 
+    def test_update_target_STR(self):
+        target = 'e75ead52-692f-4314-8725-c8a4f4d13a87'
+        extra = {'servicePlan': 'Advanced'}
+        new_target = self.driver.update_target(target, extra=extra)
+        self.assertEqual(new_target.extra['servicePlan'], 'Advanced')
+
     def test_delete_target(self):
         target = self.driver.list_targets()[0]
         self.assertTrue(self.driver.delete_target(target))
@@ -256,6 +262,11 @@ class DimensionDataMockHttp(MockHttp):
         body = self.fixtures.load('oec_0_9_myaccount.xml')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87(self, method, url, body, headers):
+        body = self.fixtures.load(
+            'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server_e75ead52_692f_4314_8725_c8a4f4d13a87.xml')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server(self, method, url, body, headers):
         body = self.fixtures.load(
             'caas_2_1_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_server.xml')