Artem Panchenko | 0594cd7 | 2017-06-12 13:25:26 +0300 | [diff] [blame] | 1 | # Copyright 2017 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | |
| 14 | |
| 15 | import base64 |
| 16 | import ssl |
| 17 | |
| 18 | from k8sclient.client import api_client |
| 19 | from k8sclient.client.apis import apiv_api |
| 20 | from k8sclient.client.apis import apisextensionsvbeta_api |
| 21 | from k8sclient.client.apis import apisbatchv_api |
| 22 | |
| 23 | from tcp_tests.managers.k8s.componentstatuses import \ |
| 24 | K8sComponentStatusManager |
| 25 | from tcp_tests.managers.k8s.daemonsets import K8sDaemonSetManager |
| 26 | from tcp_tests.managers.k8s.deployments import K8sDeploymentManager |
| 27 | from tcp_tests.managers.k8s.endpoints import K8sEndpointManager |
| 28 | from tcp_tests.managers.k8s.events import K8sEventManager |
| 29 | from tcp_tests.managers.k8s.horizontalpodautoscalers import \ |
| 30 | K8sHorizontalPodAutoscalerManager |
| 31 | from tcp_tests.managers.k8s.ingresses import K8sIngressManager |
| 32 | from tcp_tests.managers.k8s.jobs import K8sJobManager |
| 33 | from tcp_tests.managers.k8s.limitranges import K8sLimitRangeManager |
| 34 | from tcp_tests.managers.k8s.namespaces import K8sNamespaceManager |
| 35 | from tcp_tests.managers.k8s.nodes import K8sNodeManager |
| 36 | from tcp_tests.managers.k8s.persistentvolumeclaims import \ |
| 37 | K8sPersistentVolumeClaimManager |
| 38 | from tcp_tests.managers.k8s.persistentvolumes import \ |
| 39 | K8sPersistentVolumeManager |
| 40 | from tcp_tests.managers.k8s.pods import K8sPodManager |
| 41 | from tcp_tests.managers.k8s.replicationcontrollers import \ |
| 42 | K8sReplicationControllerManager |
| 43 | from tcp_tests.managers.k8s.resourcequotas import K8sResourceQuotaManager |
| 44 | from tcp_tests.managers.k8s.secrets import K8sSecretManager |
| 45 | from tcp_tests.managers.k8s.serviceaccounts import \ |
| 46 | K8sServiceAccountManager |
| 47 | from tcp_tests.managers.k8s.services import K8sServiceManager |
| 48 | from tcp_tests.managers.k8s.replicasets import K8sReplicaSetManager |
| 49 | |
| 50 | |
| 51 | class K8sCluster(object): |
| 52 | """docstring for K8sCluster""" |
| 53 | |
| 54 | def __init__(self, schema="https", user=None, password=None, |
| 55 | host='localhost', port='443', default_namespace='default'): |
| 56 | if user and password: |
| 57 | auth_string = '%s:%s' % (user, password) |
| 58 | auth = base64.encodestring(auth_string.encode()).decode()[:-1] |
| 59 | auth = "Basic {}".format(auth) |
| 60 | self._client = api_client.ApiClient( |
| 61 | '{schema}://{host}:{port}/'.format( |
| 62 | schema=schema, host=host, port=port)) |
| 63 | self._client.set_default_header('Authorization', auth) |
| 64 | restcli_impl = self._client.RESTClient.IMPL |
| 65 | restcli_impl.ssl_pool_manager.connection_pool_kw['cert_reqs'] = \ |
| 66 | ssl.CERT_NONE |
| 67 | |
| 68 | else: |
| 69 | self._client = api_client.ApiClient( |
| 70 | '{schema}://{host}:{port}/'.format( |
| 71 | schema=schema, host=host, port=port)) |
| 72 | self._api = apiv_api.ApivApi(self._client) |
| 73 | self._bapi = apisbatchv_api.ApisbatchvApi(self._client) |
| 74 | self._eapi = apisextensionsvbeta_api.ApisextensionsvbetaApi( |
| 75 | self._client) |
| 76 | self._default_namespace = default_namespace |
| 77 | |
| 78 | self.nodes = K8sNodeManager(self._api, self._default_namespace) |
| 79 | self.pods = K8sPodManager(self._api, self._default_namespace) |
| 80 | self.endpoints = K8sEndpointManager(self._api, self._default_namespace) |
| 81 | self.namespaces = K8sNamespaceManager(self._api, |
| 82 | self._default_namespace) |
| 83 | self.services = K8sServiceManager(self._api, self._default_namespace) |
| 84 | self.serviceaccounts = K8sServiceAccountManager( |
| 85 | self._api, self._default_namespace) |
| 86 | self.secrets = K8sSecretManager(self._api, self._default_namespace) |
| 87 | self.events = K8sEventManager(self._api, self._default_namespace) |
| 88 | self.limitranges = K8sLimitRangeManager(self._api, |
| 89 | self._default_namespace) |
| 90 | self.jobs = K8sJobManager(self._bapi, self._default_namespace) |
| 91 | self.daemonsets = K8sDaemonSetManager(self._eapi, |
| 92 | self._default_namespace) |
| 93 | self.ingresses = K8sIngressManager(self._eapi, self._default_namespace) |
| 94 | self.deployments = K8sDeploymentManager(self._eapi, |
| 95 | self._default_namespace) |
| 96 | self.horizontalpodautoscalers = K8sHorizontalPodAutoscalerManager( |
| 97 | self._eapi, self._default_namespace) |
| 98 | self.componentstatuses = K8sComponentStatusManager( |
| 99 | self._api, self._default_namespace) |
| 100 | self.resourcequotas = K8sResourceQuotaManager( |
| 101 | self._api, self._default_namespace) |
| 102 | self.replicationcontrollers = K8sReplicationControllerManager( |
| 103 | self._api, self._default_namespace) |
| 104 | self.pvolumeclaims = K8sPersistentVolumeClaimManager( |
| 105 | self._api, self._default_namespace) |
| 106 | self.pvolumes = K8sPersistentVolumeManager( |
| 107 | self._api, self._default_namespace) |
| 108 | self.replicasets = K8sReplicaSetManager( |
| 109 | self._eapi, self._default_namespace |
| 110 | ) |