Commit 794b743e authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Rename _commands to namespaces in kamaki.cli.cmds

The underscore is removed because it is a global variable used
outside of the modules it is declared.
The new name is a precise description of what this variable is
used for.
parent 596997be
......@@ -115,7 +115,7 @@ def command(cmd_tree, prefix='', descedants_depth=1):
e.g., spec_cmd0_cmd1 will be command spec cmd0
:param cmd_tree: is initialized in cmd_spec file and is the structure
where commands are loaded. Var name should be _commands
where commands are loaded. Var name should be "namespaces"
:param prefix: if given, load only commands prefixed with prefix,
:param descedants_depth: is the depth of the tree descedants of the
prefix command. It is used ONLY if prefix and if prefix is not
......@@ -366,11 +366,11 @@ def _groups_help(arguments):
descriptions = {}
acceptable_groups = arguments['config'].groups
for cmd_group, spec in arguments['config'].cli_specs:
pkg = _load_spec_module(spec, arguments, '_commands')
pkg = _load_spec_module(spec, arguments, 'namespaces')
if pkg:
cmds = getattr(pkg, '_commands')
namespaces = getattr(pkg, 'namespaces')
for cmd_tree in cmds:
for cmd_tree in namespaces:
if in acceptable_groups:
descriptions[] = cmd_tree.description
except TypeError:
......@@ -387,14 +387,14 @@ def _load_all_commands(cmd_tree, arguments):
_cnf = arguments['config']
for cmd_group, spec in _cnf.cli_specs:
spec_module = _load_spec_module(spec, arguments, '_commands')
spec_commands = getattr(spec_module, '_commands')
spec_module = _load_spec_module(spec, arguments, 'namespaces')
namespaces = getattr(spec_module, 'namespaces')
except AttributeError:
if _debug:
global kloger
kloger.warning('No valid description for %s' % cmd_group)
for spec_tree in spec_commands:
for spec_tree in namespaces:
if == cmd_group:
......@@ -48,28 +48,27 @@ from kamaki.cli.utils import format_size, filter_dicts_by_dict
# Mandatory
user_commands = CommandTree('user', 'Astakos/Identity API commands')
quota_commands = CommandTree(
user_cmds = CommandTree('user', 'Astakos/Identity API commands')
quota_cmds = CommandTree(
'quota', 'Astakos/Account API commands for quotas')
resource_commands = CommandTree(
resource_cmds = CommandTree(
'resource', 'Astakos/Account API commands for resources')
project_commands = CommandTree('project', 'Astakos project API commands')
membership_commands = CommandTree(
project_cmds = CommandTree('project', 'Astakos project API commands')
membership_cmds = CommandTree(
'membership', 'Astakos project membership API commands')
# Optional
endpoint_commands = CommandTree(
endpoint_cmds = CommandTree(
'endpoint', 'Astakos/Account API commands for endpoints')
service_commands = CommandTree('service', 'Astakos API commands for services')
commission_commands = CommandTree(
service_cmds = CommandTree('service', 'Astakos API commands for services')
commission_cmds = CommandTree(
'commission', 'Astakos API commands for commissions')
_commands = [
user_commands, quota_commands, resource_commands, project_commands,
service_commands, commission_commands, endpoint_commands,
namespaces = [
user_cmds, quota_cmds, resource_cmds, project_cmds, service_cmds,
commission_cmds, endpoint_cmds, membership_cmds]
def with_temp_token(func):
......@@ -115,7 +114,7 @@ class _AstakosInit(CommandInit):
class user_authenticate(_AstakosInit, OptionalOutput):
"""Authenticate a user and get all authentication information"""
......@@ -131,7 +130,7 @@ class user_authenticate(_AstakosInit, OptionalOutput):
class user_uuid2name(_AstakosInit, OptionalOutput):
"""Get user name(s) from uuid(s)"""
......@@ -149,7 +148,7 @@ class user_uuid2name(_AstakosInit, OptionalOutput):
self._run(uuids=((uuid, ) + more_uuids))
class user_name2uuid(_AstakosInit, OptionalOutput):
"""Get user uuid(s) from name(s)"""
......@@ -167,7 +166,7 @@ class user_name2uuid(_AstakosInit, OptionalOutput):
self._run(usernames=((username, ) + more_usernames))
class quota_list(_AstakosInit, OptionalOutput):
"""Show user quotas"""
......@@ -220,7 +219,7 @@ class quota_list(_AstakosInit, OptionalOutput):
# command user session
class user_info(_AstakosInit, OptionalOutput):
"""Get info for (current) session user"""
......@@ -252,7 +251,7 @@ class user_info(_AstakosInit, OptionalOutput):
self._print(self.auth_base.user_info(token), self.print_dict)
class user_add(_AstakosInit, OptionalOutput):
"""Authenticate a user by token and add to kamaki session (cache)"""
......@@ -276,7 +275,7 @@ class user_add(_AstakosInit, OptionalOutput):
class user_list(_AstakosInit, OptionalOutput):
"""List (cached) session users"""
......@@ -295,7 +294,7 @@ class user_list(_AstakosInit, OptionalOutput):
class user_select(_AstakosInit):
"""Select a user from the (cached) list as the current session user"""
......@@ -334,7 +333,7 @@ class user_select(_AstakosInit):
class user_delete(_AstakosInit):
"""Delete a user (token) from the (cached) list of session users"""
......@@ -372,7 +371,7 @@ class user_delete(_AstakosInit):
# command admin
class service_list(_AstakosInit, OptionalOutput):
"""List available services"""
......@@ -386,7 +385,7 @@ class service_list(_AstakosInit, OptionalOutput):
class service_uuid2username(_AstakosInit, OptionalOutput):
"""Get service username(s) from uuid(s)"""
......@@ -406,7 +405,7 @@ class service_uuid2username(_AstakosInit, OptionalOutput):
self._run([uuid] + list(more_uuids), token=service_token)
class service_username2uuid(_AstakosInit, OptionalOutput):
"""Get service uuid(s) from username(s)"""
......@@ -426,7 +425,7 @@ class service_username2uuid(_AstakosInit, OptionalOutput):
self._run([usernames] + list(more_usernames), token=service_token)
class service_quotas(_AstakosInit, OptionalOutput):
"""Get service quotas"""
......@@ -445,7 +444,7 @@ class service_quotas(_AstakosInit, OptionalOutput):
class commission_pending(_AstakosInit, OptionalOutput):
"""List pending commissions (special privileges required)"""
......@@ -459,7 +458,7 @@ class commission_pending(_AstakosInit, OptionalOutput):
class commission_info(_AstakosInit, OptionalOutput):
"""Get commission info (special privileges required)"""
......@@ -475,7 +474,7 @@ class commission_info(_AstakosInit, OptionalOutput):
class commission_accept(_AstakosInit):
"""Accept a pending commission (special privileges required)"""
......@@ -490,7 +489,7 @@ class commission_accept(_AstakosInit):
class commission_reject(_AstakosInit):
"""Reject a pending commission (special privileges required)"""
......@@ -505,7 +504,7 @@ class commission_reject(_AstakosInit):
class commission_resolve(_AstakosInit, OptionalOutput):
"""Resolve multiple commissions (special privileges required)"""
......@@ -532,7 +531,7 @@ class commission_resolve(_AstakosInit, OptionalOutput):
class commission_issue(_AstakosInit, OptionalOutput):
"""Issue commissions as a json string (special privileges required)
......@@ -560,7 +559,7 @@ class commission_issue(_AstakosInit, OptionalOutput):
self._run(user_uuid, source, provisions_file, name)
class resource_list(_AstakosInit, OptionalOutput):
"""List user resources"""
......@@ -574,7 +573,7 @@ class resource_list(_AstakosInit, OptionalOutput):
class endpoint_list(_AstakosInit, OptionalOutput, NameFilter):
"""Get endpoints service endpoints"""
......@@ -623,7 +622,7 @@ def apply_notification(func):
return wrap
class project_list(_AstakosInit, OptionalOutput):
"""List all projects"""
......@@ -651,7 +650,7 @@ class project_list(_AstakosInit, OptionalOutput):
class project_info(_AstakosInit, OptionalOutput):
"""Get details for a project"""
......@@ -719,7 +718,7 @@ class ProjectResourceArgument(KeyValueArgument):
class project_create(_AstakosInit, OptionalOutput):
"""Apply for a new project"""
......@@ -788,7 +787,7 @@ class project_create(_AstakosInit, OptionalOutput):
class project_modify(_AstakosInit, OptionalOutput):
"""Modify properties of a project"""
......@@ -880,25 +879,25 @@ class _ProjectAction(_AstakosInit):
self._run(project_id, self['reason'] or '')
class project_suspend(_ProjectAction):
"""Suspend a project (special privileges needed)"""
action = 'suspend'
class project_unsuspend(_ProjectAction):
"""Resume a suspended project (special privileges needed)"""
action = 'unsuspend'
class project_terminate(_ProjectAction):
"""Terminate a project (special privileges needed)"""
action = 'terminate'
class project_reinstate(_ProjectAction):
"""Reinstate a terminated project (special privileges needed)"""
action = 'reinstate'
......@@ -925,36 +924,36 @@ class _ApplicationAction(_AstakosInit):
self._run(project_id, self['app_id'], self['reason'] or '')
class project_approve(_ApplicationAction):
"""Approve an application (special privileges needed)"""
action = 'approve'
class project_deny(_ApplicationAction):
"""Deny an application (special privileges needed)"""
action = 'deny'
class project_dismiss(_ApplicationAction):
"""Dismiss your denied application"""
action = 'dismiss'
class project_cancel(_ApplicationAction):
"""Cancel your application"""
action = 'cancel'
class membership(_AstakosInit):
"""Project membership management commands"""
class membership_list(_AstakosInit, OptionalOutput):
"""List all memberships"""
......@@ -972,7 +971,7 @@ class membership_list(_AstakosInit, OptionalOutput):
class membership_info(_AstakosInit, OptionalOutput):
"""Details on a membership"""
......@@ -1003,37 +1002,37 @@ class _MembershipAction(_AstakosInit, OptionalOutput):
self._run(membership_id, self['reason'] or '')
class membership_leave(_MembershipAction):
"""Leave a project you have membership to"""
action = 'leave'
class membership_cancel(_MembershipAction):
"""Cancel your (probably pending) membership to a project"""
action = 'cancel'
class membership_accept(_MembershipAction):
"""Accept a membership for a project you manage"""
action = 'accept'
class membership_reject(_MembershipAction):
"""Reject a membership for a project you manage"""
action = 'reject'
class membership_remove(_MembershipAction):
"""Remove a membership for a project you manage"""
action = 'remove'
class project_join(_AstakosInit):
"""Join a project"""
......@@ -1047,7 +1046,7 @@ class project_join(_AstakosInit):
class project_enroll(_AstakosInit):
"""Enroll a user to a project"""
......@@ -38,7 +38,7 @@ from kamaki.cli.cmdtree import CommandTree
from kamaki.cli.errors import CLIError, CLISyntaxError
config_cmds = CommandTree('config', 'Kamaki configurations')
_commands = [config_cmds]
namespaces = [config_cmds, ]
about_options = '\nAbout options:\
\n. syntax: [group.]option\
......@@ -52,7 +52,7 @@ from kamaki.cli.cmds import (
server_cmds = CommandTree('server', 'Cyclades/Compute API server commands')
flavor_cmds = CommandTree('flavor', 'Cyclades/Compute API flavor commands')
_commands = [server_cmds, flavor_cmds]
namespaces = [server_cmds, flavor_cmds]
about_authentication = '\nUser Authentication:\
......@@ -39,7 +39,7 @@ from kamaki.cli.cmds import CommandInit, errors
history_cmds = CommandTree('history', 'Kamaki command history')
_commands = [history_cmds]
namespaces = [history_cmds]
class _HistoryInit(CommandInit):
......@@ -55,7 +55,7 @@ from kamaki.cli.cmds import (
image_cmds = CommandTree('image', 'Cyclades/Plankton API image commands')
imagecompute_cmds = CommandTree(
'imagecompute', 'Cyclades/Compute API image commands')
_commands = [image_cmds, imagecompute_cmds]
namespaces = [image_cmds, imagecompute_cmds]
howto_image_file = [
......@@ -51,7 +51,7 @@ network_cmds = CommandTree('network', 'Network API network commands')
port_cmds = CommandTree('port', 'Network API port commands')
subnet_cmds = CommandTree('subnet', 'Network API subnet commands')
ip_cmds = CommandTree('ip', 'Network API floatingip commands')
_commands = [network_cmds, port_cmds, subnet_cmds, ip_cmds]
namespaces = [network_cmds, port_cmds, subnet_cmds, ip_cmds]
about_authentication = '\nUser Authentication:\
......@@ -58,7 +58,7 @@ container_cmds = CommandTree(
'container', 'Pithos+/Storage container level API commands')
sharer_cmds = CommandTree('sharer', 'Pithos+/Storage sharers')
group_cmds = CommandTree('group', 'Pithos+/Storage user groups')
_commands = [file_cmds, container_cmds, sharer_cmds, group_cmds]
namespaces = [file_cmds, container_cmds, sharer_cmds, group_cmds]
class _PithosInit(CommandInit):
......@@ -71,7 +71,7 @@ def run(cloud, parser, _help):
_cnf = parser.arguments['config']
group_spec = _cnf.get('global', '%s_cli' % group)
spec_module = _load_spec_module(group_spec, parser.arguments, '_commands')
spec_module = _load_spec_module(group_spec, parser.arguments, 'namespaces')
if spec_module is None:
raise CLIUnknownCommand(
'Could not find specs for %s commands' % group,
......@@ -79,7 +79,7 @@ def run(cloud, parser, _help):
'Make sure %s is a valid command group' % group,
'Refer to kamaki documentation for setting custom command',
'groups or overide existing ones'])
cmd_tree = _get_cmd_tree_from_spec(group, spec_module._commands)
cmd_tree = _get_cmd_tree_from_spec(group, spec_module.namespaces)
if _best_match:
cmd = cmd_tree.get_command('_'.join(_best_match))
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