Commit 35129620 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Rename kamaki.cli.cmds.errors classes (uniformity)

Renames:
generic --> Generic
user --> Astakos
history --> History
cyclades --> Cyclades
image --> Image
pithos --> Pithos

Rational: each command specification can feature a class of error
handling methods, which can be shared with other specs, if the
later need to borrow the same behavior

Also, new names conform with pep8 suggestions for class names
parent 63786c4a
......@@ -90,9 +90,9 @@ def with_temp_token(func):
class _AstakosInit(CommandInit):
@errors.generic.all
@errors.user.load
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.load
@errors.Astakos.astakosclient
@addLogSettings
def _run(self):
if getattr(self, 'cloud', None):
......@@ -119,9 +119,9 @@ class _AstakosInit(CommandInit):
class user_authenticate(_AstakosInit, OptionalOutput):
"""Authenticate a user and get all authentication information"""
@errors.generic.all
@errors.user.authenticate
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.authenticate
@errors.Astakos.astakosclient
@with_temp_token
def _run(self):
self._print(self.client.authenticate(), self.print_dict)
......@@ -135,8 +135,8 @@ class user_authenticate(_AstakosInit, OptionalOutput):
class user_uuid2name(_AstakosInit, OptionalOutput):
"""Get user name(s) from uuid(s)"""
#@errors.generic.all
#@errors.user.astakosclient
#@errors.Generic.all
#@errors.Astakos.astakosclient
def _run(self, uuids):
r = self.client.get_usernames(uuids)
self._print(r, self.print_dict)
......@@ -153,8 +153,8 @@ class user_uuid2name(_AstakosInit, OptionalOutput):
class user_name2uuid(_AstakosInit, OptionalOutput):
"""Get user uuid(s) from name(s)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, usernames):
r = self.client.get_uuids(usernames)
self._print(r, self.print_dict)
......@@ -186,8 +186,8 @@ class quota_list(_AstakosInit, OptionalOutput):
[(k, format_size(v)) for k, v in resources[r].items()])
self.print_dict(quotas, *args, **kwargs)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
quotas = self.client.get_quotas()
if self['project_id']:
......@@ -229,8 +229,8 @@ class user_info(_AstakosInit, OptionalOutput):
name=ValueArgument('Query user with username/email', '--username')
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
if self['uuid'] and self['name']:
raise CLISyntaxError(
......@@ -256,8 +256,8 @@ class user_info(_AstakosInit, OptionalOutput):
class user_add(_AstakosInit, OptionalOutput):
"""Authenticate a user by token and add to kamaki session (cache)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, token=None):
ask = token and token not in self.auth_base._uuids
self._print(self.auth_base.authenticate(token), self.print_dict)
......@@ -284,8 +284,8 @@ class user_list(_AstakosInit, OptionalOutput):
detail=FlagArgument('Detailed listing', ('-l', '--detail'))
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print([u if self['detail'] else (dict(
id=u['id'], name=u['name'])) for u in self.auth_base.list_users()])
......@@ -299,8 +299,8 @@ class user_list(_AstakosInit, OptionalOutput):
class user_select(_AstakosInit):
"""Select a user from the (cached) list as the current session user"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, uuid):
try:
first_token = self.auth_base.get_token(uuid)
......@@ -338,8 +338,8 @@ class user_select(_AstakosInit):
class user_delete(_AstakosInit):
"""Delete a user (token) from the (cached) list of session users"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, uuid):
if uuid == self.auth_base.user_term('id'):
raise CLIError('Cannot remove current session user', details=[
......@@ -376,8 +376,8 @@ class user_delete(_AstakosInit):
class service_list(_AstakosInit, OptionalOutput):
"""List available services"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_services())
......@@ -390,8 +390,8 @@ class service_list(_AstakosInit, OptionalOutput):
class service_uuid2username(_AstakosInit, OptionalOutput):
"""Get service username(s) from uuid(s)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
@with_temp_token
def _run(self, uuids):
if 1 == len(uuids):
......@@ -410,8 +410,8 @@ class service_uuid2username(_AstakosInit, OptionalOutput):
class service_username2uuid(_AstakosInit, OptionalOutput):
"""Get service uuid(s) from username(s)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
@with_temp_token
def _run(self, usernames):
if 1 == len(usernames):
......@@ -434,8 +434,8 @@ class service_quotas(_AstakosInit, OptionalOutput):
uuid=ValueArgument('A user uuid to get quotas for', '--uuid')
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
@with_temp_token
def _run(self):
self._print(self.client.service_get_quotas(self['uuid']))
......@@ -449,8 +449,8 @@ class service_quotas(_AstakosInit, OptionalOutput):
class commission_pending(_AstakosInit, OptionalOutput):
"""List pending commissions (special privileges required)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_pending_commissions())
......@@ -463,8 +463,8 @@ class commission_pending(_AstakosInit, OptionalOutput):
class commission_info(_AstakosInit, OptionalOutput):
"""Get commission info (special privileges required)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, commission_id):
commission_id = int(commission_id)
self._print(
......@@ -479,8 +479,8 @@ class commission_info(_AstakosInit, OptionalOutput):
class commission_accept(_AstakosInit):
"""Accept a pending commission (special privileges required)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, commission_id):
commission_id = int(commission_id)
self.client.accept_commission(commission_id)
......@@ -494,8 +494,8 @@ class commission_accept(_AstakosInit):
class commission_reject(_AstakosInit):
"""Reject a pending commission (special privileges required)"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, commission_id):
commission_id = int(commission_id)
self.client.reject_commission(commission_id)
......@@ -518,8 +518,8 @@ class commission_resolve(_AstakosInit, OptionalOutput):
'--reject')
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self.writeln('accepted ', self['accept'])
self.writeln('rejected ', self['reject'])
......@@ -547,8 +547,8 @@ class commission_issue(_AstakosInit, OptionalOutput):
accept=FlagArgument('Do not wait for verification', '--accept')
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, holder, source, provisions, name=''):
provisions = loads(provisions)
self._print(self.client.issue_one_commission(
......@@ -564,8 +564,8 @@ class commission_issue(_AstakosInit, OptionalOutput):
class resource_list(_AstakosInit, OptionalOutput):
"""List user resources"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_resources(), self.print_dict)
......@@ -580,8 +580,8 @@ class endpoint_list(_AstakosInit, OptionalOutput, NameFilter):
arguments = dict(endpoint_type=ValueArgument('Filter by type', '--type'))
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
r = self.client.get_endpoints()['access']['serviceCatalog']
r = self._filter_by_name(r)
......@@ -634,8 +634,8 @@ class project_list(_AstakosInit, OptionalOutput):
owner=ValueArgument('Filter by owner', ('--with-owner', ))
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
r = self.client.get_projects(
self['name'], self['state'], self['owner'])
......@@ -655,8 +655,8 @@ class project_list(_AstakosInit, OptionalOutput):
class project_info(_AstakosInit, OptionalOutput):
"""Get details for a project"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id):
self._print(
self.client.get_project(project_id), self.print_dict)
......@@ -751,8 +751,8 @@ class project_create(_AstakosInit, OptionalOutput):
)
required = ['specs_path', 'project_name', 'end_date']
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
@apply_notification
def _run(self):
specs = dict()
......@@ -823,8 +823,8 @@ class project_modify(_AstakosInit, OptionalOutput):
'private', 'project_name', 'start_date', 'end_date', 'join_policy',
'leave_policy', 'resource_capacities', 'max_members']
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
@apply_notification
def _run(self, project_id):
specs = dict()
......@@ -870,8 +870,8 @@ class _ProjectAction(_AstakosInit):
reason=ValueArgument('Quote a reason for this action', '--reason'),
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id, quote_a_reason):
self.client.project_action(project_id, self.action, quote_a_reason)
......@@ -914,8 +914,8 @@ class _ApplicationAction(_AstakosInit):
)
required = ('app_id', )
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id, app_id, quote_a_reason):
self.client.application_action(
project_id, app_id, self.action, quote_a_reason)
......@@ -962,8 +962,8 @@ class membership_list(_AstakosInit, OptionalOutput):
project=ValueArgument('Filter by project id', '--project-id')
)
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_memberships(self['project']))
......@@ -976,8 +976,8 @@ class membership_list(_AstakosInit, OptionalOutput):
class membership_info(_AstakosInit, OptionalOutput):
"""Details on a membership"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, memb_id):
self._print(
self.client.get_membership(memb_id), self.print_dict)
......@@ -992,8 +992,8 @@ class _MembershipAction(_AstakosInit, OptionalOutput):
action = ''
arguments = dict(reason=ValueArgument('Reason for the action', '--reason'))
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, memb_id, quote_a_reason):
self._print(self.client.membership_action(
memb_id, self.action, quote_a_reason))
......@@ -1037,8 +1037,8 @@ class membership_remove(_MembershipAction):
class project_join(_AstakosInit):
"""Join a project"""
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id):
self.writeln(self.client.join_project(project_id))
......@@ -1054,8 +1054,8 @@ class project_enroll(_AstakosInit):
arguments = dict(email=ValueArgument('User e-mail', '--email'))
required = ('email', )
@errors.generic.all
@errors.user.astakosclient
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id, email):
self.writeln(self.client.enroll_member(project_id, email))
......
......@@ -67,7 +67,7 @@ class config_list(CommandInit):
A: Default options remain if not explicitly replaced or deleted
"""
@errors.generic.all
@errors.Generic.all
def _run(self):
for section in sorted(self.config.sections()):
items = self.config.items(section)
......@@ -89,7 +89,7 @@ class config_get(CommandInit):
__doc__ += about_options
@errors.generic.all
@errors.Generic.all
def _run(self, option):
section, sep, key = option.rpartition('.')
if not sep:
......@@ -123,7 +123,7 @@ class config_set(CommandInit):
__doc__ += about_options
@errors.generic.all
@errors.Generic.all
def _run(self, option, value):
section, sep, key = option.rpartition('.')
prefix = 'cloud.'
......@@ -164,7 +164,7 @@ class config_delete(CommandInit):
'--default')
)
@errors.generic.all
@errors.Generic.all
def _run(self, option):
section, sep, key = option.rpartition('.')
section = section or 'global'
......
......@@ -83,7 +83,7 @@ class _ServerWait(Wait):
class _CycladesInit(CommandInit):
@errors.generic.all
@errors.Generic.all
@addLogSettings
def _run(self):
self.client = self.get_client(CycladesClient, 'cyclades')
......@@ -193,9 +193,9 @@ class server_list(_CycladesInit, OptionalOutput, NameFilter, IDFilter):
new_servers.append(srv)
return new_servers
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.date
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.date
def _run(self):
withimage = bool(self['image_id'])
withflavor = bool(self['flavor_id'])
......@@ -255,9 +255,9 @@ class server_info(_CycladesInit, OptionalOutput):
diagnostics=FlagArgument('Diagnostic information', '--diagnostics')
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
if self['nics']:
self._print(
......@@ -428,7 +428,7 @@ class server_create(_CycladesInit, OptionalOutput, _ServerWait):
)
required = ('server_name', 'flavor_id', 'image_id')
@errors.cyclades.cluster_size
@errors.Cyclades.cluster_size
def _create_cluster(self, prefix, flavor_id, image_id, size, project=None):
networks = self['network_configuration'] or (
[] if self['no_network'] else None)
......@@ -463,10 +463,10 @@ class server_create(_CycladesInit, OptionalOutput, _ServerWait):
finally:
raise e
@errors.generic.all
@errors.cyclades.connection
@errors.plankton.id
@errors.cyclades.flavor_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Image.id
@errors.Cyclades.flavor_id
def _run(self, name, flavor_id, image_id):
for r in self._create_cluster(
name, flavor_id, image_id, size=self['cluster_size'] or 1,
......@@ -578,9 +578,9 @@ class server_modify(_CycladesInit):
profile=self['firewall_profile'],
port_id=port['id'])
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
if self['server_name'] is not None:
self.client.update_server_name((server_id), self['server_name'])
......@@ -592,7 +592,7 @@ class server_modify(_CycladesInit):
self.client.update_server_metadata(
server_id, **self['metadata_to_set'])
for key in (self['metadata_to_delete'] or []):
errors.cyclades.metadata(
errors.Cyclades.metadata(
self.client.delete_server_metadata)(server_id, key=key)
def main(self, server_id):
......@@ -615,9 +615,9 @@ class server_reassign(_CycladesInit, OptionalOutput):
)
required = ('project_id', )
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id, project):
self.client.reassign_server(server_id, project)
......@@ -643,14 +643,14 @@ class server_delete(_CycladesInit, _ServerWait):
return [s['id'] for s in self.client.list_servers() if (
s['name'].startswith(server_var))]
@errors.cyclades.server_id
@errors.Cyclades.server_id
def _check_server_id(self, server_id):
return server_id
return [_check_server_id(self, server_id=server_var), ]
@errors.generic.all
@errors.cyclades.connection
@errors.Generic.all
@errors.Cyclades.connection
def _run(self, server_var):
for server_id in self._server_ids(server_var):
if self['wait']:
......@@ -677,9 +677,9 @@ class server_reboot(_CycladesInit, _ServerWait):
wait=FlagArgument('Wait server to be destroyed', ('-w', '--wait'))
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
hard_reboot = self['hard']
if hard_reboot:
......@@ -714,9 +714,9 @@ class server_start(_CycladesInit, _ServerWait):
wait=FlagArgument('Wait server to be destroyed', ('-w', '--wait'))
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
status = 'ACTIVE'
if self['wait']:
......@@ -742,9 +742,9 @@ class server_shutdown(_CycladesInit, _ServerWait):
wait=FlagArgument('Wait server to be destroyed', ('-w', '--wait'))
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
status = 'STOPPED'
if self['wait']:
......@@ -766,9 +766,9 @@ class server_shutdown(_CycladesInit, _ServerWait):
class server_console(_CycladesInit, OptionalOutput):
"""Create a VMC console and show connection information"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id):
self.error('The following credentials will be invalidated shortly')
self._print(
......@@ -793,9 +793,9 @@ class server_wait(_CycladesInit, _ServerWait):
valid_states=server_states)
)
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id, current_status):
r = self.client.get_server_details(server_id)
if r['status'].lower() == current_status.lower():
......@@ -845,8 +845,8 @@ class flavor_list(_CycladesInit, OptionalOutput, NameFilter, IDFilter):
common_filters['SNF:disk_template'] = self['disk_template']
return filter_dicts_by_dict(flavors, common_filters)
@errors.generic.all
@errors.cyclades.connection
@errors.Generic.all
@errors.Cyclades.connection
def _run(self):
withcommons = self['ram'] or self['vcpus'] or (
self['disk'] or self['disk_template'])
......@@ -881,9 +881,9 @@ class flavor_info(_CycladesInit, OptionalOutput):
To get a list of available flavors and flavor ids, try /flavor list
"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.flavor_id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.flavor_id
def _run(self, flavor_id):
self._print(
self.client.get_flavor_details(int(flavor_id)), self.print_dict)
......
......@@ -42,7 +42,7 @@ from kamaki.cli.utils import format_size
CLOUDNAME = ['Note: Set a cloud and use its name instead of "default"']
class generic(object):
class Generic(object):
@classmethod
def all(this, func):
......@@ -103,7 +103,7 @@ class generic(object):
return _raise
class user(object):
class Astakos(object):
_token_details = [
'To check default token: /config get cloud.default.token',
......@@ -163,7 +163,7 @@ class user(object):
return _raise
class history(object):
class History(object):
@classmethod
def init(this, func):
def _raise(self, *args, **kwargs):
......@@ -184,7 +184,7 @@ class history(object):
return _raise
class cyclades(object):
class Cyclades(object):
about_flavor_id = [
'How to pick a valid flavor id:',
' # get a list of flavor ids',
......@@ -207,7 +207,7 @@ class cyclades(object):
@classmethod
def connection(this, func):