summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift
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
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')
-rw-r--r--roles/lib_openshift/library/oc_adm_registry.py35
-rw-r--r--roles/lib_openshift/library/oc_adm_router.py88
-rw-r--r--roles/lib_openshift/library/oc_secret.py2
-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
11 files changed, 173 insertions, 72 deletions
diff --git a/roles/lib_openshift/library/oc_adm_registry.py b/roles/lib_openshift/library/oc_adm_registry.py
index 691c9ee41..8b83c61d7 100644
--- a/roles/lib_openshift/library/oc_adm_registry.py
+++ b/roles/lib_openshift/library/oc_adm_registry.py
@@ -64,6 +64,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: []
@@ -1774,7 +1775,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'] = {}
@@ -1845,7 +1846,7 @@ class Secret(Yedit):
def update_secret(self, key, value):
''' update a secret'''
# pylint: disable=no-member
- if self.secrets.has_key(key):
+ if key in self.secrets:
self.secrets[key] = value
else:
self.add_secret(key, value)
@@ -2157,7 +2158,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
@@ -2171,13 +2172,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':
@@ -2185,7 +2187,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?'''
@@ -2203,9 +2209,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()
@@ -2262,10 +2275,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):
@@ -2382,6 +2395,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'''
@@ -2431,6 +2446,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/library/oc_adm_router.py b/roles/lib_openshift/library/oc_adm_router.py
index 1ee92fad5..2cb932bb9 100644
--- a/roles/lib_openshift/library/oc_adm_router.py
+++ b/roles/lib_openshift/library/oc_adm_router.py
@@ -64,6 +64,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:
@@ -2058,7 +2059,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'] = {}
@@ -2129,7 +2130,7 @@ class Secret(Yedit):
def update_secret(self, key, value):
''' update a secret'''
# pylint: disable=no-member
- if self.secrets.has_key(key):
+ if key in self.secrets:
self.secrets[key] = value
else:
self.add_secret(key, value)
@@ -2198,7 +2199,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
@@ -2210,7 +2211,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
@@ -2222,7 +2223,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
@@ -2234,7 +2235,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
@@ -2263,6 +2264,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])
@@ -2280,6 +2282,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])
@@ -2289,6 +2292,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])
@@ -2301,6 +2305,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
@@ -2318,6 +2323,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
@@ -2327,6 +2333,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
@@ -2339,6 +2346,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)
@@ -2350,6 +2358,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)
@@ -2361,6 +2370,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)
@@ -2382,6 +2392,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
@@ -2392,6 +2403,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
@@ -2402,6 +2414,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
@@ -2419,17 +2432,18 @@ class RoleBinding(Yedit):
# -*- -*- -*- Begin included fragment: class/oc_adm_router.py -*- -*- -*-
-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,
@@ -2464,7 +2478,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')
@@ -2567,7 +2581,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'''
@@ -2595,16 +2614,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()
@@ -2615,7 +2635,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},
@@ -2645,14 +2665,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']))
@@ -2666,6 +2688,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']))
@@ -2731,7 +2755,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
@@ -2744,13 +2768,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
@@ -2760,7 +2785,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},
@@ -2819,6 +2844,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}
@@ -2874,6 +2902,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}'
@@ -2905,7 +2934,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/library/oc_secret.py b/roles/lib_openshift/library/oc_secret.py
index 0eca0010e..6ab5e81b2 100644
--- a/roles/lib_openshift/library/oc_secret.py
+++ b/roles/lib_openshift/library/oc_secret.py
@@ -1358,7 +1358,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/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'''