Commit d486baec authored by Stavros Sachtouris's avatar Stavros Sachtouris

Complete UI/cli interface refactoring, minor bugs

parent be99b6ad
This diff is collapsed.
......@@ -118,6 +118,7 @@ class Argument(object):
class ConfigArgument(Argument):
@property
def value(self):
super(self.__class__, self).value
return super(self.__class__, self).value
@value.setter
......
......@@ -33,12 +33,13 @@
from cmd import Cmd
from os import popen
from argparse import ArgumentParser
from kamaki.cli import _update_parser, _exec_cmd
from .argument import _arguments
from .utils import print_dict
from sys import stdout
from .history import History
from argparse import ArgumentParser
from kamaki.cli import _exec_cmd
from kamaki.cli.argument import _arguments, update_arguments
from kamaki.cli.utils import print_dict
from kamaki.cli.history import History
def _fix_arguments():
......@@ -127,7 +128,8 @@ class Shell(Cmd):
instance = cls(dict(_arguments))
cmd_parser.prog = '%s %s' % (cmd_parser.prog.replace('_', ' '),
cls.syntax)
_update_parser(cmd_parser, instance.arguments)
update_arguments(cmd_parser, instance.arguments)
#_update_parser(cmd_parser, instance.arguments)
if '-h' in cmd_args or '--help' in cmd_args:
cmd_parser.print_help()
return
......
......@@ -38,8 +38,8 @@ from kamaki.cli.errors import raiseCLIError
from kamaki.cli.commands import _command_init
from kamaki.cli.command_tree import CommandTree
astakos_commands = CommandTree('astakos', 'Astakos API commands')
_commands = [astakos_commands]
astakos_cmds = CommandTree('astakos', 'Astakos API commands')
_commands = [astakos_cmds]
class _astakos_init(_command_init):
......@@ -53,12 +53,12 @@ class _astakos_init(_command_init):
self.client = AstakosClient(base_url=base_url, token=token)
@command(_commands)
@command(astakos_cmds)
class astakos_authenticate(_astakos_init):
"""Authenticate a user"""
def main(self, custom_token=None):
super(astakos_authenticate, self).main()
super(self.__class__, self).main()
try:
reply = self.client.authenticate(custom_token)
except ClientError as err:
......
......@@ -34,12 +34,13 @@
from kamaki.cli import command
from kamaki.cli.argument import FlagArgument
from kamaki.cli.commands import _command_init
from kamaki.cli.command_tree import CommandTree
config_cmds = CommandTree('config', 'Configuration commands')
_command = [config_cmds]
API_DESCRIPTION = {'config': 'Configuration commands'}
@command()
@command(config_cmds)
class config_list(_command_init):
"""List configuration options"""
......@@ -55,7 +56,7 @@ class config_list(_command_init):
print('%s.%s = %s' % (section, key, val))
@command()
@command(config_cmds)
class config_get(_command_init):
"""Show a configuration option"""
......@@ -67,7 +68,7 @@ class config_get(_command_init):
print(value)
@command()
@command(config_cmds)
class config_set(_command_init):
"""Set a configuration option"""
......@@ -78,7 +79,7 @@ class config_set(_command_init):
self.config.write()
@command()
@command(config_cmds)
class config_delete(_command_init):
"""Delete a configuration option (and use the default value)"""
......
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.utils import print_dict, print_items, print_list, bold
from kamaki.cli.errors import CLIError, raiseCLIError, CLISyntaxError
from kamaki.clients.cyclades import CycladesClient, ClientError
......@@ -43,10 +44,15 @@ from base64 import b64encode
from os.path import exists
API_DESCRIPTION = {'server': 'Compute/Cyclades API server commands',
'flavor': 'Compute/Cyclades API flavor commands',
'image': 'Compute/Cyclades or Glance API image commands',
'network': 'Compute/Cyclades API network commands'}
server_cmds = CommandTree('server',
'Compute/Cyclades API server commands')
flavor_cmds = CommandTree('flavor',
'Compute/Cyclades API flavor commands')
image_cmds = CommandTree('image',
'Compute/Cyclades or Glance API image commands')
network_cmds = CommandTree('network',
'Compute/Cyclades API network commands')
_commands = [server_cmds, flavor_cmds, image_cmds, network_cmds]
class _init_cyclades(_command_init):
......@@ -58,7 +64,7 @@ class _init_cyclades(_command_init):
self.client = CycladesClient(base_url=base_url, token=token)
@command()
@command(server_cmds)
class server_list(_init_cyclades):
"""List servers"""
......@@ -85,7 +91,7 @@ class server_list(_init_cyclades):
raiseCLIError(err)
@command()
@command(server_cmds)
class server_info(_init_cyclades):
"""Get server details"""
......@@ -145,7 +151,7 @@ class PersonalityArgument(ValueArgument):
pass
@command()
@command(server_cmds)
class server_create(_init_cyclades):
"""Create a server"""
......@@ -179,7 +185,7 @@ class server_create(_init_cyclades):
print_dict(reply)
@command()
@command(server_cmds)
class server_rename(_init_cyclades):
"""Update a server's name"""
......@@ -195,7 +201,7 @@ class server_rename(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_delete(_init_cyclades):
"""Delete a server"""
......@@ -210,7 +216,7 @@ class server_delete(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_reboot(_init_cyclades):
"""Reboot a server"""
......@@ -230,7 +236,7 @@ class server_reboot(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_start(_init_cyclades):
"""Start a server"""
......@@ -245,7 +251,7 @@ class server_start(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_shutdown(_init_cyclades):
"""Shutdown a server"""
......@@ -260,7 +266,7 @@ class server_shutdown(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_console(_init_cyclades):
"""Get a VNC console"""
......@@ -276,7 +282,7 @@ class server_console(_init_cyclades):
print_dict(reply)
@command()
@command(server_cmds)
class server_firewall(_init_cyclades):
"""Set the server's firewall profile"""
......@@ -291,7 +297,7 @@ class server_firewall(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_addr(_init_cyclades):
"""List a server's nic address"""
......@@ -307,7 +313,7 @@ class server_addr(_init_cyclades):
print_list(reply)
@command()
@command(server_cmds)
class server_meta(_init_cyclades):
"""Get a server's metadata"""
......@@ -323,7 +329,7 @@ class server_meta(_init_cyclades):
print_dict(reply)
@command()
@command(server_cmds)
class server_addmeta(_init_cyclades):
"""Add server metadata"""
......@@ -340,7 +346,7 @@ class server_addmeta(_init_cyclades):
print_dict(reply)
@command()
@command(server_cmds)
class server_setmeta(_init_cyclades):
"""Update server's metadata"""
......@@ -358,7 +364,7 @@ class server_setmeta(_init_cyclades):
print_dict(reply)
@command()
@command(server_cmds)
class server_delmeta(_init_cyclades):
"""Delete server metadata"""
......@@ -373,7 +379,7 @@ class server_delmeta(_init_cyclades):
importance=1)
@command()
@command(server_cmds)
class server_stats(_init_cyclades):
"""Get server statistics"""
......@@ -389,7 +395,7 @@ class server_stats(_init_cyclades):
print_dict(reply, exclude=('serverRef',))
@command()
@command(server_cmds)
class server_wait(_init_cyclades):
"""Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]"""
......@@ -421,7 +427,7 @@ class server_wait(_init_cyclades):
print('\nTime out')
@command()
@command(flavor_cmds)
class flavor_list(_init_cyclades):
"""List flavors"""
......@@ -438,7 +444,7 @@ class flavor_list(_init_cyclades):
print_items(flavors)
@command()
@command(flavor_cmds)
class flavor_info(_init_cyclades):
"""Get flavor details"""
......@@ -454,7 +460,7 @@ class flavor_info(_init_cyclades):
print_dict(flavor)
@command()
@command(network_cmds)
class network_list(_init_cyclades):
"""List networks"""
......@@ -479,7 +485,7 @@ class network_list(_init_cyclades):
self.print_networks(networks)
@command()
@command(network_cmds)
class network_create(_init_cyclades):
"""Create a network"""
......@@ -507,7 +513,7 @@ class network_create(_init_cyclades):
print_dict(reply)
@command()
@command(network_cmds)
class network_info(_init_cyclades):
"""Get network details"""
......@@ -527,7 +533,7 @@ class network_info(_init_cyclades):
network_info.print_network(network)
@command()
@command(network_cmds)
class network_rename(_init_cyclades):
"""Update network name"""
......@@ -539,7 +545,7 @@ class network_rename(_init_cyclades):
raiseCLIError(err)
@command()
@command(network_cmds)
class network_delete(_init_cyclades):
"""Delete a network"""
......@@ -551,7 +557,7 @@ class network_delete(_init_cyclades):
raiseCLIError(err)
@command()
@command(network_cmds)
class network_connect(_init_cyclades):
"""Connect a server to a network"""
......@@ -563,7 +569,7 @@ class network_connect(_init_cyclades):
raiseCLIError(err)
@command()
@command(network_cmds)
class network_disconnect(_init_cyclades):
"""Disconnect a nic that connects a server to a network"""
......
......@@ -33,13 +33,14 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.argument import IntArgument, ValueArgument
from kamaki.cli.history import History
from kamaki.cli import command
from kamaki.cli.commands import _command_init
API_DESCRIPTION = {'history': 'Command history'}
history_cmds = CommandTree('history', 'Command history')
class _init_history(_command_init):
......@@ -47,7 +48,7 @@ class _init_history(_command_init):
self.history = History(self.config.get('history', 'file'))
@command()
@command(history_cmds)
class history(_init_history):
"""Show history [containing terms...]"""
......@@ -65,7 +66,7 @@ class history(_init_history):
print(''.join(ret))
@command()
@command(history_cmds)
class history_clean(_init_history):
"""Clean up history"""
......
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.command
from kamaki.cli import command
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
......@@ -41,7 +42,9 @@ from kamaki.cli.commands.cyclades_cli import _init_cyclades
from kamaki.cli.commands import _command_init
API_DESCRIPTION = {'image': 'Compute/Cyclades or Glance API image commands'}
image_cmds = CommandTree('image',
'Compute/Cyclades or Glance API image commands')
_commands = [image_cmds]
class _init_image(_command_init):
......@@ -58,7 +61,7 @@ class _init_image(_command_init):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_public(_init_image):
"""List public images"""
......@@ -102,7 +105,7 @@ class image_public(_init_image):
print_items(images, title=('name',))
@command()
@command(image_cmds)
class image_meta(_init_image):
"""Get image metadata"""
......@@ -115,7 +118,7 @@ class image_meta(_init_image):
print_dict(image)
@command()
@command(image_cmds)
class image_test(_init_image):
"""Test stuff"""
......@@ -128,7 +131,7 @@ class image_test(_init_image):
print('OK...')
@command()
@command(image_cmds)
class image_register(_init_image):
"""Register an image"""
......@@ -184,7 +187,7 @@ class image_register(_init_image):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_members(_init_image):
"""Get image members"""
......@@ -198,7 +201,7 @@ class image_members(_init_image):
print(member['member_id'])
@command()
@command(image_cmds)
class image_shared(_init_image):
"""List shared images"""
......@@ -212,7 +215,7 @@ class image_shared(_init_image):
print(image['image_id'])
@command()
@command(image_cmds)
class image_addmember(_init_image):
"""Add a member to an image"""
......@@ -224,7 +227,7 @@ class image_addmember(_init_image):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_delmember(_init_image):
"""Remove a member from an image"""
......@@ -236,7 +239,7 @@ class image_delmember(_init_image):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_setmembers(_init_image):
"""Set the members of an image"""
......@@ -248,7 +251,7 @@ class image_setmembers(_init_image):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_list(_init_cyclades):
"""List images"""
......@@ -273,7 +276,7 @@ class image_list(_init_cyclades):
self._print(images)
@command()
@command(image_cmds)
class image_info(_init_cyclades):
"""Get image details"""
......@@ -292,7 +295,7 @@ class image_info(_init_cyclades):
self._print(image)
@command()
@command(image_cmds)
class image_delete(_init_cyclades):
"""Delete image"""
......@@ -304,7 +307,7 @@ class image_delete(_init_cyclades):
raiseCLIError(err)
@command()
@command(image_cmds)
class image_properties(_init_cyclades):
"""Get image properties"""
......@@ -317,7 +320,7 @@ class image_properties(_init_cyclades):
print_dict(reply)
@command()
@command(image_cmds)
class image_addproperty(_init_cyclades):
"""Add an image property"""
......@@ -330,7 +333,7 @@ class image_addproperty(_init_cyclades):
print_dict(reply)
@command()
@command(image_cmds)
class image_setproperty(_init_cyclades):
"""Update an image property"""
......@@ -344,7 +347,7 @@ class image_setproperty(_init_cyclades):
print_dict(reply)
@command()
@command(image_cmds)
class image_delproperty(_init_cyclades):
"""Delete an image property"""
......
......@@ -32,6 +32,7 @@
# or implied, of GRNET S.A.command
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.errors import CLIError, raiseCLIError
from kamaki.cli.utils import format_size, print_dict, pretty_keys
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
......@@ -44,7 +45,8 @@ from time import localtime, strftime
from datetime import datetime as dtm
API_DESCRIPTION = dict(store='Pithos+ storage commands')
pithos_cmds = CommandTree('store', 'Pithos+ storage commands')
_commands = [pithos_cmds]
# Argument functionality
......@@ -244,7 +246,7 @@ class _store_container_command(_store_account_command):
self.container = self.client.container
@command()
@command(pithos_cmds)
class store_list(_store_container_command):
"""List containers, object trees or objects in a directory
"""
......@@ -371,7 +373,7 @@ class store_list(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_mkdir(_store_container_command):
"""Create a directory"""
......@@ -384,7 +386,7 @@ class store_mkdir(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_create(_store_container_command):
"""Create a container or a directory object"""
......@@ -411,7 +413,7 @@ class store_create(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_copy(_store_container_command):
"""Copy an object"""
......@@ -448,7 +450,7 @@ class store_copy(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_move(_store_container_command):
"""Copy an object"""
......@@ -486,7 +488,7 @@ class store_move(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_append(_store_container_command):
"""Append local file to (existing) remote object"""
......@@ -512,7 +514,7 @@ class store_append(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_truncate(_store_container_command):
"""Truncate remote file up to a size"""
......@@ -525,7 +527,7 @@ class store_truncate(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_overwrite(_store_container_command):
"""Overwrite part (from start to end) of a remote file"""
......@@ -553,7 +555,7 @@ class store_overwrite(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_manifest(_store_container_command):
"""Create a remote file with uploaded parts by manifestation"""
......@@ -587,7 +589,7 @@ class store_manifest(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_upload(_store_container_command):
"""Upload a file"""
......@@ -651,7 +653,7 @@ class store_upload(_store_container_command):
print 'Upload completed'
@command()
@command(pithos_cmds)
class store_cat(_store_container_command):
"""Print a file to console"""
......@@ -687,7 +689,7 @@ class store_cat(_store_container_command):
raiseCLIError(err)
@command()
@command(pithos_cmds)
class store_download(_store_container_command):
"""Download a file"""
......@@ -763,7 +765,7 @@ class store_download(_store_container_command):
print
@command()
@command(pithos_cmds)
class store_hashmap(_store_container_command):
"""Get the hashmap of an object"""
......@@ -797,7 +799,7 @@ class store_hashmap(_store_container_command):
print_dict(data)