utils.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2018 Cloudbase Solutions Srl
  2. # All Rights Reserved.
  3. import json
  4. from oslo_log import log as logging
  5. from webob import exc
  6. from coriolis import exception
  7. from coriolis import schemas
  8. LOG = logging.getLogger(__name__)
  9. def _get_show_deleted(val):
  10. if val is None:
  11. return val
  12. try:
  13. show_deleted = json.loads(val)
  14. if type(show_deleted) is bool:
  15. return show_deleted
  16. except Exception as err:
  17. LOG.warn(
  18. "failed to parse show_deleted: %s" % err)
  19. pass
  20. return None
  21. def validate_network_map(network_map):
  22. """ Validates the JSON schema for the network_map. """
  23. try:
  24. schemas.validate_value(
  25. network_map, schemas.CORIOLIS_NETWORK_MAP_SCHEMA)
  26. except exception.SchemaValidationException as ex:
  27. raise exc.HTTPBadRequest(
  28. explanation="Invalid network_map: %s" % str(ex))
  29. def validate_storage_mappings(storage_mappings):
  30. """ Validates the JSON schema for the storage_mappings. """
  31. try:
  32. schemas.validate_value(
  33. storage_mappings, schemas.CORIOLIS_STORAGE_MAPPINGS_SCHEMA)
  34. except exception.SchemaValidationException as ex:
  35. raise exc.HTTPBadRequest(
  36. explanation="Invalid storage_mappings: %s" % str(ex))