summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift/src
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2017-02-20 16:37:06 -0500
committerKenny Woodson <kwoodson@redhat.com>2017-02-20 16:37:06 -0500
commit9979e0702f097f92feb6d64991ec405e0bff86ce (patch)
treea2160df06fc1b675ae87c1d2e2fbed205e1f4db2 /roles/lib_openshift/src
parent35583f57c71db5b181d0eaefc0bfc620c3790535 (diff)
downloadopenshift-9979e0702f097f92feb6d64991ec405e0bff86ce.tar.gz
openshift-9979e0702f097f92feb6d64991ec405e0bff86ce.tar.bz2
openshift-9979e0702f097f92feb6d64991ec405e0bff86ce.tar.xz
openshift-9979e0702f097f92feb6d64991ec405e0bff86ce.zip
Fixing docs. Fixed default_cert suggestion.
Diffstat (limited to 'roles/lib_openshift/src')
-rw-r--r--roles/lib_openshift/src/ansible/oc_adm_router.py6
-rw-r--r--roles/lib_openshift/src/class/oc_adm_registry.py30
-rw-r--r--roles/lib_openshift/src/class/oc_adm_router.py58
-rw-r--r--roles/lib_openshift/src/doc/registry1
-rw-r--r--roles/lib_openshift/src/doc/router1
-rw-r--r--roles/lib_openshift/src/lib/rolebinding.py21
-rw-r--r--roles/lib_openshift/src/lib/secret.py2
-rw-r--r--roles/lib_openshift/src/lib/volume.py1
8 files changed, 86 insertions, 34 deletions
diff --git a/roles/lib_openshift/src/ansible/oc_adm_router.py b/roles/lib_openshift/src/ansible/oc_adm_router.py
index 131f0c1ed..48c9f0ec1 100644
--- a/roles/lib_openshift/src/ansible/oc_adm_router.py
+++ b/roles/lib_openshift/src/ansible/oc_adm_router.py
@@ -16,6 +16,7 @@ def main():
name=dict(default='router', type='str'),
kubeconfig=dict(default='/etc/origin/master/admin.kubeconfig', type='str'),
+ default_cert=dict(default=None, type='str'),
cert_file=dict(default=None, type='str'),
key_file=dict(default=None, type='str'),
images=dict(default=None, type='str'), #'openshift3/ose-${component}:${version}'
@@ -47,7 +48,10 @@ def main():
# edits
edits=dict(default=[], type='list'),
),
- mutually_exclusive=[["router_type", "images"]],
+ mutually_exclusive=[["router_type", "images"],
+ ["key_file", "default_cert"],
+ ["cert_file", "default_cert"],
+ ],
supports_check_mode=True,
)
diff --git a/roles/lib_openshift/src/class/oc_adm_registry.py b/roles/lib_openshift/src/class/oc_adm_registry.py
index f11737086..505c4db81 100644
--- a/roles/lib_openshift/src/class/oc_adm_registry.py
+++ b/roles/lib_openshift/src/class/oc_adm_registry.py
@@ -86,7 +86,7 @@ class Registry(OpenShiftCLI):
def prepared_registry(self):
''' prepared_registry property '''
if not self.__prepared_registry:
- results = self._prepare_registry()
+ results = self.prepare_registry()
if not results:
raise RegistryException('Could not perform registry preparation.')
self.__prepared_registry = results
@@ -100,13 +100,14 @@ class Registry(OpenShiftCLI):
def force_prepare_registry(self):
'''force a registry prep'''
- self._prepare_registry = None
+ self.__prepared_registry = None
def get(self):
''' return the self.registry_parts '''
self.deploymentconfig = None
self.service = None
+ rval = 0
for part in self.registry_parts:
result = self._get(part['kind'], rname=part['name'])
if result['returncode'] == 0 and part['kind'] == 'dc':
@@ -114,7 +115,11 @@ class Registry(OpenShiftCLI):
elif result['returncode'] == 0 and part['kind'] == 'svc':
self.service = Yedit(content=result['results'][0])
- return (self.deploymentconfig, self.service)
+ if result['returncode'] != 0:
+ rval = result['returncode']
+
+
+ return {'returncode': rval, 'deploymentconfig': self.deploymentconfig, 'service': self.service}
def exists(self):
'''does the object exist?'''
@@ -132,9 +137,16 @@ class Registry(OpenShiftCLI):
continue
parts.append(self._delete(part['kind'], part['name']))
- return parts
+ # Clean up returned results
+ rval = 0
+ for part in parts:
+ # pylint: disable=invalid-sequence-index
+ if 'returncode' in part and part['returncode'] != 0:
+ rval = part['returncode']
+
+ return {'returncode': rval, 'results': parts}
- def _prepare_registry(self):
+ def prepare_registry(self):
''' prepare a registry for instantiation '''
options = self.config.to_option_list()
@@ -191,10 +203,10 @@ class Registry(OpenShiftCLI):
# Clean up returned results
rval = 0
for result in results:
- if result['returncode'] != 0:
+ # pylint: disable=invalid-sequence-index
+ if 'returncode' in result and result['returncode'] != 0:
rval = result['returncode']
-
return {'returncode': rval, 'results': results}
def update(self):
@@ -311,6 +323,8 @@ class Registry(OpenShiftCLI):
return self.prepared_registry['deployment_update'] or self.prepared_registry['service_update'] or False
+ # In the future, we would like to break out each ansible state into a function.
+ # pylint: disable=too-many-branches,too-many-return-statements
@staticmethod
def run_ansible(params, check_mode):
'''run idempotent ansible code'''
@@ -360,6 +374,8 @@ class Registry(OpenShiftCLI):
if check_mode:
return {'changed': True, 'msg': 'CHECK_MODE: Would have performed a delete.'}
+ # Unsure as to why this is angry with the return type.
+ # pylint: disable=redefined-variable-type
api_rval = ocregistry.delete()
if api_rval['returncode'] != 0:
diff --git a/roles/lib_openshift/src/class/oc_adm_router.py b/roles/lib_openshift/src/class/oc_adm_router.py
index 336232b0f..9d61cfdf2 100644
--- a/roles/lib_openshift/src/class/oc_adm_router.py
+++ b/roles/lib_openshift/src/class/oc_adm_router.py
@@ -1,16 +1,18 @@
# pylint: skip-file
+# flake8: noqa
-import time
class RouterException(Exception):
''' Router exception'''
pass
+
class RouterConfig(OpenShiftCLIConfig):
''' RouterConfig is a DTO for the router. '''
def __init__(self, rname, namespace, kubeconfig, router_options):
super(RouterConfig, self).__init__(rname, namespace, kubeconfig, router_options)
+
class Router(OpenShiftCLI):
''' Class to wrap the oc command line tools '''
def __init__(self,
@@ -45,7 +47,7 @@ class Router(OpenShiftCLI):
@property
def prepared_router(self):
''' property for the prepared router'''
- if self.__prepared_router == None:
+ if self.__prepared_router is None:
results = self._prepare_router()
if not results:
raise RouterException('Could not perform router preparation')
@@ -148,7 +150,12 @@ class Router(OpenShiftCLI):
for part in self.router_parts:
parts.append(self._delete(part['kind'], part['name']))
- return parts
+ rval = 0
+ for part in parts:
+ if part['returncode'] != 0 and not 'already exist' in part['stderr']:
+ rval = part['returncode']
+
+ return {'returncode': rval, 'results': parts}
def add_modifications(self, deploymentconfig):
'''modify the deployment config'''
@@ -176,16 +183,17 @@ class Router(OpenShiftCLI):
def _prepare_router(self):
'''prepare router for instantiation'''
# We need to create the pem file
- router_pem = '/tmp/router.pem'
- with open(router_pem, 'w') as rfd:
- rfd.write(open(self.config.config_options['cert_file']['value']).read())
- rfd.write(open(self.config.config_options['key_file']['value']).read())
- if self.config.config_options['cacert_file']['value'] and \
- os.path.exists(self.config.config_options['cacert_file']['value']):
- rfd.write(open(self.config.config_options['cacert_file']['value']).read())
-
- atexit.register(Utils.cleanup, [router_pem])
- self.config.config_options['default_cert']['value'] = router_pem
+ if self.config.config_options['default_cert']['value'] is None:
+ router_pem = '/tmp/router.pem'
+ with open(router_pem, 'w') as rfd:
+ rfd.write(open(self.config.config_options['cert_file']['value']).read())
+ rfd.write(open(self.config.config_options['key_file']['value']).read())
+ if self.config.config_options['cacert_file']['value'] and \
+ os.path.exists(self.config.config_options['cacert_file']['value']):
+ rfd.write(open(self.config.config_options['cacert_file']['value']).read())
+
+ atexit.register(Utils.cleanup, [router_pem])
+ self.config.config_options['default_cert']['value'] = router_pem
options = self.config.to_option_list()
@@ -196,7 +204,7 @@ class Router(OpenShiftCLI):
results = self.openshift_cmd(cmd, oadm=True, output=True, output_type='json')
# pylint: disable=no-member
- if results['returncode'] != 0 and results['results'].has_key('items'):
+ if results['returncode'] != 0 and 'items' in results['results']:
return results
oc_objects = {'DeploymentConfig': {'obj': None, 'path': None, 'update': False},
@@ -226,14 +234,16 @@ class Router(OpenShiftCLI):
# add modifications added
oc_objects['DeploymentConfig']['obj'] = self.add_modifications(oc_objects['DeploymentConfig']['obj'])
- for oc_type in oc_objects.keys():
- oc_objects[oc_type]['path'] = Utils.create_tmp_file_from_contents(oc_type, oc_objects[oc_type]['obj'].yaml_dict)
+ for oc_type, oc_data in oc_objects.items():
+ oc_data['path'] = Utils.create_tmp_file_from_contents(oc_type, oc_data['obj'].yaml_dict)
return oc_objects
def create(self):
'''Create a deploymentconfig '''
results = []
+
+ # pylint: disable=no-member
for _, oc_data in self.prepared_router.items():
results.append(self._create(oc_data['path']))
@@ -247,6 +257,8 @@ class Router(OpenShiftCLI):
def update(self):
'''run update for the router. This performs a replace'''
results = []
+
+ # pylint: disable=no-member
for _, oc_data in self.prepared_router.items():
if oc_data['update']:
results.append(self._replace(oc_data['path']))
@@ -312,7 +324,7 @@ class Router(OpenShiftCLI):
# dry-run doesn't add the protocol to the ports section. We will manually do that.
for idx, port in enumerate(self.prepared_router['DeploymentConfig']['obj'].get(\
'spec.template.spec.containers[0].ports') or []):
- if not port.has_key('protocol'):
+ if not 'protocol' in port:
port['protocol'] = 'TCP'
# These are different when generating
@@ -325,13 +337,14 @@ class Router(OpenShiftCLI):
]
if not Utils.check_def_equal(self.prepared_router['DeploymentConfig']['obj'].yaml_dict,
- self.deploymentconfig.yaml_dict,
- skip_keys=skip,
- debug=self.verbose):
+ self.deploymentconfig.yaml_dict,
+ skip_keys=skip,
+ debug=self.verbose):
self.prepared_router['DeploymentConfig']['update'] = True
# Check if any of the parts need updating, if so, return True
# else, no need to update
+ # pylint: disable=no-member
return any([self.prepared_router[oc_type]['update'] for oc_type in self.prepared_router.keys()])
@staticmethod
@@ -341,7 +354,7 @@ class Router(OpenShiftCLI):
rconfig = RouterConfig(params['name'],
params['namespace'],
params['kubeconfig'],
- {'default_cert': {'value': None, 'include': True},
+ {'default_cert': {'value': params['default_cert'], 'include': True},
'cert_file': {'value': params['cert_file'], 'include': False},
'key_file': {'value': params['key_file'], 'include': False},
'images': {'value': params['images'], 'include': True},
@@ -400,6 +413,9 @@ class Router(OpenShiftCLI):
if check_mode:
return {'changed': True, 'msg': 'CHECK_MODE: Would have performed a delete.'}
+ # In case of delete we return a list of each object
+ # that represents a router and its result in a list
+ # pylint: disable=redefined-variable-type
api_rval = ocrouter.delete()
return {'changed': True, 'results': api_rval, 'state': state}
diff --git a/roles/lib_openshift/src/doc/registry b/roles/lib_openshift/src/doc/registry
index 232d30513..11941351d 100644
--- a/roles/lib_openshift/src/doc/registry
+++ b/roles/lib_openshift/src/doc/registry
@@ -13,6 +13,7 @@ options:
- The desired action when managing openshift registry
- present - update or create the registry
- absent - tear down the registry service and deploymentconfig
+ - list - returns the current representiation of a registry
required: false
default: False
aliases: []
diff --git a/roles/lib_openshift/src/doc/router b/roles/lib_openshift/src/doc/router
index 6ff7e3f8d..7aee3a680 100644
--- a/roles/lib_openshift/src/doc/router
+++ b/roles/lib_openshift/src/doc/router
@@ -13,6 +13,7 @@ options:
- Whether to create or delete the router
- present - create the router
- absent - remove the router
+ - list - return the current representation of a router
required: false
default: present
choices:
diff --git a/roles/lib_openshift/src/lib/rolebinding.py b/roles/lib_openshift/src/lib/rolebinding.py
index 0835c9254..69629f9f5 100644
--- a/roles/lib_openshift/src/lib/rolebinding.py
+++ b/roles/lib_openshift/src/lib/rolebinding.py
@@ -1,4 +1,5 @@
# pylint: skip-file
+# flake8: noqa
# pylint: disable=too-many-instance-attributes
class RoleBindingConfig(object):
@@ -58,7 +59,7 @@ class RoleBinding(Yedit):
@property
def subjects(self):
''' subjects property '''
- if self._subjects == None:
+ if self._subjects is None:
self._subjects = self.get_subjects()
return self._subjects
@@ -70,7 +71,7 @@ class RoleBinding(Yedit):
@property
def role_ref(self):
''' role_ref property '''
- if self._role_ref == None:
+ if self._role_ref is None:
self._role_ref = self.get_role_ref()
return self._role_ref
@@ -82,7 +83,7 @@ class RoleBinding(Yedit):
@property
def group_names(self):
''' group_names property '''
- if self._group_names == None:
+ if self._group_names is None:
self._group_names = self.get_group_names()
return self._group_names
@@ -94,7 +95,7 @@ class RoleBinding(Yedit):
@property
def user_names(self):
''' user_names property '''
- if self._user_names == None:
+ if self._user_names is None:
self._user_names = self.get_user_names()
return self._user_names
@@ -123,6 +124,7 @@ class RoleBinding(Yedit):
def add_subject(self, inc_subject):
''' add a subject '''
if self.subjects:
+ # pylint: disable=no-member
self.subjects.append(inc_subject)
else:
self.put(RoleBinding.subjects_path, [inc_subject])
@@ -140,6 +142,7 @@ class RoleBinding(Yedit):
def add_group_names(self, inc_group_names):
''' add a group_names '''
if self.group_names:
+ # pylint: disable=no-member
self.group_names.append(inc_group_names)
else:
self.put(RoleBinding.group_names_path, [inc_group_names])
@@ -149,6 +152,7 @@ class RoleBinding(Yedit):
def add_user_name(self, inc_user_name):
''' add a username '''
if self.user_names:
+ # pylint: disable=no-member
self.user_names.append(inc_user_name)
else:
self.put(RoleBinding.user_names_path, [inc_user_name])
@@ -161,6 +165,7 @@ class RoleBinding(Yedit):
def remove_subject(self, inc_subject):
''' remove a subject '''
try:
+ # pylint: disable=no-member
self.subjects.remove(inc_subject)
except ValueError as _:
return False
@@ -178,6 +183,7 @@ class RoleBinding(Yedit):
def remove_group_name(self, inc_group_name):
''' remove a groupname '''
try:
+ # pylint: disable=no-member
self.group_names.remove(inc_group_name)
except ValueError as _:
return False
@@ -187,6 +193,7 @@ class RoleBinding(Yedit):
def remove_user_name(self, inc_user_name):
''' remove a username '''
try:
+ # pylint: disable=no-member
self.user_names.remove(inc_user_name)
except ValueError as _:
return False
@@ -199,6 +206,7 @@ class RoleBinding(Yedit):
def update_subject(self, inc_subject):
''' update a subject '''
try:
+ # pylint: disable=no-member
index = self.subjects.index(inc_subject)
except ValueError as _:
return self.add_subject(inc_subject)
@@ -210,6 +218,7 @@ class RoleBinding(Yedit):
def update_group_name(self, inc_group_name):
''' update a groupname '''
try:
+ # pylint: disable=no-member
index = self.group_names.index(inc_group_name)
except ValueError as _:
return self.add_group_names(inc_group_name)
@@ -221,6 +230,7 @@ class RoleBinding(Yedit):
def update_user_name(self, inc_user_name):
''' update a username '''
try:
+ # pylint: disable=no-member
index = self.user_names.index(inc_user_name)
except ValueError as _:
return self.add_user_name(inc_user_name)
@@ -242,6 +252,7 @@ class RoleBinding(Yedit):
''' find a subject '''
index = None
try:
+ # pylint: disable=no-member
index = self.subjects.index(inc_subject)
except ValueError as _:
return index
@@ -252,6 +263,7 @@ class RoleBinding(Yedit):
''' find a group_name '''
index = None
try:
+ # pylint: disable=no-member
index = self.group_names.index(inc_group_name)
except ValueError as _:
return index
@@ -262,6 +274,7 @@ class RoleBinding(Yedit):
''' find a user_name '''
index = None
try:
+ # pylint: disable=no-member
index = self.user_names.index(inc_user_name)
except ValueError as _:
return index
diff --git a/roles/lib_openshift/src/lib/secret.py b/roles/lib_openshift/src/lib/secret.py
index 32e67152d..622290aa8 100644
--- a/roles/lib_openshift/src/lib/secret.py
+++ b/roles/lib_openshift/src/lib/secret.py
@@ -20,7 +20,7 @@ class SecretConfig(object):
self.create_dict()
def create_dict(self):
- ''' instantiate a secret as a dict '''
+ ''' assign the correct properties for a secret dict '''
self.data['apiVersion'] = 'v1'
self.data['kind'] = 'Secret'
self.data['metadata'] = {}
diff --git a/roles/lib_openshift/src/lib/volume.py b/roles/lib_openshift/src/lib/volume.py
index fd47fa5c5..84ef1f705 100644
--- a/roles/lib_openshift/src/lib/volume.py
+++ b/roles/lib_openshift/src/lib/volume.py
@@ -1,4 +1,5 @@
# pylint: skip-file
+# flake8: noqa
class Volume(object):
''' Class to model an openshift volume object'''