Commit 35129620 authored by Stavros Sachtouris's avatar Stavros Sachtouris

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
This diff is collapsed.
......@@ -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):
return generic._connection(func)
return Generic._connection(func)
@classmethod
def date(this, func):
......@@ -391,8 +391,7 @@ class cyclades(object):
return _raise
class plankton(object):
class Image(object):
about_image_id = [
'How to pick a suitable image:',
' # get a list of image ids',
......@@ -404,7 +403,7 @@ class plankton(object):
@classmethod
def connection(this, func):
return generic._connection(func)
return Generic._connection(func)
@classmethod
def id(this, func):
......@@ -438,7 +437,7 @@ class plankton(object):
return _raise
class pithos(object):
class Pithos(object):
container_howto = [
'Use a / to refer to a container (default: /pithos) e.g.,',
' # list the contents of container "images"',
......@@ -453,7 +452,7 @@ class pithos(object):
@classmethod
def connection(this, func):
return generic._connection(func)
return Generic._connection(func)
@classmethod
def account(this, func):
......
......@@ -43,8 +43,8 @@ _commands = [history_cmds]
class _init_history(CommandInit):
@errors.generic.all
@errors.history.init
@errors.Generic.all
@errors.History.init
def _run(self):
self.history = History(self.config.get('global', 'history_file'))
self.history.limit = self.config.get('global', 'history_limit')
......@@ -65,7 +65,7 @@ class history_show(_init_history):
match=ValueArgument('Show lines matching this', '--match'),
)
@errors.generic.all
@errors.Generic.all
def _run(self, cmd_slice):
c = self.history.counter
lines = ['%s.\t%s' % (i + c, l) for i, l in enumerate(
......@@ -89,7 +89,7 @@ class history_show(_init_history):
class history_clean(_init_history):
"""Clean up history (permanent)"""
@errors.generic.all
@errors.Generic.all
def _run(self):
self.history.empty()
......
......@@ -75,7 +75,7 @@ log = getLogger(__name__)
class _init_image(CommandInit):
@errors.generic.all
@errors.Generic.all
@addLogSettings
def _run(self):
self.client = self.get_client(ImageClient, 'plankton')
......@@ -225,8 +225,8 @@ class image_list(_init_image, OptionalOutput, NameFilter, IDFilter):
member['member_id'] += ' (%s)' % usernames[member['member_id']]
self._print(members, title=('member_id',))
@errors.generic.all
@errors.cyclades.connection
@errors.Generic.all
@errors.Cyclades.connection
def _run(self):
super(self.__class__, self)._run()
if self['image_ID_for_members']:
......@@ -280,9 +280,9 @@ class image_list(_init_image, OptionalOutput, NameFilter, IDFilter):
class image_info(_init_image, OptionalOutput):
"""Get image metadata"""
@errors.generic.all
@errors.plankton.connection
@errors.plankton.id
@errors.Generic.all
@errors.Image.connection
@errors.Image.id
def _run(self, image_id):
meta = self.client.get_meta(image_id)
if not self['output_format']:
......@@ -323,9 +323,9 @@ class image_modify(_init_image):
'unpublish', 'property_to_set', 'member_ID_to_add',
'member_ID_to_remove', 'property_to_del']
@errors.generic.all
@errors.plankton.connection
@errors.plankton.id
@errors.Generic.all
@errors.Image.connection
@errors.Image.id
def _run(self, image_id):
for mid in (self['member_ID_to_add'] or []):
self.client.add_member(image_id, mid)
......@@ -509,8 +509,8 @@ class image_register(_init_image, OptionalOutput):
if ce.status != 404:
raise
@errors.generic.all
@errors.plankton.connection
@errors.Generic.all
@errors.Image.connection
def _run(self, name, locator):
location, pithos = locator.value, None
if self['local_image_path']:
......@@ -606,9 +606,9 @@ class image_register(_init_image, OptionalOutput):
class image_unregister(_init_image):
"""Unregister an image (does not delete the image file)"""
@errors.generic.all
@errors.plankton.connection
@errors.plankton.id
@errors.Generic.all
@errors.Image.connection
@errors.Image.id
def _run(self, image_id):
self.client.unregister(image_id)
......@@ -663,8 +663,8 @@ class imagecompute_list(_CycladesInit, OptionalOutput, NameFilter, IDFilter):
img[key] += ' (%s)' % uuids[img[key]]
return images
@errors.generic.all
@errors.cyclades.connection
@errors.Generic.all
@errors.Cyclades.connection
def _run(self):
withmeta = bool(self['meta'] or self['meta_like'])
withuser = bool(self['user_id'] or self['user_name'])
......@@ -701,9 +701,9 @@ class imagecompute_list(_CycladesInit, OptionalOutput, NameFilter, IDFilter):
class imagecompute_info(_CycladesInit, OptionalOutput):
"""Get detailed information on an image"""
@errors.generic.all
@errors.cyclades.connection
@errors.plankton.id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Image.id
def _run(self, image_id):
image = self.client.get_image_details(image_id)
uuids = [image['user_id']]
......@@ -720,9 +720,9 @@ class imagecompute_info(_CycladesInit, OptionalOutput):
class imagecompute_delete(_CycladesInit):
"""Delete an image (WARNING: image file is also removed)"""
@errors.generic.all
@errors.cyclades.connection
@errors.plankton.id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Image.id
def _run(self, image_id):
self.client.delete_image(image_id)
......@@ -745,9 +745,9 @@ class imagecompute_modify(_CycladesInit):
)
required = ['property_to_add', 'property_to_del']
@errors.generic.all
@errors.cyclades.connection
@errors.plankton.id
@errors.Generic.all
@errors.Cyclades.connection
@errors.Image.id
def _run(self, image_id):
if self['property_to_add']:
self.client.update_image_metadata(
......
This diff is collapsed.
This diff is collapsed.
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