From d338c1aefc702919e6fac553c60a69455ae37d05 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Tue, 7 Feb 2017 21:44:47 -0500 Subject: Adding oc_env to lib_openshift. --- roles/lib_openshift/src/doc/env | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 roles/lib_openshift/src/doc/env (limited to 'roles/lib_openshift/src/doc') diff --git a/roles/lib_openshift/src/doc/env b/roles/lib_openshift/src/doc/env new file mode 100644 index 000000000..0544014e6 --- /dev/null +++ b/roles/lib_openshift/src/doc/env @@ -0,0 +1,76 @@ +# flake8: noqa +# pylint: skip-file + +DOCUMENTATION = ''' +--- +module: oc_env +short_description: Modify, and idempotently manage openshift environment variables on pods, deploymentconfigs, and replication controllers. +description: + - Modify openshift environment variables programmatically. +options: + state: + description: + - Supported states, present, absent, list + - present - will ensure object is created or updated to the value specified + - list - will return a list of environment variables + - absent - will remove the environment varibale from the object + required: False + default: present + choices: ["present", 'absent', 'list'] + aliases: [] + kubeconfig: + description: + - The path for the kubeconfig file to use for authentication + required: false + default: /etc/origin/master/admin.kubeconfig + aliases: [] + debug: + description: + - Turn on debug output. + required: false + default: False + aliases: [] + name: + description: + - Name of the object that is being queried. + required: false + default: None + aliases: [] + namespace: + description: + - The namespace where the object lives. + required: false + default: str + aliases: [] + kind: + description: + - The kind attribute of the object. + required: False + default: dc + choices: + - rc + - dc + - pods + aliases: [] +author: +- "Kenny Woodson " +extends_documentation_fragment: [] +''' + +EXAMPLES = ''' +- name: query a list of env vars on dc + oc_env: + kind: dc + name: myawesomedc + namespace: phpapp + +- name: Set the following variables. + oc_env: + kind: dc + name: myawesomedc + namespace: phpapp + env_vars: + SUPER_TURBO_MODE: 'true' + ENABLE_PORTS: 'false' + SERVICE_PORT: 9999 +''' -- cgit v1.2.3 From 45c57201d4601d24e6131bf80800cb7f49d21af7 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Fri, 10 Feb 2017 09:45:24 -0500 Subject: Fixing docs, linting, and comments. --- roles/lib_openshift/library/oc_env.py | 19 ++++++++++++------- roles/lib_openshift/src/class/oc_env.py | 12 +++++------- roles/lib_openshift/src/doc/env | 7 +++++++ 3 files changed, 24 insertions(+), 14 deletions(-) (limited to 'roles/lib_openshift/src/doc') diff --git a/roles/lib_openshift/library/oc_env.py b/roles/lib_openshift/library/oc_env.py index fa4191d1e..06c242db6 100644 --- a/roles/lib_openshift/library/oc_env.py +++ b/roles/lib_openshift/library/oc_env.py @@ -98,6 +98,13 @@ options: - dc - pods aliases: [] + env_vars: + description: + - The environment variables to insert. The format is a dict of value pairs. + - e.g. {key1: value1, key2: value2}) + required: False + default: None + aliases: [] author: - "Kenny Woodson " extends_documentation_fragment: [] @@ -1644,16 +1651,16 @@ class OCEnv(OpenShiftCLI): ''' setter function for resource var''' self._resource = data - def value_exists(self, key, value): + def key_value_exists(self, key, value): ''' return whether a key, value pair exists ''' return self.resource.exists_env_value(key, value) def key_exists(self, key): - ''' return whether a key, value pair exists ''' + ''' return whether a key exists ''' return self.resource.exists_env_key(key) def get(self): - '''return a environment variables ''' + '''return environment variables ''' result = self._get(self.kind, self.name) if result['returncode'] == 0: if self.kind == 'dc': @@ -1662,14 +1669,12 @@ class OCEnv(OpenShiftCLI): return result def delete(self): - '''return all pods ''' - #yed.put(OCEnv.container_path[self.kind], env_vars_array) + ''' delete environment variables ''' if self.resource.delete_env_var(self.env_vars.keys()): return self._replace_content(self.kind, self.name, self.resource.yaml_dict) return {'returncode': 0, 'changed': False} - # pylint: disable=too-many-function-args def put(self): '''place env vars into dc ''' for update_key, update_value in self.env_vars.items(): @@ -1721,7 +1726,7 @@ class OCEnv(OpenShiftCLI): # Create ######## for key, value in params.get('env_vars', {}).items(): - if not ocenv.value_exists(key, value): + if not ocenv.key_value_exists(key, value): if check_mode: return {'changed': False, diff --git a/roles/lib_openshift/src/class/oc_env.py b/roles/lib_openshift/src/class/oc_env.py index b5e78bf90..d34c8234e 100644 --- a/roles/lib_openshift/src/class/oc_env.py +++ b/roles/lib_openshift/src/class/oc_env.py @@ -42,16 +42,16 @@ class OCEnv(OpenShiftCLI): ''' setter function for resource var''' self._resource = data - def value_exists(self, key, value): + def key_value_exists(self, key, value): ''' return whether a key, value pair exists ''' return self.resource.exists_env_value(key, value) def key_exists(self, key): - ''' return whether a key, value pair exists ''' + ''' return whether a key exists ''' return self.resource.exists_env_key(key) def get(self): - '''return a environment variables ''' + '''return environment variables ''' result = self._get(self.kind, self.name) if result['returncode'] == 0: if self.kind == 'dc': @@ -60,14 +60,12 @@ class OCEnv(OpenShiftCLI): return result def delete(self): - '''return all pods ''' - #yed.put(OCEnv.container_path[self.kind], env_vars_array) + ''' delete environment variables ''' if self.resource.delete_env_var(self.env_vars.keys()): return self._replace_content(self.kind, self.name, self.resource.yaml_dict) return {'returncode': 0, 'changed': False} - # pylint: disable=too-many-function-args def put(self): '''place env vars into dc ''' for update_key, update_value in self.env_vars.items(): @@ -119,7 +117,7 @@ class OCEnv(OpenShiftCLI): # Create ######## for key, value in params.get('env_vars', {}).items(): - if not ocenv.value_exists(key, value): + if not ocenv.key_value_exists(key, value): if check_mode: return {'changed': False, diff --git a/roles/lib_openshift/src/doc/env b/roles/lib_openshift/src/doc/env index 0544014e6..36edcd211 100644 --- a/roles/lib_openshift/src/doc/env +++ b/roles/lib_openshift/src/doc/env @@ -52,6 +52,13 @@ options: - dc - pods aliases: [] + env_vars: + description: + - The environment variables to insert. The format is a dict of value pairs. + - e.g. {key1: value1, key2: value2}) + required: False + default: None + aliases: [] author: - "Kenny Woodson " extends_documentation_fragment: [] -- cgit v1.2.3