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 2018/12/13 11:26:25 UTC

[16/45] libcloud git commit: added listing snapshots, edited the XmlToDictConfig class to handle XML from snapshots, added integrations test, and a fixture for unit tests

added listing snapshots, edited the XmlToDictConfig class to handle XML from snapshots, added integrations test, and a fixture for unit tests


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

Branch: refs/heads/trunk
Commit: 3d3289dcc953ba302eadd89649ab6a29e1a34248
Parents: 62e0aaf
Author: mitch <mi...@itaas.dimensiondata.com>
Authored: Fri Nov 2 17:00:02 2018 -0400
Committer: mitch <mi...@itaas.dimensiondata.com>
Committed: Fri Nov 2 17:00:02 2018 -0400

----------------------------------------------------------------------
 libcloud/common/nttcis.py                          | 15 ++++++++++-----
 libcloud/drs/drivers/nttcis.py                     | 17 +++++++++++++++++
 .../test/drs/fixtures/nttcis/drs_snapshots.xml     | 14 ++++++++++++++
 tests/lib_list_test.py                             |  9 ++++++++-
 4 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/3d3289dc/libcloud/common/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/common/nttcis.py b/libcloud/common/nttcis.py
index 390b85e..a26695a 100644
--- a/libcloud/common/nttcis.py
+++ b/libcloud/common/nttcis.py
@@ -2110,6 +2110,7 @@ class XmlDictConfig(dict):
             else:
                 self.update(dict(parent_element.items()))
 
+        c_elems = parent_element.items()
         for element in parent_element:
             if len(element) > 0:
                 # treat like dict - we assume that if the first two tags
@@ -2134,13 +2135,18 @@ class XmlDictConfig(dict):
             # good idea -- time will tell. It works for the way we are
             # currently doing XML configuration files...
             elif element.items():
+                items = element.items()
                 # It is possible to have duplicate element tags. If so, convert to a dict of lists
+                i = element.tag.split('}')[1]
                 if element.tag.split('}')[1] in self:
-                    tmp_list = list()
-                    tmp_dict = dict()
+
+                    t = type(self[element.tag.split('}')[1]])
                     if isinstance(self[element.tag.split('}')[1]], list):
-                        tmp_list.append(element.tag.split('}')[1])
+                        self[element.tag.split('}')[1]].append(dict(element.items()))
+                        #tmp_list.append(element.tag.split('}')[1])
                     else:
+                        tmp_list = list()
+                        tmp_dict = dict()
                         for k, v in self[element.tag.split('}')[1]].items():
                             if isinstance(k, XmlListConfig):
                                 tmp_list.append(k)
@@ -2148,8 +2154,7 @@ class XmlDictConfig(dict):
                                 tmp_dict.update({k: v})
                         tmp_list.append(tmp_dict)
                         tmp_list.append(dict(element.items()))
-                        print()
-                    self[element.tag.split('}')[1]] = tmp_list
+                        self[element.tag.split('}')[1]] = tmp_list
                 else:
                     self.update({element.tag.split('}')[1]: dict(element.items())})
             # finally, if there are no child tags and no attributes, extract

http://git-wip-us.apache.org/repos/asf/libcloud/blob/3d3289dc/libcloud/drs/drivers/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/drs/drivers/nttcis.py b/libcloud/drs/drivers/nttcis.py
index a2a66a4..49d1986 100644
--- a/libcloud/drs/drivers/nttcis.py
+++ b/libcloud/drs/drivers/nttcis.py
@@ -104,9 +104,26 @@ class NttCisDRSDriver(Driver):
         cg = self._to_process(response)
         return cg
 
+    def list_consistency_group_snapshots(self, consistency_group_id):
+        params = {"consistencyGroupId": consistency_group_id}
+        paged_result = self.connection.request_with_orgId_api_2(
+            'consistencyGroup/snapshot',
+            method='GET',
+            params=params
+        ).object
+        snapshots = self._to_process(paged_result)
+        return snapshots
+
     def _to_consistency_groups(self, object):
         cgs = findall(object, 'consistencyGroup', TYPES_URN)
         return [self._to_process(el) for el in cgs]
 
+    def _to_snapshots(self, object):
+        elem = findall(object, "consistencyGroupSnapshots", TYPES_URN)
+        snapshots = []
+        for element in object.findall(fixxpath("snapshot", TYPES_URN)):
+            snapshots.append(self._to_process(element))
+        return snapshots
+
     def _to_process(self, element):
         return process_xml(ET.tostring(element))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/3d3289dc/libcloud/test/drs/fixtures/nttcis/drs_snapshots.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/fixtures/nttcis/drs_snapshots.xml b/libcloud/test/drs/fixtures/nttcis/drs_snapshots.xml
new file mode 100644
index 0000000..5386f46
--- /dev/null
+++ b/libcloud/test/drs/fixtures/nttcis/drs_snapshots.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<consistencyGroupSnapshots xmlns="urn:didata.com:api:cloud:types" totalCount="1013" journalUsageGb="0.22" protectionWindow="P0Y0M2DT1H48M45.532S" predictedProtectionWindow="P23Y1M15DT11H1M58.309S">
+    <snapshot id="297700" createTime="2018-11-02T14:00:13.271-04:00" sizeKb="0"/>
+    <snapshot id="297695" createTime="2018-11-02T14:00:10.219-04:00" sizeKb="2"/>
+    <snapshot id="297650" createTime="2018-11-02T13:59:42.780-04:00" sizeKb="7"/>
+    <snapshot id="297488" createTime="2018-11-02T13:58:05.255-04:00" sizeKb="188"/>
+    <snapshot id="297235" createTime="2018-11-02T13:56:27.697-04:00" sizeKb="29"/>
+    <snapshot id="296911" createTime="2018-11-02T13:53:12.913-04:00" sizeKb="14"/>
+    <snapshot id="296591" createTime="2018-11-02T13:49:57.857-04:00" sizeKb="14"/>
+    <snapshot id="296271" createTime="2018-11-02T13:46:42.980-04:00" sizeKb="14"/>
+    <snapshot id="295951" createTime="2018-11-02T13:43:27.903-04:00" sizeKb="14"/>
+    <snapshot id="295631" createTime="2018-11-02T13:40:12.811-04:00" sizeKb="14"/>
+    <snapshot id="295311" createTime="2018-11-02T13:36:57.691-04:00" sizeKb="14"/>
+</consistencyGroupSnapshots>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/3d3289dc/tests/lib_list_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_list_test.py b/tests/lib_list_test.py
index 77b50cd..0563f9a 100644
--- a/tests/lib_list_test.py
+++ b/tests/lib_list_test.py
@@ -401,4 +401,11 @@ def test_get_consistency_group(drsdriver):
     cgs = drsdriver.list_consistency_groups()
     cg_id = [i for i in cgs if i.name == "sdk_test2_cg"][0].id
     cg = drsdriver.get_consistency_group(cg_id)
-    assert hasattr(cg, 'description')
\ No newline at end of file
+    assert hasattr(cg, 'description')
+
+
+def test_get_snapshots(drsdriver):
+    cgs = drsdriver.list_consistency_groups()
+    cg_id = [i for i in cgs if i.name == "sdk_test2_cg"][0].id
+    snaps = drsdriver.list_consistency_group_snapshots(cg_id)
+    print(cg_id)
\ No newline at end of file