diff options
author | Kenny Woodson <kwoodson@redhat.com> | 2016-03-28 17:44:48 -0400 |
---|---|---|
committer | Kenny Woodson <kwoodson@redhat.com> | 2016-03-30 12:19:31 -0400 |
commit | 15d730f3aec1f579dbd3cc5310264c68eb78e242 (patch) | |
tree | b32f0efa16101b1f47d70514d7a318c46fe3d76b /roles/lib_openshift_api/build/src/obj.py | |
parent | e1f6415cbcc4145402011fb4183a5dead2f22124 (diff) | |
download | openshift-15d730f3aec1f579dbd3cc5310264c68eb78e242.tar.gz openshift-15d730f3aec1f579dbd3cc5310264c68eb78e242.tar.bz2 openshift-15d730f3aec1f579dbd3cc5310264c68eb78e242.tar.xz openshift-15d730f3aec1f579dbd3cc5310264c68eb78e242.zip |
Moving generation of ansible module side by side with module.
Diffstat (limited to 'roles/lib_openshift_api/build/src/obj.py')
-rw-r--r-- | roles/lib_openshift_api/build/src/obj.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/roles/lib_openshift_api/build/src/obj.py b/roles/lib_openshift_api/build/src/obj.py new file mode 100644 index 000000000..a3ad4b3c4 --- /dev/null +++ b/roles/lib_openshift_api/build/src/obj.py @@ -0,0 +1,78 @@ +# pylint: skip-file + +class OCObject(OpenShiftCLI): + ''' Class to wrap the oc command line tools ''' + + # pylint allows 5. we need 6 + # pylint: disable=too-many-arguments + def __init__(self, + kind, + namespace, + rname=None, + kubeconfig='/etc/origin/master/admin.kubeconfig', + verbose=False): + ''' Constructor for OpenshiftOC ''' + super(OCObject, self).__init__(namespace, kubeconfig) + self.kind = kind + self.namespace = namespace + self.name = rname + self.kubeconfig = kubeconfig + self.verbose = verbose + + def get(self): + '''return a deploymentconfig by name ''' + return self._get(self.kind, rname=self.name) + + def delete(self): + '''return all pods ''' + return self._delete(self.kind, self.name) + + def create(self, files=None, content=None): + '''Create a deploymentconfig ''' + if files: + return self._create(files[0]) + + return self._create(Utils.create_files_from_contents(content)) + + + # pylint: disable=too-many-function-args + def update(self, files=None, content=None, force=False): + '''run update dc + + This receives a list of file names and takes the first filename and calls replace. + ''' + if files: + return self._replace(files[0], force) + + return self.update_content(content, force) + + def update_content(self, content, force=False): + '''update the dc with the content''' + return self._replace_content(self.kind, self.name, content, force=force) + + def needs_update(self, files=None, content=None, content_type='yaml'): + ''' check to see if we need to update ''' + objects = self.get() + if objects['returncode'] != 0: + return objects + + # pylint: disable=no-member + data = None + if files: + data = Utils.get_resource_file(files[0], content_type) + + # if equal then no need. So not equal is True + return not Utils.check_def_equal(data, objects['results'][0], True) + else: + data = content + + for key, value in data.items(): + if key == 'metadata': + continue + if not objects['results'][0].has_key(key): + return True + if value != objects['results'][0][key]: + return True + + return False + |