Skip to content

Commit

Permalink
cps-tools: improvements in commands and output messages
Browse files Browse the repository at this point in the history
- reordered the commands of each service in a more logical manner, with help always the last command;
- storage volume commands appear only for the generic service (the only one that supports them at the moment);
- renamed 'get_config' to 'get_php_config' to better illustrate its purpose;
- improved command explanations and output messages.
  • Loading branch information
tcrivat committed Jul 19, 2016
1 parent 50a4bcd commit c58f9bc
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 67 deletions.
4 changes: 2 additions & 2 deletions cps-tools/src/cps_tools/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def check_application(client, appl_name_or_id):
app_ids = [appl['aid'] for appl in apps]

if not apps:
raise Exception('No existing applications')
raise Exception('No existing applications.')

if appl_name_or_id is None:
return (None, None)
Expand Down Expand Up @@ -105,7 +105,7 @@ def list_appl(self, _args):
if apps:
print(self.client.prettytable(('aid', 'name', 'manager', 'cloud', 'status'), apps))
else:
print "No existing applications"
print "No existing applications."

# ========== rename
def _add_rename(self):
Expand Down
31 changes: 18 additions & 13 deletions cps-tools/src/cps_tools/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, generic_parser, client):
ServiceCmd.__init__(self, generic_parser, client, "generic",
[('count', 1)], # (role name, default number)
"Generic service sub-commands help")
self._add_create_volume() # defined in base class (ServiceCmd)
self._add_delete_volume() # defined in base class (ServiceCmd)
self._add_list_volumes() # defined in base class (ServiceCmd)
self._add_upload_key()
self._add_list_keys()
self._add_upload_code()
Expand All @@ -27,11 +30,12 @@ def __init__(self, generic_parser, client):
self._add_interrupt()
self._add_cleanup()
self._add_get_script_status()
self._add_help(generic_parser) # defined in base class (ServiceCmd)

# ========== upload_key
def _add_upload_key(self):
subparser = self.add_parser('upload_key',
help="upload key to Generic server")
help="upload an SSH key to a service")
subparser.set_defaults(run_cmd=self.upload_key, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -49,12 +53,12 @@ def upload_key(self, args):
files = [('key', args.filename, contents)]
res = self.client.call_manager_post(app_id, service_id, "/", params, files)

print res['outcome']
print "%s." % res['outcome']

# ========== list_keys
def _add_list_keys(self):
subparser = self.add_parser('list_keys',
help="list authorized keys of Generic service")
help="list the authorized SSH keys of a service")
subparser.set_defaults(run_cmd=self.list_keys, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -66,7 +70,8 @@ def list_keys(self, args):

res = self.client.call_manager_get(app_id, service_id, "list_authorized_keys")

print "%s" % res['authorizedKeys']
for key in res['authorizedKeys']:
print "%s" % key

# ========== upload_code
def _add_upload_code(self):
Expand Down Expand Up @@ -95,7 +100,7 @@ def upload_code(self, args):

res = self.client.call_manager_post(app_id, service_id, "/", params, files)

print "Code version %(codeVersionId)s uploaded" % res
print "Code version '%(codeVersionId)s' uploaded." % res

# ========== list_codes
def _add_list_codes(self):
Expand Down Expand Up @@ -127,7 +132,7 @@ def list_codes(self, args):
# ========== download_code
def _add_download_code(self):
subparser = self.add_parser('download_code',
help="download code from Generic service")
help="download a specific code version")
subparser.set_defaults(run_cmd=self.download_code, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down Expand Up @@ -165,12 +170,12 @@ def check_code_version(self, app_id, service_id, code_version):
if 'current' in code:
return code['filename']

raise Exception("There is no code version currently enabled")
raise Exception("There is no code version currently enabled.")

# ========== enable_code
def _add_enable_code(self):
subparser = self.add_parser('enable_code',
help="set a specific code version active")
help="select the code version to enable")
subparser.set_defaults(run_cmd=self.enable_code, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down Expand Up @@ -215,12 +220,12 @@ def delete_code(self, args):
params = { 'codeVersionId': code_version }
self.client.call_manager_post(app_id, service_id, "delete_code_version", params)

print code_version, 'deleted'
print "Code version '%s' deleted." % code_version

# ========== run
def _add_run(self):
subparser = self.add_parser('run',
help="execute the run.sh script")
help="execute the 'run.sh' script")
subparser.set_defaults(run_cmd=self.run, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -240,7 +245,7 @@ def run(self, args):
# ========== interrupt
def _add_interrupt(self):
subparser = self.add_parser('interrupt',
help="execute the interrupt.sh script")
help="execute the 'interrupt.sh' script")
subparser.set_defaults(run_cmd=self.interrupt, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -261,7 +266,7 @@ def interrupt(self, args):
# ========== cleanup
def _add_cleanup(self):
subparser = self.add_parser('cleanup',
help="execute the cleanup.sh script")
help="execute the 'cleanup.sh' script")
subparser.set_defaults(run_cmd=self.cleanup, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down Expand Up @@ -303,7 +308,7 @@ def get_script_status(self, args):
print " %s\t%s" % (script, status[script])
print
else:
print "No generic agents are running"
print "No generic agents are running."


def main():
Expand Down
3 changes: 2 additions & 1 deletion cps-tools/src/cps_tools/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ def __init__(self, java_parser, client):
WebCmd.__init__(self, java_parser, client, "java",
"Java server sub-commands help")
self._add_enable_code()
self._add_help(java_parser) # defined in base class (ServiceCmd)


# ========== enable_code
def _add_enable_code(self):
subparser = self.add_parser('enable_code',
help="select Java code to enable")
help="select the code version to enable")
subparser.set_defaults(run_cmd=self.enable_code, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down
8 changes: 5 additions & 3 deletions cps-tools/src/cps_tools/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, mysql_parser, client):
# self._add_migrate_nodes()
self._add_dump()
self._add_load_dump()
self._add_help(mysql_parser) # defined in base class (ServiceCmd)

# ========== change_password
def _add_change_pwd(self):
Expand All @@ -46,10 +47,11 @@ def change_pwd(self, args):
print('Passwords do not match. Try again')
pwd1, pwd2 = pprompt()

data = { 'user': 'mysqldb', 'password': pwd1 }
user = 'mysqldb'
data = { 'user': user, 'password': pwd1 }
self.client.call_manager_post(app_id, service_id, "set_password", data)

print("MySQL password updated successfully.")
print("MySQL password successfully updated for user '%s'." % user)

# ========== migrate_nodes
def _add_migrate_nodes(self):
Expand Down Expand Up @@ -131,7 +133,7 @@ def load_dump(self, args):

self.client.call_manager_post(app_id, service_id, "/", params, files)

print "MySQL dump loaded successfully."
print "MySQL dump '%s' loaded successfully." % args.filename

def main():
logger = logging.getLogger(__name__)
Expand Down
21 changes: 11 additions & 10 deletions cps-tools/src/cps_tools/php.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ def __init__(self, php_parser, client):
WebCmd.__init__(self, php_parser, client, "php",
"PHP server sub-commands help")
self._add_enable_code()
self._add_get_config()
self._add_get_php_config()
self._add_debug()
# self._add_enable_autoscaling()
# self._add_disable_autoscaling()
self._add_help(php_parser) # defined in base class (ServiceCmd)


# ========== enable_code
def _add_enable_code(self):
subparser = self.add_parser('enable_code',
help="select PHP code to enable")
help="select the code version to enable")
subparser.set_defaults(run_cmd=self.enable_code, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -53,17 +54,17 @@ def enable_code(self, args):
else:
print "FAILED!"

# ========== get_config
def _add_get_config(self):
subparser = self.add_parser('get_config',
help="return the PHP configuration")
subparser.set_defaults(run_cmd=self.get_config, parser=subparser)
# ========== get_php_config
def _add_get_php_config(self):
subparser = self.add_parser('get_php_config',
help="get the PHP server's configuration")
subparser.set_defaults(run_cmd=self.get_php_config, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
subparser.add_argument('serv_name_or_id',
help="Name or identifier of a service")

def get_config(self, args):
def get_php_config(self, args):
app_id, service_id = self.check_service(args.app_name_or_id, args.serv_name_or_id)

conf = self.client.call_manager_get(app_id, service_id, 'get_configuration')
Expand All @@ -79,7 +80,7 @@ def get_config(self, args):
# ========== debug
def _add_debug(self):
subparser = self.add_parser('debug',
help="enable or disable debug mode")
help="enable or disable PHP server's debug mode")
subparser.set_defaults(run_cmd=self.debug, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -102,7 +103,7 @@ def debug(self, args):
"update_php_configuration",
params)

print("Debug mode set to %s." % args.on_off)
print("Debug mode set to '%s'." % debug_mode)

# ========== enable_autoscaling
def _add_enable_autoscaling(self):
Expand Down
17 changes: 8 additions & 9 deletions cps-tools/src/cps_tools/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, serv_parser, client, service_type=None, roles=None,
metavar="<sub-command>")
if service_type is not None:
serv_parser.set_defaults(service_type=service_type)
self._add_get_types()
if not self.type:
self._add_get_types()
self._add_add()
self._add_remove()
self._add_list()
Expand All @@ -46,10 +47,8 @@ def __init__(self, serv_parser, client, service_type=None, roles=None,
self._add_add_nodes()
self._add_remove_nodes()
self._add_list_nodes()
self._add_create_volume()
self._add_delete_volume()
self._add_list_volumes()
self._add_help(serv_parser)
if not self.type:
self._add_help(serv_parser)

def add_parser(self, *args, **kwargs):
return self.subparsers.add_parser(*args, **kwargs)
Expand Down Expand Up @@ -172,11 +171,11 @@ def list_serv(self, args):
if table:
print "%s" % table
else:
print "No existing services"
print "No existing services."

# ========== start
def _add_start(self):
subparser = self.add_parser('start', help="start a service from the app manager")
subparser = self.add_parser('start', help="start a service")
subparser.set_defaults(run_cmd=self.start_serv, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down Expand Up @@ -399,7 +398,7 @@ def list_nodes(self, args):

print(self.client.prettytable(('aid', 'sid', 'role', 'ip', 'agent_id', 'cloud'), sorted_nodes))
else:
print "No existing nodes"
print "No existing nodes."

def _get_roles_nb(self, args=None): # if args is None we use the defaults
total_nodes = 0
Expand Down Expand Up @@ -559,7 +558,7 @@ def list_volumes(self, args):

print(self.client.prettytable(('aid', 'sid', 'vol_name', 'vol_size', 'agent_id', 'cloud'), sorted_vols))
else:
print "No existing storage volumes"
print "No existing storage volumes."

# ========== delete_volume
def _add_delete_volume(self):
Expand Down
17 changes: 9 additions & 8 deletions cps-tools/src/cps_tools/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, web_parser, client, service_type="web",
# ========== upload_key
def _add_upload_key(self):
subparser = self.add_parser('upload_key',
help="upload key to Web server")
help="upload an SSH key to a service")
subparser.set_defaults(run_cmd=self.upload_key, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -40,12 +40,12 @@ def upload_key(self, args):
files = [('key', args.filename, contents)]
res = self.client.call_manager_post(app_id, service_id, "/", params, files)

print res['outcome']
print "%s." % res['outcome']

# ========== list_keys
def _add_list_keys(self):
subparser = self.add_parser('list_keys',
help="list authorized keys of Web service")
help="list the authorized SSH keys of a service")
subparser.set_defaults(run_cmd=self.list_keys, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand All @@ -57,7 +57,8 @@ def list_keys(self, args):

res = self.client.call_manager_get(app_id, service_id, "list_authorized_keys")

print "%s" % res['authorizedKeys']
for key in res['authorizedKeys']:
print "%s" % key

# ========== upload_code
def _add_upload_code(self):
Expand All @@ -80,7 +81,7 @@ def upload_code(self, args):
files = [('code', args.filename, contents)]
res = self.client.call_manager_post(app_id, service_id, "/", params, files)

print "Code version %(codeVersionId)s uploaded" % res
print "Code version '%(codeVersionId)s' uploaded." % res

# ========== list_codes
def _add_list_codes(self):
Expand Down Expand Up @@ -112,7 +113,7 @@ def list_codes(self, args):
# ========== download_code
def _add_download_code(self):
subparser = self.add_parser('download_code',
help="download code from Web server")
help="download a specific code version")
subparser.set_defaults(run_cmd=self.download_code, parser=subparser)
subparser.add_argument('app_name_or_id',
help="Name or identifier of an application")
Expand Down Expand Up @@ -150,7 +151,7 @@ def check_code_version(self, app_id, service_id, code_version):
if 'current' in code:
return code['filename']

raise Exception("There is no code version currently enabled")
raise Exception("There is no code version currently enabled.")

# ========== delete_code
def _add_delete_code(self):
Expand All @@ -171,7 +172,7 @@ def delete_code(self, args):
params = { 'codeVersionId': code_version }
self.client.call_manager_post(app_id, service_id, "delete_code_version", params)

print code_version, 'deleted'
print "Code version '%s' deleted." % code_version

# ========== migrate_nodes
def _add_migrate_nodes(self):
Expand Down
Loading

0 comments on commit c58f9bc

Please sign in to comment.