Make k8s.cluster.K8sCluster be used both in py2 and py3

Additional changes in k8smanager.py - file() is not supported by
  Python3

Change-Id: I4bd9d2965597bd9b1372127a83f7742aee84092d
This commit is contained in:
Sergey Lebedev 2016-09-23 09:48:55 +03:00
parent 7b1057c727
commit 327556ed53
2 changed files with 6 additions and 5 deletions

View File

@ -54,7 +54,8 @@ class K8sCluster(object):
def __init__(self, schema="https", user=None, password=None,
host='localhost', port='443', default_namespace='default'):
if user and password:
auth = base64.encodestring('%s:%s' % (user, password))[:-1]
auth_string = '%s:%s' % (user, password)
auth = base64.encodestring(auth_string.encode()).decode()[:-1]
auth = "Basic {}".format(auth)
self._client = api_client.ApiClient(
'{schema}://{host}:{port}/'.format(

View File

@ -177,10 +177,10 @@ class K8SManager(object):
'registry_templates/' \
'service-registry.yaml'
with file(registry_pod) as f:
registry = yaml.load(f)
with file(service_registry) as f:
service = yaml.load(f)
with open(registry_pod) as f:
registry = yaml.load(f.read())
with open(service_registry) as f:
service = yaml.load(f.read())
registry_pod = self.api.pods.create(body=registry, namespace='default')
self.api.services.create(body=service, namespace='default')