Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

OpenShift to KubeShift #778

Merged
merged 1 commit into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions atomicapp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
PROVIDER_CA_KEY = "provider-cafile"

K8S_DEFAULT_API = "http://localhost:8080"
OC_DEFAULT_API = "http://localhost:8443"

# Persistent Storage Formats
PERSISTENT_STORAGE_FORMAT = ["ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"]
Expand Down
2 changes: 2 additions & 0 deletions atomicapp/providers/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ def _from_required_params(self):
self._check_required_params(exception=True)
paramdict = self._build_param_dict()

logger.debug("Building from required params")
# Generate the configuration from the paramters
config = KubeConfig().from_params(api=paramdict[PROVIDER_API_KEY],
auth=paramdict[PROVIDER_AUTH_KEY],
ca=paramdict[PROVIDER_CA_KEY],
verify=paramdict[PROVIDER_TLS_VERIFY_KEY])
logger.debug("Passed configuration for .kube/config %s" % config)
return config

def _check_namespaces(self):
Expand Down
4 changes: 4 additions & 0 deletions atomicapp/providers/lib/kubeshift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

from atomicapp.providers.lib.kubeshift.kubernetes import KubeKubernetesClient
from atomicapp.providers.lib.kubeshift.openshift import KubeOpenshiftClient
from atomicapp.providers.lib.kubeshift.exceptions import KubeClientError
from atomicapp.constants import LOGGER_DEFAULT
import logging
Expand All @@ -41,6 +42,9 @@ def __init__(self, config, provider):
if provider is "kubernetes":
self.connection = KubeKubernetesClient(config)
logger.debug("Using Kubernetes Provider KubeClient library")
elif provider is "openshift":
self.connection = KubeOpenshiftClient(config)
logger.debug("Using OpenShift Provider KubeClient library")
else:
raise KubeClientError("No provider by that name.")

Expand Down
4 changes: 2 additions & 2 deletions atomicapp/providers/lib/kubeshift/kubebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def get_resources(self, url):

def test_connection(self, url):
self.api.request("get", url)
logger.debug("Connection successfully tested")
logger.debug("Connection successfully tested on URL %s" % url)

@staticmethod
def cert_file(data, key):
Expand Down Expand Up @@ -337,7 +337,7 @@ def _request_method(self, method, url, data):
data (object): object of the data that is being passed (will be converted to json)
'''
if method.lower() == "get":
res = self.api.get(url)
res = self.api.get(url, json=data)
elif method.lower() == "post":
res = self.api.post(url, json=data)
elif method.lower() == "put":
Expand Down
3 changes: 3 additions & 0 deletions atomicapp/providers/lib/kubeshift/kubeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def from_params(api=None, auth=None, ca=None, verify=True):

if ca:
config['clusters'][0]['cluster']['certificate-authority'] = ca

if verify is False:
config['clusters'][0]['cluster']['insecure-skip-tls-verify'] = 'true'
return config

@staticmethod
Expand Down
10 changes: 6 additions & 4 deletions atomicapp/providers/lib/kubeshift/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
along with Atomic App. If not, see <http://www.gnu.org/licenses/>.
"""

from urlparse import urljoin
from urllib import urlencode
import logging
import re

from urlparse import urljoin
from urllib import urlencode
from atomicapp.constants import LOGGER_DEFAULT
from atomicapp.providers.lib.kubeshift.kubebase import KubeBase
from atomicapp.providers.lib.kubeshift.exceptions import (KubeKubernetesError)
Expand All @@ -39,7 +39,7 @@ def __init__(self, config):
'''

# Pass in the configuration data (.kube/config object) to the KubeBase
# The configuration data passed in will be .kube/config data, so process is accordingly.
self.api = KubeBase(config)

# Check the API url
Expand Down Expand Up @@ -75,7 +75,9 @@ def create(self, obj, namespace):
'''
name = self._get_metadata_name(obj)
kind, url = self._generate_kurl(obj, namespace)

self.api.request("post", url, data=obj)

logger.info("%s '%s' successfully created", kind.capitalize(), name)

def delete(self, obj, namespace):
Expand All @@ -99,8 +101,8 @@ def delete(self, obj, namespace):

if kind in ['rcs', 'replicationcontrollers']:
self.scale(obj, namespace)

self.api.request("delete", url)

logger.info("%s '%s' successfully deleted", kind.capitalize(), name)

def scale(self, obj, namespace, replicas=0):
Expand Down
Loading