volume.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # pylint: skip-file
  2. # flake8: noqa
  3. class Volume(object):
  4. ''' Class to represent an openshift volume object'''
  5. volume_mounts_path = {"pod": "spec.containers[0].volumeMounts",
  6. "dc": "spec.template.spec.containers[0].volumeMounts",
  7. "rc": "spec.template.spec.containers[0].volumeMounts",
  8. }
  9. volumes_path = {"pod": "spec.volumes",
  10. "dc": "spec.template.spec.volumes",
  11. "rc": "spec.template.spec.volumes",
  12. }
  13. @staticmethod
  14. def create_volume_structure(volume_info):
  15. ''' return a properly structured volume '''
  16. volume_mount = None
  17. volume = {'name': volume_info['name']}
  18. volume_type = volume_info['type'].lower()
  19. if volume_type == 'secret':
  20. volume['secret'] = {}
  21. volume[volume_info['type']] = {'secretName': volume_info['secret_name']}
  22. volume_mount = {'mountPath': volume_info['path'],
  23. 'name': volume_info['name']}
  24. elif volume_type == 'emptydir':
  25. volume['emptyDir'] = {}
  26. volume_mount = {'mountPath': volume_info['path'],
  27. 'name': volume_info['name']}
  28. elif volume_type == 'pvc' or volume_type == 'persistentvolumeclaim':
  29. volume['persistentVolumeClaim'] = {}
  30. volume['persistentVolumeClaim']['claimName'] = volume_info['claimName']
  31. volume['persistentVolumeClaim']['claimSize'] = volume_info['claimSize']
  32. elif volume_type == 'hostpath':
  33. volume['hostPath'] = {}
  34. volume['hostPath']['path'] = volume_info['path']
  35. elif volume_type == 'configmap':
  36. volume['configMap'] = {}
  37. volume['configMap']['name'] = volume_info['configmap_name']
  38. volume_mount = {'mountPath': volume_info['path'],
  39. 'name': volume_info['name']}
  40. return (volume, volume_mount)