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
14fef2b7
Commit
14fef2b7
authored
May 21, 2013
by
Stavros Sachtouris
Browse files
Merge branch 'feature-json-output' into feature-image-meta-record
parents
36778d79
395fbf9e
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Changelog
View file @
14fef2b7
...
...
@@ -6,6 +6,7 @@ Bug Fixes:
- Shell can manage all valid command line arguments [#3716]
- Restore 2nd level command syntax in shell [#3736]
- Allow copy of deleted objects by refering to older version [#3737]
- Add image.add_member missing content-length header
Changes:
...
...
@@ -18,6 +19,24 @@ Changes:
- Disallow moving deleted objects by version [#3737]
This operation was implemented by accident, due to the symetry between
move and copy
- Rename file-meta commands to file-metadata
- Rename image-[add|del]member commands to members-[add|delete]
- Remove update option from imagre-register
- In image-compute split properties to properties-list and properties-get
- Add optional output to methods[#3756, #3732]:
- file:
mkdir, touch, create, move, copy, move, append, truncate, overwrite,
manifest, upload, delete, purge, unpublish, permissions set/delete, info,
metadata set/delete, containerlimit set, versioning set, group set/delete,
upload, overwrite
- image:
unregister, members add/delete/set
-image compute:
delete, properties delete
- Transliterate methods to list-get-set-delete command groups:
- file: permissions, versioning, group and metadata
- image: members, member
- image compute: properties
Features:
...
...
@@ -34,4 +53,5 @@ Features:
- Add enumeration to all listing commands, make it optional [#3739]
- Add a download_to_string method in pithos client [#3608]
- Add an upload_from_string method in pithos client [#3608]
- Add pithos client method create_container [#3756]
docs/commands.rst
View file @
14fef2b7
...
...
@@ -64,22 +64,26 @@ image (Plankton commands + Compute Image subcommands)
.. code-block:: text
addmember : Add a member to an image
addproperty: Add an image property
delmember : Remove a member from an image
list : List images accessible by user
members : Get image members
meta : Get image metadata
register : (Re)Register an image
setmemb
er
s
:
Set the members of an image
unregist
er :
Unregister an image (does not delete the image file)
shared : List shared images
compute : Compute Image API commands
list : List images
delete : Delete image
info : Get image details
properties : Get image properties
delproperty: Delete an image property
setproperty: Update an image property
properties : Manage properties related to OS installation in an image
add : Add a property to an image
delete: Delete a property from an image
get : Get an image property
list : List all image properties
set : Add / update a set of properties for an image
members : Manage members (users who can modify an image)
add : Add a member to an image
delete : Remove a member from an image
list : List members of an image
set : Set the members of an image
Showcase: Pick an image and list the properties
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
...
@@ -311,38 +315,42 @@ file (Storage/Pithos+)
append : Append local file to remote
cat : Print a file to console
copy : Copy an object
containerlimit: Container size limit commands
set : Set container data limit
get : Get container data limit
create : Create a container
delete : Delete a container [or an object]
delgroup : Delete a user group
delmeta : Delete an existing metadatum for an account [, container [or object]]
delpermissions: Delete all sharing permissions
download : Download a file or directory
group : Get user groups details
group : Manage access groups and group members
delete: Delete a user group
get : Get groups and group members
set : Set a user group
hashmap : Get the hashmap of an object
info : Get information for account [, container [or object]]
list : List containers, object trees or objects in a directory
manifest : Create a remote file with uploaded parts by manifestation
meta : Get custom meta-content for account [, container [or object]]
metadata : Metadata are attached on objects (key:value pairs)
delete: Delete metadata with given key
get : Get metadatum
set : Set a piece of metadata
mkdir : Create a directory
move : Copy an object
overwrite : Overwrite part (from start to end) of a remote file
permissions : Get object read/write permissions
permissions : Manage user and group accessibility for objects
delete: Delete all permissions set on object
get : Get read and write permissions of an object
set : Set permissions for an object
publish : Publish an object
purge : Purge a container
quota : Get quota for account
setgroup : Create/update a new user group
setmeta : Set a new metadatum for account [, container [or object]]
setpermissions: Set sharing permissions
containerlimit: Container size limit commands
set : Set container data limit
get : Get container data limit
setversioning : Set new versioning (auto, none) for account [or container]
sharers : List the accounts that share objects with default account
touch : Create an empty object (file)
truncate : Truncate remote file up to a size
unpublish : Unpublish an object
upload : Upload a file or directory
versioning : Get versioning for account [or container ]
versioning : Manage the versioning scheme of current pithos user account
get: Get versioning for account or container
set: Set versioning mode (auto, none) for account or container
versions : Get the version list of an object
Showcase: Upload and download a file
...
...
docs/man/kamaki.rst
View file @
14fef2b7
...
...
@@ -140,27 +140,26 @@ flavor commands
image commands
**************
* addmember Add a member to an image
* addproperty Add an OS-related property to an image
* delete Delete an image (image file remains intact)
* delmember Remove a member from an image
* delproperty Delete a property of an image
* info Get detailed information on an image
* members Get image members
* meta Get image metadata
* properties Get properties related to OS installation in an image
* list List images accessible by user
* register (Re)Register an image
* setmembers Set the members of an image
* setproperty Update an existing property in an image
* shared List images shared by a member
* compute Compute Image API commands
* list List images
* delete Delete image
* info Get image details
* properties Get image properties
* delproperty Delete an image property
* setproperty Update an image property
* list List images accessible by user
* meta Get image metadata
* register (Re)Register an image
* unregister Unregister an image (does not delete the image file)
* shared List shared images
* compute Compute Image API commands
* list List images
* delete Delete image
* info Get image details
* properties Manage properties related to OS installation in an image
* add Add a property to an image
* delete Delete a property from an image
* get Get an image property
* list List all image properties
* set Add / update a set of properties for an image
* members Manage members (users who can modify an image)
* add Add a member to an image
* delete Remove a member from an image
* list List members of an image
* set Set the members of an image
network commands
...
...
@@ -178,41 +177,46 @@ network commands
file commands
**************
* append Append local file to (existing) remote object
* cat Print remote file contents to console
* copy Copy an object from container to (another) container
* create Create a container
* delete Delete a container [or an object]
* delgroup Delete a user group
* delmeta Delete metadata from account, container or object
* delpermissions Delete all permissions set on object
* download Download remote object(s) as local file(s)
* group Get groups and group members
* hashmap Get the hash-map of an object
* info Get detailed info for account, containers or objects
* list List containers, object trees or objects in a directory
* manifest Create a remote file of uploaded parts by manifestation
* meta Get metadata for account, containers or objects
* mkdir Create a directory
* move Copy an object
* overwrite Overwrite part (from start to end) of a remote file
* permissions Get read and write permissions of an object
* publish Publish the object and print the public url
* purge Delete a container and release related data blocks
* quota Get quota (in KB) for account or container
* setgroup Set a user group
* setmeta Set a piece of metadata for account, container or object
* setpermissions Set permissions for an object
* containerlimit set Set new limit for container
* containerlimit get Get container limit
* setversioning Set versioning mode (auto, none) for account or container
* sharers List the accounts that share objects with current user
* touch Create an empty object (file)
* truncate Truncate remote file up to a size
* unpublish Unpublish an object
* upload Upload a file or directory
* versioning Get versioning for account or container
* versions Get the list of object versions
* append Append local file to remote
* cat Print a file to console
* copy Copy an object
* containerlimit Container size limit commands
* set Set container data limit
* get Get container data limit
* create Create a container
* delete Delete a container [or an object]
* download Download a file or directory
* group Manage access groups and group members
* delete Delete a user group
* get Get groups and group members
* set Set a user group
* hashmap Get the hashmap of an object
* info Get information for account [, container [or object]]
* list List containers, object trees or objects in a directory
* manifest Create a remote file with uploaded parts by manifestation
* metadata Metadata are attached on objects (key:value pairs)
* delete Delete metadata with given key
* get Get metadatum
* set Set a piece of metadata
* mkdir Create a directory
* move Copy an object
* overwrite Overwrite part (from start to end) of a remote file
* permissions Manage user and group accessibility for objects
* delete Delete all permissions set on object
* get Get read and write permissions of an object
* set Set permissions for an object
* publish Publish an object
* purge Purge a container
* quota Get quota for account
* sharers List the accounts that share objects with default account
* touch Create an empty object (file)
* truncate Truncate remote file up to a size
* unpublish Unpublish an object
* upload Upload a file or directory
* versioning Manage the versioning scheme of current pithos user account
* get Get versioning for account or container
* set Set versioning mode (auto, none) for account or container
* versions Get the version list of an object
test commands (hidden)
...
...
kamaki/cli/commands/__init__.py
View file @
14fef2b7
...
...
@@ -32,6 +32,8 @@
# or implied, of GRNET S.A.command
from
kamaki.logger
import
get_logger
from
kamaki.cli.utils
import
print_json
,
print_items
from
kamaki.cli.argument
import
FlagArgument
log
=
get_logger
(
__name__
)
...
...
@@ -41,10 +43,11 @@ class _command_init(object):
def
__init__
(
self
,
arguments
=
{}):
if
hasattr
(
self
,
'arguments'
):
arguments
.
update
(
self
.
arguments
)
if
isinstance
(
self
,
_optional_output_cmd
):
arguments
.
update
(
self
.
oo_arguments
)
self
.
arguments
=
dict
(
arguments
)
try
:
self
.
config
=
self
[
'config'
]
#self.config = self.get_argument('config')
except
KeyError
:
pass
...
...
@@ -124,3 +127,17 @@ class _command_init(object):
:raises KeyError: if argterm not in self.arguments of this object
"""
return
self
[
argterm
]
class
_optional_output_cmd
(
object
):
oo_arguments
=
dict
(
with_output
=
FlagArgument
(
'show response headers'
,
(
'--with-output'
)),
json_output
=
FlagArgument
(
'show headers in json'
,
(
'-j'
,
'--json'
))
)
def
_optional_output
(
self
,
r
):
if
self
[
'json_output'
]:
print_json
(
r
)
elif
self
[
'with_output'
]:
print_items
([
r
]
if
isinstance
(
r
,
dict
)
else
r
)
kamaki/cli/commands/image.py
View file @
14fef2b7
...
...
@@ -33,12 +33,12 @@
from
kamaki.cli
import
command
from
kamaki.cli.command_tree
import
CommandTree
from
kamaki.cli.utils
import
print_dict
,
print_items
from
kamaki.cli.utils
import
print_dict
,
print_items
,
print_json
from
kamaki.clients.image
import
ImageClient
from
kamaki.cli.argument
import
FlagArgument
,
ValueArgument
,
KeyValueArgument
from
kamaki.cli.argument
import
IntArgument
from
kamaki.cli.commands.cyclades
import
_init_cyclades
from
kamaki.cli.commands
import
_command_init
,
errors
from
kamaki.cli.commands
import
_command_init
,
errors
,
_optional_output_cmd
image_cmds
=
CommandTree
(
...
...
@@ -104,7 +104,8 @@ class image_list(_init_image):
more
=
FlagArgument
(
'output results in pages (-n to set items per page, default 10)'
,
'--more'
),
enum
=
FlagArgument
(
'Enumerate results'
,
'--enumerate'
)
enum
=
FlagArgument
(
'Enumerate results'
,
'--enumerate'
),
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
def
_filtered_by_owner
(
self
,
detail
,
*
list_params
):
...
...
@@ -146,8 +147,11 @@ class image_list(_init_image):
images
=
self
.
_filtered_by_owner
(
detail
,
filters
,
order
)
else
:
images
=
self
.
client
.
list_public
(
detail
,
filters
,
order
)
images
=
self
.
_filtered_by_name
(
images
)
if
self
[
'json_output'
]:
print_json
(
images
)
return
images
=
self
.
_filtered_by_name
(
images
)
if
self
[
'more'
]:
print_items
(
images
,
...
...
@@ -171,12 +175,16 @@ class image_meta(_init_image):
- image os properties (os, fs, etc.)
"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
image
=
self
.
client
.
get_meta
(
image_id
)
print
_dict
(
image
)
printer
=
print_json
if
self
[
'json_output'
]
else
print_dict
print
er
(
self
.
client
.
get_meta
(
image
_id
)
)
def
main
(
self
,
image_id
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -200,9 +208,10 @@ class image_register(_init_image):
(
'-p'
,
'--property'
)),
is_public
=
FlagArgument
(
'mark image as public'
,
'--public'
),
size
=
IntArgument
(
'set image size'
,
'--size'
),
update
=
FlagArgument
(
'update existing image properties'
,
(
'-u'
,
'--update'
))
#update=FlagArgument(
# 'update existing image properties',
# ('-u', '--update')),
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
...
...
@@ -232,11 +241,9 @@ class image_register(_init_image):
params
[
key
]
=
self
[
key
]
properties
=
self
[
'properties'
]
if
self
[
'update'
]:
self
.
client
.
reregister
(
location
,
name
,
params
,
properties
)
else
:
r
=
self
.
client
.
register
(
name
,
location
,
params
,
properties
)
print_dict
(
r
)
printer
=
print_json
if
self
[
'json_output'
]
else
print_dict
printer
(
self
.
client
.
register
(
name
,
location
,
params
,
properties
))
def
main
(
self
,
name
,
location
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -244,14 +251,14 @@ class image_register(_init_image):
@
command
(
image_cmds
)
class
image_unregister
(
_init_image
):
class
image_unregister
(
_init_image
,
_optional_output_cmd
):
"""Unregister an image (does not delete the image file)"""
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
self
.
client
.
unregister
(
image_id
)
self
.
_optional_output
(
self
.
client
.
unregister
(
image_id
)
)
def
main
(
self
,
image_id
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -259,45 +266,64 @@ class image_unregister(_init_image):
@
command
(
image_cmds
)
class
image_members
(
_init_image
):
"""Get image members"""
class
image_shared
(
_init_image
):
"""List images shared by a member"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
members
=
self
.
client
.
list_members
(
image_id
)
print_items
(
members
)
def
_run
(
self
,
member
):
r
=
self
.
client
.
list_shared
(
member
)
if
self
[
'json_output'
]:
print_json
(
r
)
else
:
print_items
(
r
,
title
=
(
'image_id'
,))
def
main
(
self
,
image_id
):
def
main
(
self
,
member
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
image_id
=
image_id
)
self
.
_run
(
member
)
@
command
(
image_cmds
)
class
image_shared
(
_init_image
):
"""List images shared by a member"""
class
image_members
(
_init_image
):
"""Manage members. Members of an image are users who can modify it"""
@
command
(
image_cmds
)
class
image_members_list
(
_init_image
):
"""List members of an image"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
def
_run
(
self
,
member
):
images
=
self
.
client
.
list_shared
(
member
)
print_items
(
images
)
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
members
=
self
.
client
.
list_members
(
image_id
)
if
self
[
'json_output'
]:
print_json
(
members
)
else
:
print_items
(
members
,
title
=
(
'member_id'
,),
with_redundancy
=
True
)
def
main
(
self
,
member
):
def
main
(
self
,
image_id
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
member
)
self
.
_run
(
image_id
=
image_id
)
@
command
(
image_cmds
)
class
image_
add
member
(
_init_image
):
class
image_member
s_add
(
_init_image
,
_optional_output_cmd
):
"""Add a member to an image"""
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
=
None
,
member
=
None
):
self
.
client
.
add_member
(
image_id
,
member
)
self
.
_optional_output
(
self
.
client
.
add_member
(
image_id
,
member
)
)
def
main
(
self
,
image_id
,
member
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -305,14 +331,14 @@ class image_addmember(_init_image):
@
command
(
image_cmds
)
class
image_
del
member
(
_init_image
):
class
image_member
s_delete
(
_init_image
,
_optional_output_cmd
):
"""Remove a member from an image"""
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
=
None
,
member
=
None
):
self
.
client
.
remove_member
(
image_id
,
member
)
self
.
_optional_output
(
self
.
client
.
remove_member
(
image_id
,
member
)
)
def
main
(
self
,
image_id
,
member
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -320,14 +346,14 @@ class image_delmember(_init_image):
@
command
(
image_cmds
)
class
image_
set
members
(
_init_image
):
class
image_members
_set
(
_init_image
,
_optional_output_cmd
):
"""Set the members of an image"""
@
errors
.
generic
.
all
@
errors
.
plankton
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
,
members
):
self
.
client
.
set_members
(
image_id
,
members
)
self
.
_optional_output
(
self
.
client
.
set_members
(
image_id
,
members
)
)
def
main
(
self
,
image_id
,
*
members
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -352,7 +378,8 @@ class image_compute_list(_init_cyclades):
more
=
FlagArgument
(
'output results in pages (-n to set items per page, default 10)'
,
'--more'
),
enum
=
FlagArgument
(
'Enumerate results'
,
'--enumerate'
)
enum
=
FlagArgument
(
'Enumerate results'
,
'--enumerate'
),
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
def
_make_results_pretty
(
self
,
images
):
...
...
@@ -364,6 +391,9 @@ class image_compute_list(_init_cyclades):
@
errors
.
cyclades
.
connection
def
_run
(
self
):
images
=
self
.
client
.
list_images
(
self
[
'detail'
])
if
self
[
'json_output'
]:
print_json
(
images
)
return
if
self
[
'detail'
]:
self
.
_make_results_pretty
(
images
)
if
self
[
'more'
]:
...
...
@@ -382,11 +412,18 @@ class image_compute_list(_init_cyclades):
class
image_compute_info
(
_init_cyclades
):
"""Get detailed information on an image"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
cyclades
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
image
=
self
.
client
.
get_image_details
(
image_id
)
if
self
[
'json_output'
]:
print_json
(
image
)
return
if
'metadata'
in
image
:
image
[
'metadata'
]
=
image
[
'metadata'
][
'values'
]
print_dict
(
image
)
...
...
@@ -397,14 +434,14 @@ class image_compute_info(_init_cyclades):
@
command
(
image_cmds
)
class
image_compute_delete
(
_init_cyclades
):
class
image_compute_delete
(
_init_cyclades
,
_optional_output_cmd
):
"""Delete an image (WARNING: image file is also removed)"""
@
errors
.
generic
.
all
@
errors
.
cyclades
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
self
.
client
.
delete_image
(
image_id
)
self
.
_optional_output
(
self
.
client
.
delete_image
(
image_id
)
)
def
main
(
self
,
image_id
):
super
(
self
.
__class__
,
self
).
_run
()
...
...
@@ -413,32 +450,65 @@ class image_compute_delete(_init_cyclades):
@
command
(
image_cmds
)
class
image_compute_properties
(
_init_cyclades
):
"""Get properties related to OS installation in an image"""
"""Manage properties related to OS installation in an image"""
@
command
(
image_cmds
)
class
image_compute_properties_list
(
_init_cyclades
):
"""List all image properties"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
cyclades
.
connection
@
errors
.
plankton
.
id
def
_run
(
self
,
image_id
):
printer
=
print_json
if
self
[
'json_output'
]
else
print_dict
printer
(
self
.
client
.
get_image_metadata
(
image_id
))
def
main
(
self
,
image_id
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
image_id
=
image_id
)
@
command
(
image_cmds
)
class
image_compute_properties_get
(
_init_cyclades
):
"""Get an image property"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)
@
errors
.
generic
.
all
@
errors
.
cyclades
.
connection
@
errors
.
plankton
.
id
@
errors
.
plankton
.
metadata
def
_run
(
self
,
image_id
,
key
):
r
=
self
.
client
.
get_image_metadata
(
image_id
,
key
)
print
_dict
(
r
)
printer
=
print_json
if
self
[
'json_output'
]
else
print_dict
print
er
(
self
.
client
.
get_image_metadata
(
image_id
,
key
)
)
def
main
(
self
,
image_id
,
key
=
''
):
def
main
(
self
,
image_id
,
key
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
image_id
=
image_id
,
key
=
key
)
@
command
(
image_cmds
)
class
image_compute_addproperty
(
_init_cyclades
):
"""Add an OS-related property to an image"""
class
image_compute_properties_add
(
_init_cyclades
):
"""Add a property to an image"""
arguments
=
dict
(
json_output
=
FlagArgument
(
'Show results in json'
,
(
'-j'
,
'--json'
))
)