Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
83c3ba87
Commit
83c3ba87
authored
Jan 08, 2013
by
Stavros Sachtouris
Browse files
Enrich image_public
parent
0e806947
Changes
3
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/commands/cyclades_cli.py
View file @
83c3ba87
...
...
@@ -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
]
)
...
...
kamaki/cli/commands/image_cli.py
View file @
83c3ba87
...
...
@@ -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
)
...
...
kamaki/clients/storage.py
View file @
83c3ba87
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment