summaryrefslogtreecommitdiffstats
path: root/roles/lib_openshift_api
diff options
context:
space:
mode:
authorMatt Woodson <mwoodson@gmail.com>2016-04-04 16:16:25 -0400
committerMatt Woodson <mwoodson@gmail.com>2016-04-04 16:16:25 -0400
commit9db67b8095b206efefeb2c3def07e1e4394733d0 (patch)
treeecd55d566adf0d2ccfaeaaec9c208af3fceae8bb /roles/lib_openshift_api
parent63af28f86977e2d870153df98eae497a3c4680cf (diff)
parentc667debd59e584530438198dfcf77403ed9c18c4 (diff)
downloadopenshift-9db67b8095b206efefeb2c3def07e1e4394733d0.tar.gz
openshift-9db67b8095b206efefeb2c3def07e1e4394733d0.tar.bz2
openshift-9db67b8095b206efefeb2c3def07e1e4394733d0.tar.xz
openshift-9db67b8095b206efefeb2c3def07e1e4394733d0.zip
Merge pull request #1704 from kwoodson/yeditfix
yedit now handles periods in key names
Diffstat (limited to 'roles/lib_openshift_api')
-rw-r--r--roles/lib_openshift_api/build/ansible/edit.py6
-rw-r--r--roles/lib_openshift_api/build/ansible/obj.py7
-rw-r--r--roles/lib_openshift_api/library/oc_edit.py28
-rw-r--r--roles/lib_openshift_api/library/oc_obj.py29
-rw-r--r--roles/lib_openshift_api/library/oc_secret.py22
5 files changed, 71 insertions, 21 deletions
diff --git a/roles/lib_openshift_api/build/ansible/edit.py b/roles/lib_openshift_api/build/ansible/edit.py
index 275789298..943fa47a6 100644
--- a/roles/lib_openshift_api/build/ansible/edit.py
+++ b/roles/lib_openshift_api/build/ansible/edit.py
@@ -18,6 +18,12 @@ def main():
choices=['dc', 'deploymentconfig',
'svc', 'service',
'scc', 'securitycontextconstraints',
+ 'ns', 'namespace', 'project', 'projects',
+ 'is', 'imagestream',
+ 'istag', 'imagestreamtag',
+ 'bc', 'buildconfig',
+ 'routes',
+ 'node',
'secret',
]),
file_name=dict(default=None, type='str'),
diff --git a/roles/lib_openshift_api/build/ansible/obj.py b/roles/lib_openshift_api/build/ansible/obj.py
index 0796d807e..a14ac0e43 100644
--- a/roles/lib_openshift_api/build/ansible/obj.py
+++ b/roles/lib_openshift_api/build/ansible/obj.py
@@ -19,6 +19,13 @@ def main():
type='str',
choices=['dc', 'deploymentconfig',
'svc', 'service',
+ 'scc', 'securitycontextconstraints',
+ 'ns', 'namespace', 'project', 'projects',
+ 'is', 'imagestream',
+ 'istag', 'imagestreamtag',
+ 'bc', 'buildconfig',
+ 'routes',
+ 'node',
'secret',
]),
delete_after=dict(default=False, type='bool'),
diff --git a/roles/lib_openshift_api/library/oc_edit.py b/roles/lib_openshift_api/library/oc_edit.py
index 1e2a41077..44e77331d 100644
--- a/roles/lib_openshift_api/library/oc_edit.py
+++ b/roles/lib_openshift_api/library/oc_edit.py
@@ -285,8 +285,8 @@ class YeditException(Exception):
class Yedit(object):
''' Class to modify yaml files '''
- re_valid_key = r"(((\[-?\d+\])|(\w+)).?)+$"
- re_key = r"(?:\[(-?\d+)\])|(\w+)"
+ re_valid_key = r"(((\[-?\d+\])|([a-zA-Z-./]+)).?)+$"
+ re_key = r"(?:\[(-?\d+)\])|([a-zA-Z-./]+)"
def __init__(self, filename=None, content=None, content_type='yaml'):
self.content = content
@@ -326,11 +326,13 @@ class Yedit(object):
if key_indexes[-1][0]:
if isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1:
del data[int(key_indexes[-1][0])]
+ return True
# expected dict entry
elif key_indexes[-1][1]:
if isinstance(data, dict):
del data[key_indexes[-1][1]]
+ return True
@staticmethod
def add_entry(data, key, item=None):
@@ -447,7 +449,7 @@ class Yedit(object):
return entry
def delete(self, key):
- ''' put key, value into a yaml file '''
+ ''' remove key from a dict'''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -455,11 +457,14 @@ class Yedit(object):
if not entry:
return (False, self.yaml_dict)
- Yedit.remove_entry(self.yaml_dict, key)
+ result = Yedit.remove_entry(self.yaml_dict, key)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def put(self, key, value):
- ''' put key, value into a yaml file '''
+ ''' put key, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -468,11 +473,14 @@ class Yedit(object):
if entry == value:
return (False, self.yaml_dict)
- Yedit.add_entry(self.yaml_dict, key, value)
+ result = Yedit.add_entry(self.yaml_dict, key, value)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def create(self, key, value):
- ''' create the file '''
+ ''' create a yaml file '''
if not self.exists():
self.yaml_dict = {key: value}
return (True, self.yaml_dict)
@@ -545,6 +553,12 @@ def main():
choices=['dc', 'deploymentconfig',
'svc', 'service',
'scc', 'securitycontextconstraints',
+ 'ns', 'namespace', 'project', 'projects',
+ 'is', 'imagestream',
+ 'istag', 'imagestreamtag',
+ 'bc', 'buildconfig',
+ 'routes',
+ 'node',
'secret',
]),
file_name=dict(default=None, type='str'),
diff --git a/roles/lib_openshift_api/library/oc_obj.py b/roles/lib_openshift_api/library/oc_obj.py
index 27135e02e..c058072e3 100644
--- a/roles/lib_openshift_api/library/oc_obj.py
+++ b/roles/lib_openshift_api/library/oc_obj.py
@@ -285,8 +285,8 @@ class YeditException(Exception):
class Yedit(object):
''' Class to modify yaml files '''
- re_valid_key = r"(((\[-?\d+\])|(\w+)).?)+$"
- re_key = r"(?:\[(-?\d+)\])|(\w+)"
+ re_valid_key = r"(((\[-?\d+\])|([a-zA-Z-./]+)).?)+$"
+ re_key = r"(?:\[(-?\d+)\])|([a-zA-Z-./]+)"
def __init__(self, filename=None, content=None, content_type='yaml'):
self.content = content
@@ -326,11 +326,13 @@ class Yedit(object):
if key_indexes[-1][0]:
if isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1:
del data[int(key_indexes[-1][0])]
+ return True
# expected dict entry
elif key_indexes[-1][1]:
if isinstance(data, dict):
del data[key_indexes[-1][1]]
+ return True
@staticmethod
def add_entry(data, key, item=None):
@@ -447,7 +449,7 @@ class Yedit(object):
return entry
def delete(self, key):
- ''' put key, value into a yaml file '''
+ ''' remove key from a dict'''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -455,11 +457,14 @@ class Yedit(object):
if not entry:
return (False, self.yaml_dict)
- Yedit.remove_entry(self.yaml_dict, key)
+ result = Yedit.remove_entry(self.yaml_dict, key)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def put(self, key, value):
- ''' put key, value into a yaml file '''
+ ''' put key, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -468,11 +473,14 @@ class Yedit(object):
if entry == value:
return (False, self.yaml_dict)
- Yedit.add_entry(self.yaml_dict, key, value)
+ result = Yedit.add_entry(self.yaml_dict, key, value)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def create(self, key, value):
- ''' create the file '''
+ ''' create a yaml file '''
if not self.exists():
self.yaml_dict = {key: value}
return (True, self.yaml_dict)
@@ -575,6 +583,13 @@ def main():
type='str',
choices=['dc', 'deploymentconfig',
'svc', 'service',
+ 'scc', 'securitycontextconstraints',
+ 'ns', 'namespace', 'project', 'projects',
+ 'is', 'imagestream',
+ 'istag', 'imagestreamtag',
+ 'bc', 'buildconfig',
+ 'routes',
+ 'node',
'secret',
]),
delete_after=dict(default=False, type='bool'),
diff --git a/roles/lib_openshift_api/library/oc_secret.py b/roles/lib_openshift_api/library/oc_secret.py
index 8e5800e52..a03022e35 100644
--- a/roles/lib_openshift_api/library/oc_secret.py
+++ b/roles/lib_openshift_api/library/oc_secret.py
@@ -285,8 +285,8 @@ class YeditException(Exception):
class Yedit(object):
''' Class to modify yaml files '''
- re_valid_key = r"(((\[-?\d+\])|(\w+)).?)+$"
- re_key = r"(?:\[(-?\d+)\])|(\w+)"
+ re_valid_key = r"(((\[-?\d+\])|([a-zA-Z-./]+)).?)+$"
+ re_key = r"(?:\[(-?\d+)\])|([a-zA-Z-./]+)"
def __init__(self, filename=None, content=None, content_type='yaml'):
self.content = content
@@ -326,11 +326,13 @@ class Yedit(object):
if key_indexes[-1][0]:
if isinstance(data, list) and int(key_indexes[-1][0]) <= len(data) - 1:
del data[int(key_indexes[-1][0])]
+ return True
# expected dict entry
elif key_indexes[-1][1]:
if isinstance(data, dict):
del data[key_indexes[-1][1]]
+ return True
@staticmethod
def add_entry(data, key, item=None):
@@ -447,7 +449,7 @@ class Yedit(object):
return entry
def delete(self, key):
- ''' put key, value into a yaml file '''
+ ''' remove key from a dict'''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -455,11 +457,14 @@ class Yedit(object):
if not entry:
return (False, self.yaml_dict)
- Yedit.remove_entry(self.yaml_dict, key)
+ result = Yedit.remove_entry(self.yaml_dict, key)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def put(self, key, value):
- ''' put key, value into a yaml file '''
+ ''' put key, value into a dict '''
try:
entry = Yedit.get_entry(self.yaml_dict, key)
except KeyError as _:
@@ -468,11 +473,14 @@ class Yedit(object):
if entry == value:
return (False, self.yaml_dict)
- Yedit.add_entry(self.yaml_dict, key, value)
+ result = Yedit.add_entry(self.yaml_dict, key, value)
+ if not result:
+ return (False, self.yaml_dict)
+
return (True, self.yaml_dict)
def create(self, key, value):
- ''' create the file '''
+ ''' create a yaml file '''
if not self.exists():
self.yaml_dict = {key: value}
return (True, self.yaml_dict)