libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [4/5] libcloud git commit: Making it so we can pass in the proper classes as well as strings
Date Wed, 10 Feb 2016 01:08:40 GMT
Making it so we can pass in the proper classes as well as strings


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

Branch: refs/heads/trunk
Commit: bb8ab6689e7df19dc4b9f090fb10eee4463d9f86
Parents: fe86be7
Author: Jeffrey Dunham <jeffrey.a.dunham@gmail.com>
Authored: Tue Feb 9 00:44:54 2016 -0500
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Wed Feb 10 12:08:06 2016 +1100

----------------------------------------------------------------------
 libcloud/backup/drivers/dimensiondata.py   | 38 +++++++++++++++++++------
 libcloud/test/backup/test_dimensiondata.py | 11 ++++++-
 2 files changed, 39 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/bb8ab668/libcloud/backup/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/backup/drivers/dimensiondata.py b/libcloud/backup/drivers/dimensiondata.py
index e35fd76..45fb1d7 100644
--- a/libcloud/backup/drivers/dimensiondata.py
+++ b/libcloud/backup/drivers/dimensiondata.py
@@ -421,7 +421,7 @@ class DimensionDataBackupDriver(BackupDriver):
         raise NotImplementedError(
             'cancel_target_job not implemented for this driver')
 
-    def ex_add_client_to_target(self, target, client, storage_policy,
+    def ex_add_client_to_target(self, target, client_type, storage_policy,
                                 schedule_policy, trigger, email):
         """
         Add a client to a target
@@ -430,13 +430,18 @@ class DimensionDataBackupDriver(BackupDriver):
         :type  target: Instance of :class:`BackupTarget` or ``str``
 
         :param client: Client to add to the target
-        :type  client: ``str``
+        :type  client: Instance of :class:`DimensionDataBackupClientType`
+                       or ``str``
 
         :param storage_policy: The storage policy for the client
-        :type  storage_policy: ``str``
+        :type  storage_policy: Instance of
+                               :class:`DimensionDataBackupStoragePolicy`
+                               or ``str``
 
-        :param schedule_policy: The storage policy for the client
-        :type  schedule_policy: ``str``
+        :param schedule_policy: The schedule policy for the client
+        :type  schedule_policy: Instance of
+                                :class:`DimensionDataBackupSchedulePolicy`
+                                or ``str``
 
         :param trigger: The notify trigger for the client
         :type  trigger: ``str``
@@ -454,9 +459,25 @@ class DimensionDataBackupDriver(BackupDriver):
 
         backup_elm = ET.Element('NewBackupClient',
                                 {'xmlns': BACKUP_NS})
-        ET.SubElement(backup_elm, "type").text = client
-        ET.SubElement(backup_elm, "storagePolicyName").text = storage_policy
-        ET.SubElement(backup_elm, "schedulePolicyName").text = schedule_policy
+        if isinstance(client_type, DimensionDataBackupClientType):
+            ET.SubElement(backup_elm, "type").text = client_type.type
+        else:
+            ET.SubElement(backup_elm, "type").text = client_type
+
+        if isinstance(storage_policy, DimensionDataBackupStoragePolicy):
+            ET.SubElement(backup_elm,
+                          "storagePolicyName").text = storage_policy.name
+        else:
+            ET.SubElement(backup_elm,
+                          "storagePolicyName").text = storage_policy
+
+        if isinstance(schedule_policy, DimensionDataBackupSchedulePolicy):
+            ET.SubElement(backup_elm,
+                          "schedulePolicyName").text = schedule_policy.name
+        else:
+            ET.SubElement(backup_elm,
+                          "schedulePolicyName").text = schedule_policy
+
         alerting_elm = ET.SubElement(backup_elm, "alerting")
         ET.SubElement(alerting_elm, "trigger").text = trigger
         ET.SubElement(alerting_elm, "emailAddress").text = email
@@ -465,7 +486,6 @@ class DimensionDataBackupDriver(BackupDriver):
             'server/%s/backup/client' % (server_id),
             method='POST',
             data=ET.tostring(backup_elm)).object
-
         response_code = findtext(response, 'result', GENERAL_NS)
         return response_code in ['IN_PROGRESS', 'SUCCESS']
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/bb8ab668/libcloud/test/backup/test_dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/test/backup/test_dimensiondata.py b/libcloud/test/backup/test_dimensiondata.py
index ef03179..fe5a964 100644
--- a/libcloud/test/backup/test_dimensiondata.py
+++ b/libcloud/test/backup/test_dimensiondata.py
@@ -81,8 +81,17 @@ class DimensionDataTests(unittest.TestCase, TestCaseMixin):
 
     def test_ex_add_client_to_target(self):
         target = self.driver.list_targets()[0]
+        client = self.driver.ex_list_available_client_types(target)[0]
+        storage_policy = self.driver.ex_list_available_storage_policies(target)[0]
+        schedule_policy = self.driver.ex_list_available_schedule_policies(target)[0]
         self.assertTrue(
-            self.driver.ex_add_client_to_target(target, 'FA.Linux', '14 Day Storage Policy',
+            self.driver.ex_add_client_to_target(target, client, storage_policy,
+                                                schedule_policy, 'ON_FAILURE', 'nobody@example.com')
+        )
+
+    def test_ex_add_client_to_target_STR(self):
+        self.assertTrue(
+            self.driver.ex_add_client_to_target('e75ead52-692f-4314_8725-c8a4f4d13a87', 'FA.Linux',
'14 Day Storage Policy',
                                                 '12AM - 6AM', 'ON_FAILURE', 'nobody@example.com')
         )
 


Mime
View raw message