libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] Kami commented on a change in pull request #1394: Add KubeVirt driver & tests
Date Tue, 24 Dec 2019 18:57:35 GMT
Kami commented on a change in pull request #1394: Add KubeVirt driver & tests
URL: https://github.com/apache/libcloud/pull/1394#discussion_r361213772
 
 

 ##########
 File path: libcloud/compute/drivers/kubevirt.py
 ##########
 @@ -0,0 +1,996 @@
+"""
+kubevirt driver with support for nodes (vms)
+"""
+import os
+import json
+import time
+from datetime import datetime
+
+import libcloud.security
+
+
+from libcloud.container.drivers.kubernetes import KubernetesResponse
+from libcloud.container.drivers.kubernetes import KubernetesConnection
+from libcloud.container.drivers.kubernetes import VALID_RESPONSE_CODES
+
+from libcloud.common.base import KeyCertificateConnection, ConnectionKey
+from libcloud.common.types import InvalidCredsError
+
+from libcloud.compute.types import Provider, NodeState
+from libcloud.compute.base import NodeDriver, NodeSize, Node
+from libcloud.compute.base import NodeImage, NodeLocation, StorageVolume
+
+__all__ = [
+    "KubernetesTLSConnection",
+    "KubernetesTokenAuthentication",
+    "KubeVirtNode",
+    "KubeVirtNodeDriver"
+]
+ROOT_URL = '/api/v1/'
+KUBEVIRT_URL = '/apis/kubevirt.io/v1alpha3/'
+
+
+class KubernetesTLSConnection(KeyCertificateConnection):
+    responseCls = KubernetesResponse
+    timeout = 60
+
+    def __init__(self, key, secure=True, host='localhost',
+                 port='6443', key_file=None, cert_file=None, ca_cert='',
+                 **kwargs):
+
+        super(KubernetesTLSConnection, self).__init__(key_file=key_file,
+                                                      cert_file=cert_file,
+                                                      secure=secure, host=host,
+                                                      port=port, url=None,
+                                                      proxy_url=None,
+                                                      timeout=None,
+                                                      backoff=None,
+                                                      retry_delay=None)
+        if key_file:
+            keypath = os.path.expanduser(key_file)
+            is_file_path = os.path.exists(keypath) and os.path.isfile(keypath)
+            if not is_file_path:
+                raise InvalidCredsError(
+                    'You need an key PEM file to authenticate with '
+                    'via tls. For more info please visit:'
+                    'https://kubernetes.io/docs/concepts/cluster-administration/certificates/')
+            self.key_file = key_file
+            certpath = os.path.expanduser(cert_file)
+            is_file_path = os.path.exists(
+                certpath) and os.path.isfile(certpath)
+            if not is_file_path:
+                raise InvalidCredsError(
+                    'You need an certificate PEM file to authenticate'
+                    'via tls. For more info please visit:'
+                    'https://kubernetes.io/docs/concepts/cluster-administration/certificates/'
+                )
+
+            self.cert_file = cert_file
+
+    def add_default_headers(self, headers):
+        if 'Content-Type' not in headers:
+            headers['Content-Type'] = 'application/json'
+        return headers
+
+
+class KubernetesTokenAuthentication(ConnectionKey):
+    responseCls = KubernetesResponse
+    timeout = 60
+
+    def add_default_headers(self, headers):
+        if 'Content-Type' not in headers:
+            headers['Content-Type'] = 'application/json'
+        if self.key:
+            headers['Authorization'] = 'Bearer ' + self.key
+        else:
+            raise ValueError("Please provide a valid token in the key param")
+        return headers
+
+
+class KubeVirtNode(Node):
+
+    def start_node(self):
 
 Review comment:
   This was changed recently (https://github.com/apache/libcloud/pull/1375) so this custom
node class shouldn't be needed anymore.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message