libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [26/45] libcloud git commit: Started ssl import and offload
Date Thu, 13 Dec 2018 11:26:35 GMT
Started ssl import and offload


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

Branch: refs/heads/trunk
Commit: 9319bbbc334c62f26dfb57f9ae96466c7c134a82
Parents: 99b7bda
Author: mitch <mitch.raful@itaas.dimensiondata.com>
Authored: Fri Nov 16 15:15:49 2018 -0500
Committer: mitch <mitch.raful@itaas.dimensiondata.com>
Committed: Fri Nov 16 15:15:49 2018 -0500

----------------------------------------------------------------------
 libcloud/common/base.py                         |  1 -
 libcloud/loadbalancer/drivers/nttcis.py         | 26 ++++++++++++++++++++
 .../fixtures/nttcis/ssl_import_fail.xml         |  6 +++++
 .../fixtures/nttcis/ssl_import_success.xml      |  7 ++++++
 tests/lib_create_test.py                        |  9 +++++++
 tests/lib_list_test.py                          |  7 ++++--
 6 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/libcloud/common/base.py
----------------------------------------------------------------------
diff --git a/libcloud/common/base.py b/libcloud/common/base.py
index 17ca286..bcfa249 100644
--- a/libcloud/common/base.py
+++ b/libcloud/common/base.py
@@ -232,7 +232,6 @@ class XmlResponse(Response):
                                          body=self.body,
                                          driver=self.connection.driver)
         return body
-
     parse_error = parse_body
 
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/libcloud/loadbalancer/drivers/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/loadbalancer/drivers/nttcis.py b/libcloud/loadbalancer/drivers/nttcis.py
index 1348c65..ee1bd53 100644
--- a/libcloud/loadbalancer/drivers/nttcis.py
+++ b/libcloud/loadbalancer/drivers/nttcis.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+import OpenSSL.crypto
 
 from libcloud.utils.py3 import ET
 from libcloud.common.nttcis import NttCisConnection
@@ -757,6 +758,28 @@ class NttCisLBDriver(Driver):
             status=State.RUNNING
         )
 
+    def import_ssl_cert(self, network_domain_id, name, crt_file, key_file,
+                        description=None):
+        c = OpenSSL.crypto.load_certificate(
+            OpenSSL.crypto.FILETYPE_PEM, open(crt_file).read())
+        cert = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, c).decode(encoding='utf-8')
+        k = OpenSSL.crypto.load_privatekey(
+            OpenSSL.crypto.FILETYPE_PEM, open(key_file).read())
+        key = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, k).decode(encoding='utf-8')
+        cert_elem = ET.Element("importSslDomainCertificate", {"xmlns": TYPES_URN})
+        ET.SubElement(cert_elem, "networkDomainId").text = network_domain_id
+        ET.SubElement(cert_elem, "name").text = name
+        if description is not None:
+            ET.SubElement(cert_elem, "description").text = description
+        ET.SubElement(cert_elem, "key").text = key
+        ET.SubElement(cert_elem, "certificate").text = cert
+        result = self.connection.request_with_orgId_api_2(
+            'networkDomainVip/importSslDomainCertificate',
+            method='POST',
+            data=ET.tostring(cert_elem)).object
+        response_code = findtext(result, 'responseCode', TYPES_URN)
+        return response_code in ['IN_PROGRESS', 'OK']
+
     def ex_get_pools(self, ex_network_domain_id=None):
         """
         Get all of the pools inside the current geography or
@@ -1049,6 +1072,9 @@ class NttCisLBDriver(Driver):
             method='GET').object
         return self._to_irules(result)
 
+    def ex_list_ssl_domain_certs(self, params={}):
+        pass
+
     def _to_irules(self, object):
         irules = []
         matches = object.findall(

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_fail.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_fail.xml b/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_fail.xml
new file mode 100644
index 0000000..f7cc0e3
--- /dev/null
+++ b/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_fail.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="eu_20181116T181425004+0100_b6be08f0-30ae-4acd-8f25-1d7a5ce3f42a">
+    <operation>IMPORT_SSL_DOMAIN_CERTIFICATE</operation>
+    <responseCode>CONFIGURATION_NOT_SUPPORTED</responseCode>
+    <message>Data Center EU6 requires key length must be one of 512, 1024, 2048.</message>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_success.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_success.xml b/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_success.xml
new file mode 100644
index 0000000..3797d36
--- /dev/null
+++ b/libcloud/test/loadbalancer/fixtures/nttcis/ssl_import_success.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response xmlns="urn:didata.com:api:cloud:types" requestId="eu_20181116T205220817+0100_5bbea1ac-0643-4c92-a67d-7258706ec9bf">
+    <operation>IMPORT_SSL_DOMAIN_CERTIFICATE</operation>
+    <responseCode>OK</responseCode>
+    <message>SSL Domain Certificate has been imported.</message>
+    <info name="sslDomainCertificateId" value="4d2e9792-c986-4f2b-80c9-39e457eed8e8"/>
+</response>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/tests/lib_create_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_create_test.py b/tests/lib_create_test.py
index f2c8eeb..944cea0 100644
--- a/tests/lib_create_test.py
+++ b/tests/lib_create_test.py
@@ -291,3 +291,12 @@ def test_initiate_failover(drsdriver):
     cg_id = "3710c093-7dcc-4a21-bd07-af9f4d93b6b5"
     result = drsdriver.initiate_failover(cg_id)
     assert result is True
+
+
+def test_insert_ssl(lbdriver, compute_driver):
+    net_dom_name = "sdk_test_1"
+    net_dom = compute_driver.ex_list_network_domains(name=net_dom_name)[0]
+    cert = '/home/mraful/client/alice.crt'
+    key = '/home/mraful/client/alice.key'
+    result = lbdriver.import_ssl_cert(net_dom.id, "alice", cert, key, description="test cert")
+    assert result is True
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/9319bbbc/tests/lib_list_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_list_test.py b/tests/lib_list_test.py
index c6395c4..bf572e3 100644
--- a/tests/lib_list_test.py
+++ b/tests/lib_list_test.py
@@ -200,7 +200,6 @@ def test_list_nat_rules(compute_driver):
 
 def test_list_balancers(lbdriver):
     balancers = lbdriver.list_balancers(ex_network_domain_id="6aafcf08-cb0b-432c-9c64-7371265db086")
-    print()
     for balancer in balancers:
         print(balancer.id, balancer.ip, balancer.name, balancer.port)
     assert isinstance(balancers, list)
@@ -424,4 +423,8 @@ def test_get_snapshots_by_min(drsdriver):
         cg_id,
         create_time_min="2018-11-07T00:00:00.000-05:00")
     for snap in snaps.snapshot:
-        print(snap)
\ No newline at end of file
+        print(snap)
+
+
+def test_list_domain_certs(compute_driver, lbdriver):
+    pass
\ No newline at end of file


Mime
View raw message