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:31 UTC
[22/45] libcloud git commit: drs finished...need to run tox,
pull latest and pull request
drs finished...need to run tox, pull latest and pull request
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8ed60c7d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8ed60c7d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8ed60c7d
Branch: refs/heads/trunk
Commit: 8ed60c7dc11b2ca4ce35149a4d14a9ecf099ca42
Parents: 3e83d4b
Author: mitch <mi...@itaas.dimensiondata.com>
Authored: Thu Nov 8 17:34:29 2018 -0500
Committer: mitch <mi...@itaas.dimensiondata.com>
Committed: Thu Nov 8 17:34:29 2018 -0500
----------------------------------------------------------------------
.../drs/nttcis/add_consistency_group.py | 2 +-
.../drs/nttcis/list_snapshots_by_create_time.py | 23 +++++
libcloud/drs/drivers/nttcis.py | 81 +++++++++++++++-
.../nttcis/delete_consistency_group.xml | 6 ++
.../fixtures/nttcis/drs_initiate_failover.xml | 6 ++
.../fixtures/nttcis/start_snapshot_preview.xml | 6 ++
.../fixtures/nttcis/stop_snapshot_preview.xml | 6 ++
libcloud/test/drs/test_nttcis.py | 97 ++++++++++++++++----
tests/lib_create_test.py | 21 ++++-
tests/lib_edit_test.py | 8 +-
10 files changed, 233 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/docs/examples/drs/nttcis/add_consistency_group.py
----------------------------------------------------------------------
diff --git a/docs/examples/drs/nttcis/add_consistency_group.py b/docs/examples/drs/nttcis/add_consistency_group.py
index 68861e8..9194b24 100644
--- a/docs/examples/drs/nttcis/add_consistency_group.py
+++ b/docs/examples/drs/nttcis/add_consistency_group.py
@@ -15,7 +15,7 @@ def create_drs(compute_driver, drs_driver):
assert result is True
-def compute_driver():
+if __name__ == "__main__":
cls = libcloud.get_driver(libcloud.DriverType.COMPUTE,
libcloud.DriverType.COMPUTE.NTTCIS)
computedriver = cls('my_user', 'my_pass', region='na')
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/docs/examples/drs/nttcis/list_snapshots_by_create_time.py
----------------------------------------------------------------------
diff --git a/docs/examples/drs/nttcis/list_snapshots_by_create_time.py b/docs/examples/drs/nttcis/list_snapshots_by_create_time.py
new file mode 100644
index 0000000..f3fb7bc
--- /dev/null
+++ b/docs/examples/drs/nttcis/list_snapshots_by_create_time.py
@@ -0,0 +1,23 @@
+# This script lists the snapshots in a consistency group
+# filtered by a minimum and maximum create time
+
+import libcloud
+
+
+def get_snapshots_by_min_max(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,
+ create_time_min="2018-11-06T00:00:00.000Z",
+ create_time_max="2018-11-07T00:00:00.000Z")
+ return snaps
+
+
+if __name__ == "__main__":
+ cls = libcloud.get_driver(libcloud.DriverType.DRS,
+ libcloud.DriverType.DRS.NTTCIS)
+ drsdriver = cls('my_user', 'my_pass', region='na')
+ objs = get_snapshots_by_min_max(drsdriver)
+ for obj in objs.snapshot:
+ print(obj)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/drs/drivers/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/drs/drivers/nttcis.py b/libcloud/drs/drivers/nttcis.py
index 13490ae..363d737 100644
--- a/libcloud/drs/drivers/nttcis.py
+++ b/libcloud/drs/drivers/nttcis.py
@@ -221,7 +221,86 @@ class NttCisDRSDriver(DRSDriver):
return response_code in ['IN_PROGRESS', 'OK']
def start_failover_preview(self, consistency_group_id, snapshot_id):
- pass
+ """
+ Brings a Consistency Group into PREVIEWING_SNAPSHOT mode
+
+ :param consistency_group_id: Id of the Consistency Group to put into
+ PRIEVEW_MODE
+ :type consistency_group_id: ``str``
+ :param snapshot_id: Id of the Snapshot to preview
+ :type snapshot_id: ``str``
+ :return: True/False
+ :rtype: ``bool``
+ """
+ preview_elm = ET.Element("startPreviewSnapshot",
+ {"consistencyGroupId": consistency_group_id,
+ "xmlns": TYPES_URN
+ })
+ ET.SubElement(preview_elm, "snapshotId").text = snapshot_id
+ response = self.connection.request_with_orgId_api_2(
+ "consistencyGroup/startPreviewSnapshot",
+ method="POST",
+ data=ET.tostring(preview_elm)).object
+ response_code = findtext(response, 'responseCode', TYPES_URN)
+ return response_code in ['IN_PROGRESS', 'OK']
+
+ def stop_failover_preview(self, consistency_group_id):
+ """
+ Takes a Consistency Group out of PREVIEW_MODE and back to DRS_MODE
+
+ :param consistency_group_id: Consistency Group's Id
+ :type ``str``
+ :return: True/False
+ :rtype: ``bool``
+ """
+ preview_elm = ET.Element("stopPreviewSnapshot",
+ {"consistencyGroupId": consistency_group_id,
+ "xmlns": TYPES_URN})
+ response = self.connection.request_with_orgId_api_2(
+ "consistencyGroup/stopPreviewSnapshot",
+ method="POST",
+ data=ET.tostring(preview_elm)).object
+ response_code = findtext(response, 'responseCode', TYPES_URN)
+ return response_code in ['IN_PROGRESS', 'OK']
+
+ def initiate_failover(self, consistency_group_id):
+ """
+ This method is irreversible.
+ It will failover the Consistency Group while removing it as well.
+
+ :param consistency_group_id: Consistency Group's Id to failover
+ :type consistency_group_id: ``str``
+ :return: True/False
+ :rtype: ``bool``
+ """
+ failover_elm = ET.Element("initiateFailover",
+ {"consistencyGroupId": consistency_group_id,
+ "xmlns": TYPES_URN})
+ response = self.connection.request_with_orgId_api_2(
+ "consistencyGroup/initiateFailover",
+ method="POST",
+ data=ET.tostring(failover_elm)).object
+ response_code = findtext(response, "responseCode", TYPES_URN)
+ return response_code in ["IN_PROGRESS", "OK"]
+
+ def delete_consistency_group(self, consistency_group_id):
+ """
+ Delete's a Consistency Group
+
+ :param consistency_group_id: Id of Consistency Group to delete
+ :type ``str``
+ :return: True/False
+ :rtype: ``bool``
+ """
+ delete_elm = ET.Element("deleteConsistencyGroup",
+ {"id": consistency_group_id,
+ "xmlns": TYPES_URN})
+ response = self.connection.request_with_orgId_api_2(
+ "consistencyGroup/deleteConsistencyGroup",
+ method="POST",
+ data=ET.tostring(delete_elm)).object
+ response_code = findtext(response, "responseCode", TYPES_URN)
+ return response_code in ["IN_PROGRESS", "OK"]
def _to_consistency_groups(self, object):
cgs = findall(object, 'consistencyGroup', TYPES_URN)
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/test/drs/fixtures/nttcis/delete_consistency_group.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/fixtures/nttcis/delete_consistency_group.xml b/libcloud/test/drs/fixtures/nttcis/delete_consistency_group.xml
new file mode 100644
index 0000000..6c5c1ed
--- /dev/null
+++ b/libcloud/test/drs/fixtures/nttcis/delete_consistency_group.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="na_20181108T170953967-0500_49fbd66f-4eca-4107-acf5-08d7bb07c706">
+ <operation>DELETE_CONSISTENCY_GROUP</operation>
+ <responseCode>IN_PROGRESS</responseCode>
+ <message>Request to Delete Consistency Group has been accepted. Please use appropriate Get or List API for status.</message>
+</response>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/test/drs/fixtures/nttcis/drs_initiate_failover.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/fixtures/nttcis/drs_initiate_failover.xml b/libcloud/test/drs/fixtures/nttcis/drs_initiate_failover.xml
new file mode 100644
index 0000000..115dda1
--- /dev/null
+++ b/libcloud/test/drs/fixtures/nttcis/drs_initiate_failover.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="na_20181108T160941803-0500_729ba262-347d-4da9-bf4d-c30e861bfa63">
+ <operation>INITIATE_FAILOVER</operation>
+ <responseCode>IN_PROGRESS</responseCode>
+ <message>Request to Initiate Failover has been accepted. Please use appropriate Get or List API for status.</message>
+</response>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/test/drs/fixtures/nttcis/start_snapshot_preview.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/fixtures/nttcis/start_snapshot_preview.xml b/libcloud/test/drs/fixtures/nttcis/start_snapshot_preview.xml
new file mode 100644
index 0000000..50bede8
--- /dev/null
+++ b/libcloud/test/drs/fixtures/nttcis/start_snapshot_preview.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="na_20181108T135438714-0500_b30a28fa-f9e4-4e04-ae4c-cf07a3b31bb4">
+ <operation>START_PREVIEW_SNAPSHOT</operation>
+ <responseCode>IN_PROGRESS</responseCode>
+ <message>Request to Start Preview Snapshot has been accepted. Please use appropriate Get or List API for status.</message>
+</response>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/test/drs/fixtures/nttcis/stop_snapshot_preview.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/fixtures/nttcis/stop_snapshot_preview.xml b/libcloud/test/drs/fixtures/nttcis/stop_snapshot_preview.xml
new file mode 100644
index 0000000..22ae894
--- /dev/null
+++ b/libcloud/test/drs/fixtures/nttcis/stop_snapshot_preview.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="na_20181108T135122604-0500_c06c2498-63d0-4172-8476-5af1b1fe07db">
+ <operation>STOP_PREVIEW_SNAPSHOT</operation>
+ <responseCode>IN_PROGRESS</responseCode>
+ <message>Request to Stop Preview Snapshot has been accepted. Please use appropriate Get or List API for status.</message>
+</response>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/libcloud/test/drs/test_nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/test/drs/test_nttcis.py b/libcloud/test/drs/test_nttcis.py
index 9f9bf50..566e1d1 100644
--- a/libcloud/test/drs/test_nttcis.py
+++ b/libcloud/test/drs/test_nttcis.py
@@ -66,8 +66,29 @@ def test_list_snapshots_with_min(driver):
assert len(result.snapshot) == 87
-def test_start_failover_preview(driver):
- pass
+def test_start_snapshot_preview(driver):
+ snapshot_id = "87703"
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = driver.start_failover_preview(cg_id, snapshot_id)
+ assert result is True
+
+
+def test_stop_snapshot_preivew(driver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = driver.stop_failover_preview(cg_id)
+ assert result is True
+
+
+def test_initiate_failover(driver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = driver.initiate_failover(cg_id)
+ assert result is True
+
+
+def test_delete_consistency_group(driver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = driver.initiate_failover(cg_id)
+ assert result is True
class NttCisMockHttp(MockHttp):
@@ -113,33 +134,73 @@ class NttCisMockHttp(MockHttp):
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_consistencyGroup_name(self,
- method,
- url,
- body,
- headers):
+ method,
+ url,
+ body,
+ headers):
body = self.fixtures.load("list_cg_by_params.xml")
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_expandJournal(self,
- method,
- url,
- body,
- headers):
+ method,
+ url,
+ body,
+ headers):
body = self.fixtures.load("expand_cg.xml")
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_snapshot(self,
- method,
- url,
- body,
- headers):
- body = self.fixtures.load("drs_snapshots.xml")
- return (httplib.OK, body, {}, httplib.responses[httplib.OK])
-
- def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_snapshot_WITH_MIN(self,
method,
url,
body,
headers):
+ body = self.fixtures.load("drs_snapshots.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_snapshot_WITH_MIN(self,
+ method,
+ url,
+ body,
+ headers):
body = self.fixtures.load("drs_snapshots_by_min.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_startPreviewSnapshot(self,
+ method,
+ url,
+ body,
+ headers):
+ body = self.fixtures.load("start_snapshot_preview.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_stopPreviewSnapshot(self,
+ method,
+ url,
+ body,
+ headers):
+ body = self.fixtures.load("stop_snapshot_preview.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_initiateFailover(self,
+ method,
+ url,
+ body,
+ headers):
+ body = self.fixtures.load("drs_initiate_failover.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_initiateFailover(self,
+ method,
+ url,
+ body,
+ headers):
+ body = self.fixtures.load("drs_initiate_failover.xml")
+ return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+ def _caas_2_7_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_consistencyGroup_deleteConsistencyGroup(self,
+ method,
+ url,
+ body,
+ headers):
+ body = self.fixtures.load("delete_consistency_group.xml")
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/tests/lib_create_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_create_test.py b/tests/lib_create_test.py
index 9dc28ff..f2c8eeb 100644
--- a/tests/lib_create_test.py
+++ b/tests/lib_create_test.py
@@ -271,4 +271,23 @@ def test_create_drs(na_compute_driver, drsdriver):
target_id = nodes[0].id
result = drsdriver.create_consistency_group(
"sdk_test2_cg", "100", src_id, target_id, description="A test consistency group")
- assert result is True
\ No newline at end of file
+ assert result is True
+
+
+def test_start_snapshot_preview(drsdriver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ snapshot_id = "87703"
+ result = drsdriver.start_failover_preview(cg_id, snapshot_id)
+ assert result is True
+
+
+def test_stop_snapshot_preivew(drsdriver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = drsdriver.stop_failover_preview(cg_id)
+ assert result is True
+
+
+def test_initiate_failover(drsdriver):
+ cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
+ result = drsdriver.initiate_failover(cg_id)
+ assert result is True
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8ed60c7d/tests/lib_edit_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_edit_test.py b/tests/lib_edit_test.py
index ff1dccc..9a2904c 100644
--- a/tests/lib_edit_test.py
+++ b/tests/lib_edit_test.py
@@ -459,6 +459,10 @@ def test_expand_journal(drsdriver):
result = drsdriver.expand_journal(cg_id, expand_by)
assert result is True
+
def test_delete_consistency_group(drsdriver):
- cg_name = "sdk_test_cg"
- pass
+ cg_name = "sdk_test2_cg"
+ cg = drsdriver.list_consistency_groups(name=cg_name)
+ cg_id = cg[0].id
+ result = drsdriver.delete_consistency_group(cg_id)
+ assert result is True