- def _validate_location(self, location):
- if not location:
- raiseCLIError(
- 'No image file location provided',
- importance=2, details=[
- 'An image location is needed. Image location format:',
- ' <container>:<path>',
- ' where an image file at the above location must exist.'
- ] + howto_image_file)
- try:
- return _validate_image_location(location)
- except AssertionError as ae:
- raiseCLIError(
- ae, 'Invalid image location format',
- importance=1, details=[
- 'Valid image location format:',
- ' <container>:<img-file-path>'
- ] + howto_image_file)
-
- @staticmethod
- def _old_location_format(location):
- prefix = 'pithos://'
- try:
- if location.startswith(prefix):
- uuid, sep, rest = location[len(prefix):].partition('/')
- container, sep, path = rest.partition('/')
- return (uuid, container, path)
- except Exception as e:
- raiseCLIError(e, 'Invalid location format', details=[
- 'Correct location format:', ' <container>:<image path>'])
- return ()
-
- def _mine_location(self, container_path):
- old_response = self._old_location_format(container_path)
- if old_response:
- return old_response
- uuid = self['uuid'] or (self._username2uuid(self['owner_name']) if (
- self['owner_name']) else self._get_user_id())
- if not uuid:
- if self['owner_name']:
- raiseCLIError('No user with username %s' % self['owner_name'])
- raiseCLIError('Failed to get user uuid', details=[
- 'For details on current user:',
- ' /user whoami',
- 'To authenticate a new user through a user token:',
- ' /user authenticate <token>'])
- if self['container']:
- return uuid, self['container'], container_path
- container, sep, path = container_path.partition(':')
- if not (bool(container) and bool(path)):
- raiseCLIError(
- 'Incorrect container-path format', importance=1, details=[
- 'Use : to seperate container form path',
- ' <container>:<image-path>',
- 'OR',
- 'Use -C to specifiy a container',
- ' -C <container> <image-path>'] + howto_image_file)
-
- return uuid, container, path
-