migrate 898 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/python3
  2. import json
  3. import os
  4. import sys
  5. def migrate(values):
  6. storageKey = 'ddnsStorage'
  7. storages = ['data']
  8. for storage in storages:
  9. check_val = values.get(storageKey, {}).get(storage, {})
  10. if not isinstance(check_val, dict) or not check_val or check_val.get('type', 'hostPath') == 'hostPath':
  11. continue
  12. values[storageKey][storage] = {key: value for key, value in check_val.items() if key != 'hostPath'}
  13. for config in values.get('ddnsConfig', {}).get('config', []):
  14. for key in config.keys():
  15. if key.endswith('ProviderIP'):
  16. config.pop(key)
  17. break
  18. return values
  19. if __name__ == '__main__':
  20. if len(sys.argv) != 2:
  21. exit(1)
  22. if os.path.exists(sys.argv[1]):
  23. with open(sys.argv[1], 'r') as f:
  24. print(json.dumps(migrate(json.loads(f.read()))))