Skip to content

Commit

Permalink
Modify member methods in kamaki.cli.cmds classes
Browse files Browse the repository at this point in the history
Refs: grnet#9

Renamed:
kamaki.cli.cmds._optional_json: _print --> print_
kamaki.cli.cmds.cyclades.Wait: _wait --> wait
kamaki.cli.cmds.cyclades.ServerWait: _wait --> wait
kamaki.cli.cmds.image: _load_image_meta --> load_image_meta
kamak.cli.cmds.network: _wait --> wait
kamaki.cli.cmds.pithos.PithosAccount:
    _is_dir --> obj_is_dir
    _resolve_pithos_url --> resolve_pithos_url

Removed:
kamaki.cli.cmds.pithos.PithosAccount:
    _validate_image_meta, _validate_image_location
  • Loading branch information
saxtouri committed May 12, 2014
1 parent c79749f commit f3af64f
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 169 deletions.
4 changes: 2 additions & 2 deletions kamaki/cli/cmds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class OptionalOutput(object):
'--output-format'),
)

def _print(self, output, print_method=print_items, **print_method_kwargs):
def print_(self, output, print_method=print_items, **print_method_kwargs):
if self['output_format']:
func = OutputFormatArgument.formats[self['output_format']]
func(output, out=self)
Expand Down Expand Up @@ -385,7 +385,7 @@ class Wait(object):
'do not show progress bar', ('-N', '--no-progress-bar'), False)
)

def _wait(
def wait(
self, service, service_id, status_method, current_status,
countdown=True, timeout=60):
(progress_bar, wait_cb) = self._safe_progress_bar(
Expand Down
52 changes: 26 additions & 26 deletions kamaki/cli/cmds/astakos.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class user_authenticate(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
@with_temp_token
def _run(self):
self._print(self.client.authenticate(), self.print_dict)
self.print_(self.client.authenticate(), self.print_dict)

def main(self, token=None):
super(self.__class__, self)._run()
Expand All @@ -138,7 +138,7 @@ class user_uuid2name(_AstakosInit, OptionalOutput):
#@errors.Astakos.astakosclient
def _run(self, uuids):
r = self.client.get_usernames(uuids)
self._print(r, self.print_dict)
self.print_(r, self.print_dict)
unresolved = set(uuids).difference(r)
if unresolved:
self.error('Unresolved uuids: %s' % ', '.join(unresolved))
Expand All @@ -156,7 +156,7 @@ class user_name2uuid(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
def _run(self, usernames):
r = self.client.get_uuids(usernames)
self._print(r, self.print_dict)
self.print_(r, self.print_dict)
unresolved = set(usernames).difference(r)
if unresolved:
self.error('Unresolved usernames: %s' % ', '.join(unresolved))
Expand Down Expand Up @@ -209,7 +209,7 @@ def _run(self):
if not d:
raise CLIError('Resource "%s" not found' % self['resource'])
quotas = d
self._print(quotas, self._print_quotas)
self.print_(quotas, self._print_quotas)

def main(self):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -248,7 +248,7 @@ def _run(self):
' /user list',
'To authenticate and add a new user in the session list',
' /user add <new token>'])
self._print(self.auth_base.user_info(token), self.print_dict)
self.print_(self.auth_base.user_info(token), self.print_dict)


@command(user_cmds)
Expand All @@ -259,7 +259,7 @@ class user_add(_AstakosInit, OptionalOutput):
@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)
self.print_(self.auth_base.authenticate(token), self.print_dict)
if ask and self.ask_user(
'Token is temporarily stored in memory. If it is stored in'
' kamaki configuration file, it will be available in later'
Expand All @@ -286,7 +286,7 @@ class user_list(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print([u if self['detail'] else (dict(
self.print_([u if self['detail'] else (dict(
id=u['id'], name=u['name'])) for u in self.auth_base.list_users()])

def main(self):
Expand Down Expand Up @@ -378,7 +378,7 @@ class service_list(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_services())
self.print_(self.client.get_services())

def main(self):
super(self.__class__, self)._run()
Expand All @@ -394,9 +394,9 @@ class service_uuid2username(_AstakosInit, OptionalOutput):
@with_temp_token
def _run(self, uuids):
if 1 == len(uuids):
self._print(self.client.service_get_username(uuids[0]))
self.print_(self.client.service_get_username(uuids[0]))
else:
self._print(
self.print_(
self.client.service_get_usernames(uuids),
self.print_dict)

Expand All @@ -414,9 +414,9 @@ class service_username2uuid(_AstakosInit, OptionalOutput):
@with_temp_token
def _run(self, usernames):
if 1 == len(usernames):
self._print(self.client.service_get_uuid(usernames[0]))
self.print_(self.client.service_get_uuid(usernames[0]))
else:
self._print(
self.print_(
self.client.service_get_uuids(usernames),
self.print_dict)

Expand All @@ -437,7 +437,7 @@ class service_quotas(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
@with_temp_token
def _run(self):
self._print(self.client.service_get_quotas(self['uuid']))
self.print_(self.client.service_get_quotas(self['uuid']))

def main(self, service_token):
super(self.__class__, self)._run()
Expand All @@ -451,7 +451,7 @@ class commission_pending(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_pending_commissions())
self.print_(self.client.get_pending_commissions())

def main(self):
super(self.__class__, self)._run()
Expand All @@ -466,7 +466,7 @@ class commission_info(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
def _run(self, commission_id):
commission_id = int(commission_id)
self._print(
self.print_(
self.client.get_commission_info(commission_id), self.print_dict)

def main(self, commission_id):
Expand Down Expand Up @@ -522,7 +522,7 @@ class commission_resolve(_AstakosInit, OptionalOutput):
def _run(self):
self.writeln('accepted ', self['accept'])
self.writeln('rejected ', self['reject'])
self._print(
self.print_(
self.client.resolve_commissions(self['accept'], self['reject']),
self.print_dict)

Expand Down Expand Up @@ -550,7 +550,7 @@ class commission_issue(_AstakosInit, OptionalOutput):
@errors.Astakos.astakosclient
def _run(self, holder, source, provisions, name=''):
provisions = loads(provisions)
self._print(self.client.issue_one_commission(
self.print_(self.client.issue_one_commission(
holder, source, provisions, name,
self['force'], self['accept']))

Expand All @@ -566,7 +566,7 @@ class resource_list(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_resources(), self.print_dict)
self.print_(self.client.get_resources(), self.print_dict)

def main(self):
super(self.__class__, self)._run()
Expand All @@ -586,7 +586,7 @@ def _run(self):
r = self._filter_by_name(r)
if self['endpoint_type']:
r = filter_dicts_by_dict(r, dict(type=self['endpoint_type']))
self._print(r)
self.print_(r)

def main(self):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -643,7 +643,7 @@ def _run(self):
id=i['id'],
name=i['name'],
description=i['description']) for i in r]
self._print(r)
self.print_(r)

def main(self):
super(self.__class__, self)._run()
Expand All @@ -657,7 +657,7 @@ class project_info(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, project_id):
self._print(
self.print_(
self.client.get_project(project_id), self.print_dict)

def main(self, project_id):
Expand Down Expand Up @@ -772,7 +772,7 @@ def _run(self):
('resources', self['resource_capacities'])):
if arg:
specs[key] = arg
self._print(self.client.create_project(specs), self.print_dict)
self.print_(self.client.create_project(specs), self.print_dict)

def main(self):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -847,7 +847,7 @@ def _run(self, project_id):
if private is not None:
self['private'] = private

self._print(
self.print_(
self.client.modify_project(project_id, specs), self.print_dict)

def main(self, project_id):
Expand Down Expand Up @@ -964,7 +964,7 @@ class membership_list(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self._print(self.client.get_memberships(self['project']))
self.print_(self.client.get_memberships(self['project']))

def main(self):
super(self.__class__, self)._run()
Expand All @@ -978,7 +978,7 @@ class membership_info(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, memb_id):
self._print(
self.print_(
self.client.get_membership(memb_id), self.print_dict)

def main(self, membership_id):
Expand All @@ -994,7 +994,7 @@ class _MembershipAction(_AstakosInit, OptionalOutput):
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self, memb_id, quote_a_reason):
self._print(self.client.membership_action(
self.print_(self.client.membership_action(
memb_id, self.action, quote_a_reason))

def main(self, membership_id):
Expand Down
48 changes: 18 additions & 30 deletions kamaki/cli/cmds/cyclades.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@

class _ServerWait(Wait):

def _wait(self, server_id, current_status, timeout=60):
super(_ServerWait, self)._wait(
def wait(self, server_id, current_status, timeout=60):
super(_ServerWait, self).wait(
'Server', server_id, self.client.wait_server, current_status,
countdown=(current_status not in ('BUILD', )),
timeout=timeout if current_status not in ('BUILD', ) else 100)
Expand Down Expand Up @@ -228,7 +228,7 @@ def _run(self):
kwargs['title'] = ()
if self['limit']:
servers = servers[:self['limit']]
self._print(servers, **kwargs)
self.print_(servers, **kwargs)
if self['more']:
pager(kwargs['out'].getvalue())

Expand All @@ -254,17 +254,16 @@ class server_info(_CycladesInit, OptionalOutput):
@errors.Cyclades.server_id
def _run(self, server_id):
if self['nics']:
self._print(
self.print_(
self.client.get_server_nics(server_id), self.print_dict)
elif self['stats']:
self._print(
self.print_(
self.client.get_server_stats(server_id), self.print_dict)
elif self['diagnostics']:
self._print(self.client.get_server_diagnostics(server_id))
self.print_(self.client.get_server_diagnostics(server_id))
else:
vm = self.client.get_server_details(server_id)
# self._print(self._restruct_server_info(vm), self.print_dict)
self._print(vm, self.print_dict)
self.print_(vm, self.print_dict)

def main(self, server_id):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -450,7 +449,7 @@ def _create_cluster(self, prefix, flavor_id, image_id, size, project=None):
s['name'] in requested_names)]
self.error('Failed to build %s servers' % size)
self.error('Found %s matching servers:' % len(spawned_servers))
self._print(spawned_servers, out=self._err)
self.print_(spawned_servers, out=self._err)
self.error('Check if any of these servers should be removed\n')
except Exception as ne:
self.error('Error (%s) while notifying about errors' % ne)
Expand All @@ -468,10 +467,9 @@ def _run(self, name, flavor_id, image_id):
if not r:
self.error('Create %s: server response was %s' % (name, r))
continue
# self._print(self._restruct_server_info(r), self.print_dict)
self._print(r, self.print_dict)
self.print_(r, self.print_dict)
if self['wait']:
self._wait(r['id'], r['status'] or 'BUILD')
self.wait(r['id'], r['status'] or 'BUILD')
self.writeln(' ')

def main(self):
Expand Down Expand Up @@ -653,7 +651,7 @@ def _run(self, server_var):

self.client.delete_server(server_id)
if self['wait']:
self._wait(server_id, status)
self.wait(server_id, status)

def main(self, server_id_or_cluster_prefix):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -693,7 +691,7 @@ def _run(self, server_id):

self.client.reboot_server(int(server_id), hard_reboot)
if self['wait']:
self._wait(server_id, 'REBOOT')
self.wait(server_id, 'REBOOT')

def main(self, server_id):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -721,7 +719,7 @@ def _run(self, server_id):

self.client.start_server(int(server_id))
if self['wait']:
self._wait(server_id, status)
self.wait(server_id, status)

def main(self, server_id):
super(self.__class__, self)._run()
Expand Down Expand Up @@ -749,7 +747,7 @@ def _run(self, server_id):

self.client.shutdown_server(int(server_id))
if self['wait']:
self._wait(server_id, status)
self.wait(server_id, status)

def main(self, server_id):
super(self.__class__, self)._run()
Expand All @@ -765,7 +763,7 @@ class server_console(_CycladesInit, OptionalOutput):
@errors.Cyclades.server_id
def _run(self, server_id):
self.error('The following credentials will be invalidated shortly')
self._print(
self.print_(
self.client.get_server_console(server_id), self.print_dict)

def main(self, server_id):
Expand Down Expand Up @@ -793,7 +791,7 @@ class server_wait(_CycladesInit, _ServerWait):
def _run(self, server_id, current_status):
r = self.client.get_server_details(server_id)
if r['status'].lower() == current_status.lower():
self._wait(server_id, current_status, timeout=self['timeout'])
self.wait(server_id, current_status, timeout=self['timeout'])
else:
self.error(
'Server %s: Cannot wait for status %s, '
Expand Down Expand Up @@ -857,7 +855,7 @@ def _run(self):
for key in set(flv).difference(self.PERMANENTS):
flv.pop(key)
kwargs = dict(out=StringIO(), title=()) if self['more'] else {}
self._print(
self.print_(
flavors,
with_redundancy=self['detail'], with_enumeration=self['enum'],
**kwargs)
Expand All @@ -879,19 +877,9 @@ class flavor_info(_CycladesInit, OptionalOutput):
@errors.Cyclades.connection
@errors.Cyclades.flavor_id
def _run(self, flavor_id):
self._print(
self.print_(
self.client.get_flavor_details(int(flavor_id)), self.print_dict)

def main(self, flavor_id):
super(self.__class__, self)._run()
self._run(flavor_id=flavor_id)


def _add_name(self, net):
user_id, tenant_id, uuids = net['user_id'], net['tenant_id'], []
if user_id:
uuids.append(user_id)
if uuids or tenant_id:
usernames = self._uuids2usernames(uuids)
if user_id:
net['user_id'] += ' (%s)' % usernames[user_id]
Loading

0 comments on commit f3af64f

Please sign in to comment.