obj.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # pylint: skip-file
  2. class OCObject(OpenShiftCLI):
  3. ''' Class to wrap the oc command line tools '''
  4. # pylint allows 5. we need 6
  5. # pylint: disable=too-many-arguments
  6. def __init__(self,
  7. kind,
  8. namespace,
  9. rname=None,
  10. kubeconfig='/etc/origin/master/admin.kubeconfig',
  11. verbose=False):
  12. ''' Constructor for OpenshiftOC '''
  13. super(OCObject, self).__init__(namespace, kubeconfig)
  14. self.kind = kind
  15. self.namespace = namespace
  16. self.name = rname
  17. self.kubeconfig = kubeconfig
  18. self.verbose = verbose
  19. def get(self):
  20. '''return a deploymentconfig by name '''
  21. return self._get(self.kind, rname=self.name)
  22. def delete(self):
  23. '''return all pods '''
  24. return self._delete(self.kind, self.name)
  25. def create(self, files=None, content=None):
  26. '''Create a deploymentconfig '''
  27. if files:
  28. return self._create(files[0])
  29. return self._create(Utils.create_files_from_contents(content))
  30. # pylint: disable=too-many-function-args
  31. def update(self, files=None, content=None, force=False):
  32. '''run update dc
  33. This receives a list of file names and takes the first filename and calls replace.
  34. '''
  35. if files:
  36. return self._replace(files[0], force)
  37. return self.update_content(content, force)
  38. def update_content(self, content, force=False):
  39. '''update the dc with the content'''
  40. return self._replace_content(self.kind, self.name, content, force=force)
  41. def needs_update(self, files=None, content=None, content_type='yaml'):
  42. ''' check to see if we need to update '''
  43. objects = self.get()
  44. if objects['returncode'] != 0:
  45. return objects
  46. # pylint: disable=no-member
  47. data = None
  48. if files:
  49. data = Utils.get_resource_file(files[0], content_type)
  50. # if equal then no need. So not equal is True
  51. return not Utils.check_def_equal(data, objects['results'][0], True)
  52. else:
  53. data = content
  54. for key, value in data.items():
  55. if key == 'metadata':
  56. continue
  57. if not objects['results'][0].has_key(key):
  58. return True
  59. if value != objects['results'][0][key]:
  60. return True
  61. return False