gke moving along
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/de40af52 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/de40af52 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/de40af52 Branch: refs/heads/trunk Commit: de40af52639c9f638bde30040e0fa19f37194d5c Parents: 7949ca3 Author: andy <andymahe...@gmail.com> Authored: Tue May 23 09:47:18 2017 -0700 Committer: andy <andymahe...@gmail.com> Committed: Tue May 23 09:47:18 2017 -0700 ---------------------------------------------------------------------- docs/container/drivers/gke.rst | 58 +++++++++++++++ docs/container/drivers/joyent.rst | 18 ++--- .../container/gke/instantiate_driver.py | 9 +++ libcloud/container/drivers/gke.py | 75 ++++++++++---------- libcloud/container/providers.py | 2 + libcloud/container/types.py | 1 + libcloud/test/container/test_gke.py | 38 ++++++++++ 7 files changed, 156 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/docs/container/drivers/gke.rst ---------------------------------------------------------------------- diff --git a/docs/container/drivers/gke.rst b/docs/container/drivers/gke.rst new file mode 100644 index 0000000..d2c5548 --- /dev/null +++ b/docs/container/drivers/gke.rst @@ -0,0 +1,58 @@ +Google Container Driver Documentation +============================================ + +`Google Container Platform`_ is a Docker hosting service, provided by Google. +Docker-native tools and elastic hosts make deploying on Google Cloud as easy as running Docker on your laptop. +There is no special software to install or configure. +Mix Docker containers with container-native Linux to extend the benefits of containerization to legacy applications and stateful services. + + +Instantiating the driver +------------------------ + +Download the script:: + + **** + +Now execute the script, substituting the correct values:: + + **** + +This should output something similar to the following:: + + Setting up Docker client for SDC using: + CloudAPI: https://us-east-1.api.joyent.com + Account: jill + Key: /Users/localuser/.ssh/sdc-docker.id_rsa + + If you have a pass phrase on your key, the openssl command will + prompt you for your pass phrase now and again later. + + Verifying GoogleCloudAPI access. + CloudAPI access verified. + + Generating client certificate from SSH private key. + writing RSA key + Wrote certificate files to /Users/localuser/.sdc/docker/jill + + Get Docker host endpoint from cloudapi. + Docker service endpoint is: tcp://us-east-1.docker.joyent.com:2376 + + * * * + Success. Set your environment as follows: + + export DOCKER_CERT_PATH=/Users/localuser/.sdc/docker/jill + export DOCKER_HOST=tcp://us-east-1.docker.joyent.com:2376 + export DOCKER_CLIENT_TIMEOUT=300 + export DOCKER_TLS_VERIFY=1 + +.. literalinclude:: /examples/container/joyent/instantiate_driver.py + :language: python + +API Docs +-------- + +.. autoclass:: libcloud.container.drivers.joyent.GoogleContainerDriver + :members: + :inherited-members: + http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/docs/container/drivers/joyent.rst ---------------------------------------------------------------------- diff --git a/docs/container/drivers/joyent.rst b/docs/container/drivers/joyent.rst index a8b29d3..8dcaacf 100644 --- a/docs/container/drivers/joyent.rst +++ b/docs/container/drivers/joyent.rst @@ -17,7 +17,7 @@ Instantiating the driver Download the script:: curl -O https://raw.githubusercontent.com/joyent/sdc-docker/master/tools/sdc-docker-setup.sh - + Now execute the script, substituting the correct values:: bash sdc-docker-setup.sh <CLOUDAPI_URL> <ACCOUNT_USERNAME> ~/.ssh/<PRIVATE_KEY_FILE> @@ -28,31 +28,31 @@ This should output something similar to the following:: CloudAPI: https://us-east-1.api.joyent.com Account: jill Key: /Users/localuser/.ssh/sdc-docker.id_rsa - + If you have a pass phrase on your key, the openssl command will prompt you for your pass phrase now and again later. - + Verifying CloudAPI access. CloudAPI access verified. - + Generating client certificate from SSH private key. writing RSA key Wrote certificate files to /Users/localuser/.sdc/docker/jill - + Get Docker host endpoint from cloudapi. Docker service endpoint is: tcp://us-east-1.docker.joyent.com:2376 - + * * * Success. Set your environment as follows: - + export DOCKER_CERT_PATH=/Users/localuser/.sdc/docker/jill export DOCKER_HOST=tcp://us-east-1.docker.joyent.com:2376 export DOCKER_CLIENT_TIMEOUT=300 export DOCKER_TLS_VERIFY=1 - + .. literalinclude:: /examples/container/joyent/instantiate_driver.py :language: python - + API Docs -------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/docs/examples/container/gke/instantiate_driver.py ---------------------------------------------------------------------- diff --git a/docs/examples/container/gke/instantiate_driver.py b/docs/examples/container/gke/instantiate_driver.py new file mode 100644 index 0000000..a5b6143 --- /dev/null +++ b/docs/examples/container/gke/instantiate_driver.py @@ -0,0 +1,9 @@ +from libcloud.container.types import Provider +from libcloud.container.providers import get_driver + +cls = get_driver(Provider.GKE) + +conn = ComputeEngine('testaccount-...@testproject.iam.gserviceaccount.com', + 'libcloud.json', project='testproject') + +conn.list_images() http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/libcloud/container/drivers/gke.py ---------------------------------------------------------------------- diff --git a/libcloud/container/drivers/gke.py b/libcloud/container/drivers/gke.py index 3faf009..50455c7 100644 --- a/libcloud/container/drivers/gke.py +++ b/libcloud/container/drivers/gke.py @@ -1,7 +1,10 @@ from libcloud.common.google import GoogleOAuth2Credential +from libcloud.container.drivers.docker import (DockerContainerDriver, + DockerConnection) -class GKENodeDriver(NodeDriver): + +class GKEContainerDriver(DockerContainerDriver): """ GCE Node Driver class. @@ -13,7 +16,7 @@ class GKENodeDriver(NodeDriver): objects/strings). In most cases, passing strings instead of objects will result in additional GKE API calls. """ - connectionCls = GKEConnection + connectionCls = DockerConnection api_name = 'google' name = "Google Container Engine" type = Provider.GKE @@ -29,38 +32,8 @@ class GKENodeDriver(NodeDriver): # node in a 'terminated' state. # For more details, please see GCE's docs, # https://cloud.google.com/compute/docs/instances#checkmachinestatus - NODE_STATE_MAP = { - "PROVISIONING": NodeState.PENDING, - "STAGING": NodeState.PENDING, - "RUNNING": NodeState.RUNNING, - "STOPPING": NodeState.PENDING, - "TERMINATED": NodeState.STOPPED, - "UNKNOWN": NodeState.UNKNOWN - } AUTH_URL = "https://www.googleapis.com/auth/" - SA_SCOPES_MAP = { - # list derived from 'gcloud compute instances create --help' - "bigquery": "bigquery", - "cloud-platform": "cloud-platform", - "compute-ro": "compute.readonly", - "compute-rw": "compute", - "datastore": "datastore", - "logging-write": "logging.write", - "monitoring": "monitoring", - "monitoring-write": "monitoring.write", - "service-control": "servicecontrol", - "service-management": "service.management", - "sql": "sqlservice", - "sql-admin": "sqlservice.admin", - "storage-full": "devstorage.full_control", - "storage-ro": "devstorage.read_only", - "storage-rw": "devstorage.read_write", - "taskqueue": "taskqueue", - "useraccounts-ro": "cloud.useraccounts.readonly", - "useraccounts-rw": "cloud.useraccounts", - "userinfo-email": "userinfo.email" - } IMAGE_PROJECTS = { "centos-cloud": ["centos"], @@ -123,11 +96,9 @@ class GKENodeDriver(NodeDriver): self.credential_file = credential_file or \ GoogleOAuth2Credential.default_credential_file + '.' + self.project - super(GCENodeDriver, self).__init__(user_id, key, **kwargs) + super(GKEContainerDriver, self).__init__(user_id, key, **kwargs) - # Cache Zone and Region information to reduce API calls and - # increase speed - self.base_path = '/%s/projects/%s' % (API_VERSION, + self.base_path = '/compute/%s/projects/%s' % (API_VERSION, self.project) self.zone_list = self.ex_list_zones() self.zone_dict = {} @@ -151,3 +122,35 @@ class GKENodeDriver(NodeDriver): # Volume details are looked up in this name-zone dict. # It is populated if the volume name is not found or the dict is empty. self._ex_volume_dict = {} + + def list_images(self, ex_project=None, ex_include_deprecated=False): + """ + Return a list of image objects. If no project is specified, a list of + all non-deprecated global and vendor images images is returned. By + default, only non-deprecated images are returned. + + :keyword ex_project: Optional alternate project name. + :type ex_project: ``str``, ``list`` of ``str``, or ``None`` + + :keyword ex_include_deprecated: If True, even DEPRECATED images will + be returned. + :type ex_include_deprecated: ``bool`` + + :return: List of GCENodeImage objects + :rtype: ``list`` of :class:`GCENodeImage` + """ + dep = ex_include_deprecated + if ex_project is not None: + return self.ex_list_project_images(ex_project=ex_project, + ex_include_deprecated=dep) + image_list = self.ex_list_project_images(ex_project=None, + ex_include_deprecated=dep) + for img_proj in list(self.IMAGE_PROJECTS.keys()): + try: + image_list.extend( + self.ex_list_project_images(ex_project=img_proj, + ex_include_deprecated=dep)) + except: + # do not break if an OS type is invalid + pass + return image_list http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/libcloud/container/providers.py ---------------------------------------------------------------------- diff --git a/libcloud/container/providers.py b/libcloud/container/providers.py index a823382..da6661c 100644 --- a/libcloud/container/providers.py +++ b/libcloud/container/providers.py @@ -30,6 +30,8 @@ DRIVERS = { ('libcloud.container.drivers.kubernetes', 'KubernetesContainerDriver'), Provider.RANCHER: ('libcloud.container.drivers.rancher', 'RancherContainerDriver'), + Provider.GKE: + ('libcloud.container.drivers.gke', 'GKEContainerDriver') } http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/libcloud/container/types.py ---------------------------------------------------------------------- diff --git a/libcloud/container/types.py b/libcloud/container/types.py index b89fdfd..b7a50ce 100644 --- a/libcloud/container/types.py +++ b/libcloud/container/types.py @@ -49,6 +49,7 @@ class Provider(object): DUMMY = 'dummy' DOCKER = 'docker' ECS = 'ecs' + GKE = 'GKE' JOYENT = 'joyent' KUBERNETES = 'kubernetes' RANCHER = 'rancher' http://git-wip-us.apache.org/repos/asf/libcloud/blob/de40af52/libcloud/test/container/test_gke.py ---------------------------------------------------------------------- diff --git a/libcloud/test/container/test_gke.py b/libcloud/test/container/test_gke.py new file mode 100644 index 0000000..5c17975 --- /dev/null +++ b/libcloud/test/container/test_gke.py @@ -0,0 +1,38 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +from libcloud.test import unittest + +from libcloud.container.drivers.gke import GoogleContainerDriver +from libcloud.test.secrets import CONTAINER_PARAMS_DOCKER + + +from libcloud.test.container.test_docker import DockerContainerDriverTestCase, DockerMockHttp + + +class JoyentContainerDriverTestCase(DockerContainerDriverTestCase, unittest.TestCase): + + def setUp(self): + # Create a test driver for each version + versions = ('linux_124', 'mac_124') + self.drivers = [] + for version in versions: + JoyentContainerDriver.connectionCls.conn_class = \ + DockerMockHttp + DockerMockHttp.type = None + DockerMockHttp.use_param = 'a' + driver = JoyentContainerDriver(*CONTAINER_PARAMS_DOCKER) + driver.version = version + self.drivers.append(driver)