Skip to content

Commit

Permalink
Adding ability to delete by selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny Woodson committed Apr 3, 2017
1 parent 3a5376d commit 24a063e
Show file tree
Hide file tree
Showing 33 changed files with 813 additions and 500 deletions.
38 changes: 21 additions & 17 deletions roles/lib_openshift/library/oc_adm_ca_server_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,15 @@ def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])

def _delete(self, resource, rname, selector=None):
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource, rname]
if selector:
cmd.append('--selector=%s' % selector)
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')

return self.openshift_cmd(cmd)

Expand All @@ -941,7 +945,7 @@ def _process(self, template_name, create=False, params=None, template_data=None)
else:
cmd.append(template_name)
if params:
param_str = ["%s=%s" % (key, value) for key, value in params.items()]
param_str = ["{}={}".format(key, value) for key, value in params.items()]
cmd.append('-v')
cmd.extend(param_str)

Expand All @@ -958,13 +962,13 @@ def _process(self, template_name, create=False, params=None, template_data=None)

return self.openshift_cmd(['create', '-f', fname])

def _get(self, resource, rname=None, selector=None):
def _get(self, resource, name=None, selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector:
cmd.append('--selector=%s' % selector)
elif rname:
cmd.append(rname)
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)

cmd.extend(['-o', 'json'])

Expand All @@ -984,9 +988,9 @@ def _schedulable(self, node=None, selector=None, schedulable=True):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

cmd.append('--schedulable=%s' % schedulable)
cmd.append('--schedulable={}'.format(schedulable))

return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501

Expand All @@ -1001,10 +1005,10 @@ def _list_pods(self, node=None, selector=None, pod_selector=None):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

cmd.extend(['--list-pods', '-o', 'json'])

Expand All @@ -1017,16 +1021,16 @@ def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False,
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if dry_run:
cmd.append('--dry-run')

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

if grace_period:
cmd.append('--grace-period=%s' % int(grace_period))
cmd.append('--grace-period={}'.format(int(grace_period)))

if force:
cmd.append('--force')
Expand Down
40 changes: 22 additions & 18 deletions roles/lib_openshift/library/oc_adm_manage_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,11 +905,15 @@ def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])

def _delete(self, resource, rname, selector=None):
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource, rname]
if selector:
cmd.append('--selector=%s' % selector)
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')

return self.openshift_cmd(cmd)

Expand All @@ -927,7 +931,7 @@ def _process(self, template_name, create=False, params=None, template_data=None)
else:
cmd.append(template_name)
if params:
param_str = ["%s=%s" % (key, value) for key, value in params.items()]
param_str = ["{}={}".format(key, value) for key, value in params.items()]
cmd.append('-v')
cmd.extend(param_str)

Expand All @@ -944,13 +948,13 @@ def _process(self, template_name, create=False, params=None, template_data=None)

return self.openshift_cmd(['create', '-f', fname])

def _get(self, resource, rname=None, selector=None):
def _get(self, resource, name=None, selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector:
cmd.append('--selector=%s' % selector)
elif rname:
cmd.append(rname)
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)

cmd.extend(['-o', 'json'])

Expand All @@ -970,9 +974,9 @@ def _schedulable(self, node=None, selector=None, schedulable=True):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

cmd.append('--schedulable=%s' % schedulable)
cmd.append('--schedulable={}'.format(schedulable))

return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501

Expand All @@ -987,10 +991,10 @@ def _list_pods(self, node=None, selector=None, pod_selector=None):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

cmd.extend(['--list-pods', '-o', 'json'])

Expand All @@ -1003,16 +1007,16 @@ def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False,
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if dry_run:
cmd.append('--dry-run')

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

if grace_period:
cmd.append('--grace-period=%s' % int(grace_period))
cmd.append('--grace-period={}'.format(int(grace_period)))

if force:
cmd.append('--force')
Expand Down Expand Up @@ -1457,7 +1461,7 @@ def get_nodes(self, node=None, selector=''):
if selector:
_sel = selector

results = self._get('node', rname=_node, selector=_sel)
results = self._get('node', name=_node, selector=_sel)
if results['returncode'] != 0:
return results

Expand Down
38 changes: 21 additions & 17 deletions roles/lib_openshift/library/oc_adm_policy_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,15 @@ def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])

def _delete(self, resource, rname, selector=None):
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource, rname]
if selector:
cmd.append('--selector=%s' % selector)
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')

return self.openshift_cmd(cmd)

Expand All @@ -913,7 +917,7 @@ def _process(self, template_name, create=False, params=None, template_data=None)
else:
cmd.append(template_name)
if params:
param_str = ["%s=%s" % (key, value) for key, value in params.items()]
param_str = ["{}={}".format(key, value) for key, value in params.items()]
cmd.append('-v')
cmd.extend(param_str)

Expand All @@ -930,13 +934,13 @@ def _process(self, template_name, create=False, params=None, template_data=None)

return self.openshift_cmd(['create', '-f', fname])

def _get(self, resource, rname=None, selector=None):
def _get(self, resource, name=None, selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector:
cmd.append('--selector=%s' % selector)
elif rname:
cmd.append(rname)
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)

cmd.extend(['-o', 'json'])

Expand All @@ -956,9 +960,9 @@ def _schedulable(self, node=None, selector=None, schedulable=True):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

cmd.append('--schedulable=%s' % schedulable)
cmd.append('--schedulable={}'.format(schedulable))

return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501

Expand All @@ -973,10 +977,10 @@ def _list_pods(self, node=None, selector=None, pod_selector=None):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

cmd.extend(['--list-pods', '-o', 'json'])

Expand All @@ -989,16 +993,16 @@ def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False,
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if dry_run:
cmd.append('--dry-run')

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

if grace_period:
cmd.append('--grace-period=%s' % int(grace_period))
cmd.append('--grace-period={}'.format(int(grace_period)))

if force:
cmd.append('--force')
Expand Down
38 changes: 21 additions & 17 deletions roles/lib_openshift/library/oc_adm_policy_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,15 @@ def _create(self, fname):
'''call oc create on a filename'''
return self.openshift_cmd(['create', '-f', fname])

def _delete(self, resource, rname, selector=None):
def _delete(self, resource, name=None, selector=None):
'''call oc delete on a resource'''
cmd = ['delete', resource, rname]
if selector:
cmd.append('--selector=%s' % selector)
cmd = ['delete', resource]
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)
else:
raise OpenShiftCLIError('Either name or selector is required when calling delete.')

return self.openshift_cmd(cmd)

Expand All @@ -913,7 +917,7 @@ def _process(self, template_name, create=False, params=None, template_data=None)
else:
cmd.append(template_name)
if params:
param_str = ["%s=%s" % (key, value) for key, value in params.items()]
param_str = ["{}={}".format(key, value) for key, value in params.items()]
cmd.append('-v')
cmd.extend(param_str)

Expand All @@ -930,13 +934,13 @@ def _process(self, template_name, create=False, params=None, template_data=None)

return self.openshift_cmd(['create', '-f', fname])

def _get(self, resource, rname=None, selector=None):
def _get(self, resource, name=None, selector=None):
'''return a resource by name '''
cmd = ['get', resource]
if selector:
cmd.append('--selector=%s' % selector)
elif rname:
cmd.append(rname)
if selector is not None:
cmd.append('--selector={}'.format(selector))
elif name is not None:
cmd.append(name)

cmd.extend(['-o', 'json'])

Expand All @@ -956,9 +960,9 @@ def _schedulable(self, node=None, selector=None, schedulable=True):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

cmd.append('--schedulable=%s' % schedulable)
cmd.append('--schedulable={}'.format(schedulable))

return self.openshift_cmd(cmd, oadm=True, output=True, output_type='raw') # noqa: E501

Expand All @@ -973,10 +977,10 @@ def _list_pods(self, node=None, selector=None, pod_selector=None):
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

cmd.extend(['--list-pods', '-o', 'json'])

Expand All @@ -989,16 +993,16 @@ def _evacuate(self, node=None, selector=None, pod_selector=None, dry_run=False,
if node:
cmd.extend(node)
else:
cmd.append('--selector=%s' % selector)
cmd.append('--selector={}'.format(selector))

if dry_run:
cmd.append('--dry-run')

if pod_selector:
cmd.append('--pod-selector=%s' % pod_selector)
cmd.append('--pod-selector={}'.format(pod_selector))

if grace_period:
cmd.append('--grace-period=%s' % int(grace_period))
cmd.append('--grace-period={}'.format(int(grace_period)))

if force:
cmd.append('--force')
Expand Down
Loading

0 comments on commit 24a063e

Please sign in to comment.