Commit c4aefeaf authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Update and enrich error messages in image register

Parse ivalid property file and guide users to correct it
Guide users to pass valid container:path parameters

parent 9553da85
......@@ -358,6 +358,22 @@ class plankton(object):
'* get a list of image ids: /image list',
'* details of image: /flavor info <image id>']
remote_image_file = [
'Suggested usage:',
' /image register <image container>:<uploaded image file path>',
'To set "image" as image container and "my_dir/img.diskdump" as',
'the remote image file path, try one of the following:',
'- <image container>:<remote path>',
' e.g. image:/my_dir/img.diskdump',
'- <remote path> -C <image container>',
' e.g. /my_dir/img.diskdump -C image',
'To check if the image file is accessible to current user:',
' /file list <image container>',
'If the file is located under a different user id "us3r1d"',
' use the --fileowner=us3r1d argument e.g.:',
' /image register "my" image:my_dir/img.diskdump --fileowner=us3r1d',
'Note: The form pithos://<userid>/<container>/<path> is deprecated']
def connection(this, foo):
return generic._connection(foo, 'image.url')
......@@ -386,7 +402,7 @@ class plankton(object):
def _raise(self, *args, **kwargs):
key = kwargs.get('key', None)
foo(self, *args, **kwargs)
return foo(self, *args, **kwargs)
except ClientError as ce:
ce_msg = ('%s' % ce).lower()
if ce.status == 404 or (
......@@ -396,6 +412,20 @@ class plankton(object):
return _raise
def image_file(this, foo):
def _raise(self, name, container_path):
return foo(self, name, container_path)
except ClientError as ce:
if ce.status in (400,):
'Nonexistent location for %s' % container_path,
importance=2, details=this.remote_image_file)
return _raise
class pithos(object):
container_howto = [
......@@ -319,6 +319,7 @@ class image_register(_init_image):
return container, path
def _run(self, name, container_path):
container, path = self._get_container_path(container_path)
......@@ -351,9 +352,24 @@ class image_register(_init_image):
#load properties
properties = dict()
if self['property_file']:
for k, v in _load_image_props(self['property_file']).items():
properties[k.lower()] = v
pfile = self['property_file']
if pfile:
for k, v in _load_image_props(pfile).items():
properties[k.lower()] = v
except Exception as e:
e, 'Format error in property file %s' % pfile,
'Expected content format:',
' {',
' "key1": "value1",',
' "key2": "value2",',
' ...',
' }',
for k, v in self['properties'].items():
properties[k.lower()] = v
......@@ -368,7 +384,7 @@ class image_register(_init_image):
property_file_location='%s:%s' % (container, prop_path),
print('Property file location is %s:%s with version %s' % (
print('Property file uploaded as %s:%s (version %s)' % (
container, prop_path, prop_headers['x-object-version']))
def main(self, name, container___path):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment