Commit 83c3ba87 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Enrich image_public

parent 0e806947
......@@ -33,7 +33,7 @@
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict, print_list, print_items, bold
from kamaki.cli.utils import print_dict, print_list, print_items
from kamaki.cli.errors import raiseCLIError, CLISyntaxError
from kamaki.clients.cyclades import CycladesClient, ClientError
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
......@@ -69,18 +69,18 @@ howto_personality = [
' MODEL: permition in octal (e.g. 0777 or o+rwx)']
def raise_if_connection_error(err):
def raise_if_connection_error(err, base_url='compute.url'):
if err.status == 401:
raiseCLIError(err, 'Authorization failed', details=[
'Make sure a valid token is provided:',
' to check if the token is valid: /astakos authenticate',
' to set a token: /config set [.server.]token <token>',
' to get current token: /config get [server.]token'])
elif err.status in range(-12, 200) + [403]:
elif err.status in range(-12, 200) + [403, 500]:
raiseCLIError(err, details=[
'Check if service is up or set to compute.url',
' to get service url: /config get compute.url',
' to set service url: /config set compute.url <URL>']
'Check if service is up or set to %s' % base_url,
' to get service url: /config get %s' % base_url,
' to set service url: /config set %s <URL>' % base_url]
)
......
......@@ -36,9 +36,10 @@ from kamaki.cli.command_tree import CommandTree
from kamaki.cli.errors import raiseCLIError
from kamaki.cli.utils import print_dict, print_items, bold
from kamaki.clients.image import ImageClient, ClientError
from kamaki.cli.argument import\
FlagArgument, ValueArgument, KeyValueArgument, IntArgument
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
from kamaki.cli.argument import IntArgument
from kamaki.cli.commands.cyclades_cli import _init_cyclades
from kamaki.cli.commands.cyclades_cli import raise_if_connection_error
from kamaki.cli.commands import _command_init
......@@ -79,7 +80,11 @@ class image_public(_init_image):
order=ValueArgument(
'order by FIELD ( - to reverse order)',
'--order',
default='')
default=''),
limit=IntArgument('limit the number of images in list', '-n'),
more=FlagArgument(
'output results in pages (-n to set items per page, default 10)',
'--more')
)
def main(self):
......@@ -100,9 +105,24 @@ class image_public(_init_image):
detail = self['detail']
try:
images = self.client.list_public(detail, filters, order)
except ClientError as ce:
raise_if_connection_error(ce, base_url='image.url')
raiseCLIError(ce)
except Exception as err:
raiseCLIError(err)
print_items(images, title=('name',), with_enumeration=True)
if self['more']:
print_items(
images,
title=('name',),
with_enumeration=True,
page_size=self['limit'] if self['limit'] else 10)
elif self['limit']:
print_items(
images[:self['limit']],
title=('name',),
with_enumeration=True)
else:
print_items(images, title=('name',), with_enumeration=True)
@command(image_cmds)
......
......@@ -159,6 +159,17 @@ class StorageClient(Client):
r = self.put(path, data=data, success=201)
r.release()
def create_object(self, obj):
"""
:param obj: (str) directory-object name
"""
self._assert_container()
path = path4url(self.account, self.container, obj)
self.set_header('Content-Type', 'application/directory')
self.set_header('Content-length', '0')
r = self.put(path, success=201)
r.release()
def create_directory(self, obj):
"""
:param obj: (str) directory-object name
......
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