summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift/src/lib
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2017-02-09 17:59:11 -0500
committerKenny Woodson <kwoodson@redhat.com>2017-03-06 09:09:14 -0500
commitc25792965600baf821d0244682423ff841baffe1 (patch)
treeab91dd2920e43829583c67b6f80ae8b6a6b02a04 /roles/lib_openshift/src/lib
parent6ecb86b2fcc36e3383d86395d3be0a443e12981e (diff)
downloadopenshift-c25792965600baf821d0244682423ff841baffe1.tar.gz
openshift-c25792965600baf821d0244682423ff841baffe1.tar.bz2
openshift-c25792965600baf821d0244682423ff841baffe1.tar.xz
openshift-c25792965600baf821d0244682423ff841baffe1.zip
Adding oc_project to lib_openshift.
Diffstat (limited to 'roles/lib_openshift/src/lib')
-rw-r--r--roles/lib_openshift/src/lib/project.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/roles/lib_openshift/src/lib/project.py b/roles/lib_openshift/src/lib/project.py
new file mode 100644
index 000000000..1e28637de
--- /dev/null
+++ b/roles/lib_openshift/src/lib/project.py
@@ -0,0 +1,82 @@
+# pylint: skip-file
+
+# pylint: disable=too-many-instance-attributes
+class ProjectConfig(OpenShiftCLIConfig):
+ ''' project config object '''
+ def __init__(self, rname, namespace, kubeconfig, project_options):
+ super(ProjectConfig, self).__init__(rname, rname, kubeconfig, project_options)
+
+class Project(Yedit):
+ ''' Class to wrap the oc command line tools '''
+ annotations_path = "metadata.annotations"
+ kind = 'Service'
+ annotation_prefix = 'openshift.io/'
+
+ def __init__(self, content):
+ '''Service constructor'''
+ super(Project, self).__init__(content=content)
+
+ def get_annotations(self):
+ ''' get a list of ports '''
+ return self.get(Project.annotations_path) or {}
+
+ def add_annotations(self, inc_annos):
+ ''' add a port object to the ports list '''
+ if not isinstance(inc_annos, list):
+ inc_annos = [inc_annos]
+
+ annos = self.get_annotations()
+ if not annos:
+ self.put(Project.annotations_path, inc_annos)
+ else:
+ for anno in inc_annos:
+ for key, value in anno.items():
+ annos[key] = value
+
+ return True
+
+ def find_annotation(self, key):
+ ''' find a specific port '''
+ annotations = self.get_annotations()
+ for anno in annotations:
+ if Project.annotation_prefix + key == anno:
+ return annotations[anno]
+
+ return None
+
+ def delete_annotation(self, inc_anno_keys):
+ ''' remove an annotation from a project'''
+ if not isinstance(inc_anno_keys, list):
+ inc_anno_keys = [inc_anno_keys]
+
+ annos = self.get(Project.annotations_path) or {}
+
+ if not annos:
+ return True
+
+ removed = False
+ for inc_anno in inc_anno_keys:
+ anno = self.find_annotation(inc_anno)
+ if anno:
+ del annos[Project.annotation_prefix + anno]
+ removed = True
+
+ return removed
+
+ def update_annotation(self, key, value):
+ ''' remove an annotation from a project'''
+ annos = self.get(Project.annotations_path) or {}
+
+ if not annos:
+ return True
+
+ updated = False
+ anno = self.find_annotation(key)
+ if anno:
+ annos[Project.annotation_prefix + key] = value
+ updated = True
+
+ else:
+ self.add_annotations({Project.annotation_prefix + key: value})
+
+ return updated