libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [24/40] libcloud git commit: Add feature to Change NIC network adapter of a server
Date Fri, 02 Dec 2016 04:33:26 GMT
Add feature to Change NIC network adapter of a server


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

Branch: refs/heads/trunk
Commit: 060954eb30dc376f5eec0b49be7a480e25e70c64
Parents: 8404532
Author: Samuel Chong <samuelchong1@gmail.com>
Authored: Thu Nov 17 15:10:08 2016 +1100
Committer: Samuel Chong <samuelchong1@gmail.com>
Committed: Thu Nov 17 15:10:08 2016 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/dimensiondata.py       | 31 ++++++++++++++++++++
 .../2.4/change_nic_networkadapter_response.xml  |  7 +++++
 .../test/compute/test_dimensiondata_v2_4.py     | 13 ++++++++
 3 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/060954eb/libcloud/compute/drivers/dimensiondata.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/dimensiondata.py b/libcloud/compute/drivers/dimensiondata.py
index 6f0a197..eec32a6 100644
--- a/libcloud/compute/drivers/dimensiondata.py
+++ b/libcloud/compute/drivers/dimensiondata.py
@@ -3720,6 +3720,37 @@ class DimensionDataNodeDriver(NodeDriver):
         response_code = findtext(response, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'OK']
 
+    def ex_change_nic_network_adapter(self, nic_id, network_adapter_name):
+        """
+        Change network adapter of a NIC on a cloud server
+
+        :param    nic_id:  Nic ID
+        :type     nic_id: :``str``
+
+        :param    network_adapter_name:  Network adapter name
+        :type     network_adapter_name: :``str``
+
+        :rtype: ``bool``
+        """
+
+        change_elem = ET.Element(
+            'changeNetworkAdapter',
+            {
+                'nicId': nic_id,
+                'xmlns': TYPES_URN
+            })
+
+        ET.SubElement(change_elem, 'networkAdapter').text = \
+            network_adapter_name
+
+        response = self.connection.request_with_orgId_api_2(
+            'server/changeNetworkAdapter',
+            method='POST',
+            data=ET.tostring(change_elem)).object
+
+        response_code = findtext(response, 'responseCode', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
+
     def _format_csv(self, http_response):
         text = http_response.read()
         lines = str.splitlines(ensure_string(text))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/060954eb/libcloud/test/compute/fixtures/dimensiondata/2.4/change_nic_networkadapter_response.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/dimensiondata/2.4/change_nic_networkadapter_response.xml
b/libcloud/test/compute/fixtures/dimensiondata/2.4/change_nic_networkadapter_response.xml
new file mode 100644
index 0000000..40b60a5
--- /dev/null
+++ b/libcloud/test/compute/fixtures/dimensiondata/2.4/change_nic_networkadapter_response.xml
@@ -0,0 +1,7 @@
+<response requestId="na/2014-04-14T13:37:20/62f06368-c3fb-11e3-b29c-001517c4643e"
+xmlns="urn:didata.com:api:cloud:types">
+  <operation>CHANGE_NETWORK_ADAPTER</operation>
+  <responseCode>IN_PROGRESS</responseCode>
+  <message>Request to Change Network Adapter for NIC with Id has been
+accepted and is being processed.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/060954eb/libcloud/test/compute/test_dimensiondata_v2_4.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_dimensiondata_v2_4.py b/libcloud/test/compute/test_dimensiondata_v2_4.py
index d835b5c..caef5a8 100644
--- a/libcloud/test/compute/test_dimensiondata_v2_4.py
+++ b/libcloud/test/compute/test_dimensiondata_v2_4.py
@@ -2045,6 +2045,12 @@ class DimensionData_v2_4_Tests(unittest.TestCase, TestCaseMixin):
                   nic_id_2='b39d09b8-ea65-424a-8fa6-c6f5a98afc69')
         self.assertTrue(success)
 
+    def test_change_nic_network_adapter(self):
+        success = self.driver.ex_change_nic_network_adapter(
+            nic_id='0c55c269-20a5-4fec-8054-22a245a48fe4',
+            network_adapter_name='E1000')
+        self.assertTrue(success)
+
 class InvalidRequestError(Exception):
     def __init__(self, tag):
         super(InvalidRequestError, self).__init__("Invalid Request - %s" % tag)
@@ -3315,5 +3321,12 @@ class DimensionDataMockHttp(StorageMockHttp, MockHttp):
         )
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
+    def _caas_2_4_8a8f6abc_2745_4d8a_9cbc_8dabe5a7d0e4_server_changeNetworkAdapter(
+        self, method, url, body, headers):
+        body = self.fixtures.load(
+            '2.4/change_nic_networkadapter_response.xml'
+        )
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message