updates

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

Branch: refs/heads/trunk
Commit: f222792230ff44297a8537c3d6f3b54ca3df79c2
Parents: 7c7576b
Author: andy <[email protected]>
Authored: Tue Jun 6 08:12:04 2017 -0400
Committer: andy <[email protected]>
Committed: Tue Jun 6 08:12:04 2017 -0400

----------------------------------------------------------------------
 libcloud/container/drivers/gke.py        | 85 ++++++++++++++++++++++-----
 libcloud/container/drivers/kubernetes.py | 23 ++++----
 2 files changed, 84 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f2227922/libcloud/container/drivers/gke.py
----------------------------------------------------------------------
diff --git a/libcloud/container/drivers/gke.py 
b/libcloud/container/drivers/gke.py
index c881716..96c1f8c 100644
--- a/libcloud/container/drivers/gke.py
+++ b/libcloud/container/drivers/gke.py
@@ -1,10 +1,71 @@
 from libcloud.common.google import GoogleOAuth2Credential
 from libcloud.container.providers import Provider
 from libcloud.container.drivers.kubernetes import KubernetesConnection, 
KubernetesContainerDriver
-
+from libcloud.common.google import GoogleResponse
+from libcloud.common.google import GoogleBaseConnection
 API_VERSION = 'v1'
 
 
+class GKEResponse(GoogleResponse):
+    pass
+
+
+class GKEConnection(GoogleBaseConnection):
+    """
+    Connection class for the GKE driver.
+
+    GCEConnection extends :class:`google.GoogleBaseConnection` for 2 reasons:
+      1. modify request_path for GCE URI.
+      2. Implement gce_params functionality described below.
+      3. Add request_aggregated_items method for making aggregated API calls.
+
+    If the parameter gce_params is set to a dict prior to calling request(),
+    the URL parameters will be updated to include those key/values FOR A
+    SINGLE REQUEST. If the response contains a nextPageToken,
+    gce_params['pageToken'] will be set to its value. This can be used to
+    implement paging in list:
+
+    >>> params, more_results = {'maxResults': 2}, True
+    >>> while more_results:
+    ...     driver.connection.gce_params=params
+    ...     driver.ex_list_urlmaps()
+    ...     more_results = 'pageToken' in params
+    ...
+    [<GCEUrlMap id="..." name="cli-map">, <GCEUrlMap id="..." name="lc-map">]
+    [<GCEUrlMap id="..." name="web-map">]
+    """
+    host = 'www.googleapis.com'
+    responseCls = GKEResponse
+
+    def __init__(self, user_id, key, secure, auth_type=None,
+                 credential_file=None, project=None, **kwargs):
+        print("GKE CONNECTION", "auth_type", auth_type, "cred", 
credential_file)
+        super(GKEConnection, self).__init__(
+            user_id, key, secure=secure, auth_type=auth_type,
+            credential_file=credential_file, **kwargs)
+        self.request_path = '%s/projects/%s' % (API_VERSION, project)
+        self.gce_params = None
+
+    def request(self, *args, **kwargs):
+        """
+        Perform request then do GCE-specific processing of URL params.
+
+        @inherits: :class:`GoogleBaseConnection.request`
+        """
+        response = super(GKEConnection, self).request(*args, **kwargs)
+
+        # If gce_params has been set, then update the pageToken with the
+        # nextPageToken so it can be used in the next request.
+        if self.gce_params:
+            if 'nextPageToken' in response.object:
+                self.gce_params['pageToken'] = response.object['nextPageToken']
+            elif 'pageToken' in self.gce_params:
+                del self.gce_params['pageToken']
+            self.gce_params = None
+
+        return response
+
+
 class GKEContainerDriver(KubernetesContainerDriver):
     """
     GCE Node Driver class.
@@ -17,24 +78,13 @@ class GKEContainerDriver(KubernetesContainerDriver):
     objects/strings).  In most cases, passing strings instead of objects will
     result in additional GKE API calls.
     """
-    connectionCls = KubernetesConnection
+    connectionCls = GKEConnection
     api_name = 'google'
     name = "Google Container Engine"
     type = Provider.GKE
     website = 'https://container.googleapis.com'
     supports_clusters = True
 
-    # Google Compute Engine node states are mapped to Libcloud node states
-    # per the following dict. GCE does not have an actual 'stopped' state
-    # but instead uses a 'terminated' state to indicate the node exists
-    # but is not running. In order to better match libcloud, GCE maps this
-    # 'terminated' state to 'STOPPED'.
-    # Also, when a node is deleted from GCE, it no longer exists and instead
-    # will result in a ResourceNotFound error versus returning a placeholder
-    # node in a 'terminated' state.
-    # For more details, please see GCE's docs,
-    # https://cloud.google.com/compute/docs/instances#checkmachinestatus
-
     AUTH_URL = "https://www.googleapis.com/auth/";
 
     BACKEND_SERVICE_PROTOCOLS = ['HTTP', 'HTTPS', 'HTTP2', 'TCP', 'SSL']
@@ -86,12 +136,19 @@ class GKEContainerDriver(KubernetesContainerDriver):
         self.credential_file = credential_file or \
             GoogleOAuth2Credential.default_credential_file + '.' + self.project
 
-        super(GKEContainerDriver, self).__init__(user_id, key, host=host, 
port=port, **kwargs)
+        super(GKEContainerDriver, self).__init__(user_id, key, secure=True, 
host=None,
+                 port=None, **kwargs)
 
         self.base_path = '/%s/projects/%s' % (API_VERSION,
                                                       self.project)
         self.website = GKEContainerDriver.website
 
+    def _ex_connection_class_kwargs(self):
+        return {'auth_type': self.auth_type,
+                'project': self.project,
+                'scopes': self.scopes,
+                'credential_file': self.credential_file}
+
     def list_clusters(self, zone=None):
         """
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f2227922/libcloud/container/drivers/kubernetes.py
----------------------------------------------------------------------
diff --git a/libcloud/container/drivers/kubernetes.py 
b/libcloud/container/drivers/kubernetes.py
index 92036be..f3c547a 100644
--- a/libcloud/container/drivers/kubernetes.py
+++ b/libcloud/container/drivers/kubernetes.py
@@ -123,26 +123,29 @@ class KubernetesContainerDriver(ContainerDriver):
 
         :return: ``None``
         """
+        print(key, secret)
         super(KubernetesContainerDriver, self).__init__(key=key, secret=secret,
                                                         secure=secure,
                                                         host=host,
                                                         port=port)
-        if host.startswith('https://'):
-            secure = True
 
-        # strip the prefix
-        prefixes = ['http://', 'https://']
-        for prefix in prefixes:
-            if host.startswith(prefix):
-                host = host.strip(prefix)
+        if host is not None:
+            if host.startswith('https://'):
+                secure = True
+
+            # strip the prefix
+            prefixes = ['http://', 'https://']
+            for prefix in prefixes:
+                if host.startswith(prefix):
+                    host = host.strip(prefix)
+
+            self.connection.host = host
+            self.connection.port = port
 
         self.connection.secure = secure
         self.connection.key = key
         self.connection.secret = secret
 
-        self.connection.host = host
-        self.connection.port = port
-
     def list_containers(self, image=None, all=True):
         """
         List the deployed container images

Reply via email to