From c58f9bcc5ecc2972599d9b175e1f20393666213f Mon Sep 17 00:00:00 2001 From: tcrivat Date: Tue, 19 Jul 2016 11:52:36 +0200 Subject: [PATCH] cps-tools: improvements in commands and output messages - 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. --- cps-tools/src/cps_tools/application.py | 4 +-- cps-tools/src/cps_tools/generic.py | 31 +++++++++++-------- cps-tools/src/cps_tools/java.py | 3 +- cps-tools/src/cps_tools/mysql.py | 8 +++-- cps-tools/src/cps_tools/php.py | 21 ++++++------- cps-tools/src/cps_tools/service.py | 17 +++++------ cps-tools/src/cps_tools/web.py | 17 ++++++----- cps-tools/src/cps_tools/xtreemfs.py | 41 +++++++++++++------------- 8 files changed, 75 insertions(+), 67 deletions(-) diff --git a/cps-tools/src/cps_tools/application.py b/cps-tools/src/cps_tools/application.py index a1c56c08..f95fb20e 100644 --- a/cps-tools/src/cps_tools/application.py +++ b/cps-tools/src/cps_tools/application.py @@ -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) @@ -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): diff --git a/cps-tools/src/cps_tools/generic.py b/cps-tools/src/cps_tools/generic.py index 8b1d09ad..59e8fc68 100644 --- a/cps-tools/src/cps_tools/generic.py +++ b/cps-tools/src/cps_tools/generic.py @@ -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() @@ -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") @@ -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") @@ -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): @@ -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): @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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(): diff --git a/cps-tools/src/cps_tools/java.py b/cps-tools/src/cps_tools/java.py index 412b26bd..6086e8e5 100644 --- a/cps-tools/src/cps_tools/java.py +++ b/cps-tools/src/cps_tools/java.py @@ -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") diff --git a/cps-tools/src/cps_tools/mysql.py b/cps-tools/src/cps_tools/mysql.py index bfc53f9c..3881b5fb 100644 --- a/cps-tools/src/cps_tools/mysql.py +++ b/cps-tools/src/cps_tools/mysql.py @@ -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): @@ -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): @@ -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__) diff --git a/cps-tools/src/cps_tools/php.py b/cps-tools/src/cps_tools/php.py index 9dd33b8b..1d9d5eb9 100644 --- a/cps-tools/src/cps_tools/php.py +++ b/cps-tools/src/cps_tools/php.py @@ -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") @@ -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') @@ -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") @@ -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): diff --git a/cps-tools/src/cps_tools/service.py b/cps-tools/src/cps_tools/service.py index 393120f2..7b8d5e5a 100644 --- a/cps-tools/src/cps_tools/service.py +++ b/cps-tools/src/cps_tools/service.py @@ -29,7 +29,8 @@ def __init__(self, serv_parser, client, service_type=None, roles=None, metavar="") 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() @@ -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) @@ -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") @@ -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 @@ -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): diff --git a/cps-tools/src/cps_tools/web.py b/cps-tools/src/cps_tools/web.py index 75fb72f2..6c0a84d5 100644 --- a/cps-tools/src/cps_tools/web.py +++ b/cps-tools/src/cps_tools/web.py @@ -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") @@ -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") @@ -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): @@ -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): @@ -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") @@ -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): @@ -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): diff --git a/cps-tools/src/cps_tools/xtreemfs.py b/cps-tools/src/cps_tools/xtreemfs.py index 7fe9ec3c..1d174525 100644 --- a/cps-tools/src/cps_tools/xtreemfs.py +++ b/cps-tools/src/cps_tools/xtreemfs.py @@ -11,14 +11,13 @@ import base64 POLICIES = {'osd_sel': {'list': 'list_osd_sel_policies', - 'set': 'set_osd_sel_policy', - }, + 'set': 'set_osd_sel_policy'}, 'replica_sel': {'list': 'list_replica_sel_policies', - 'set': 'set_replica_sel_policy', - }, + 'set': 'set_replica_sel_policy'}, 'replication': {'list': 'list_replication_policies', - 'set': 'set_replication_policy', - }, + 'set': 'set_replication_policy'}, + 'striping': {'list': 'list_striping_policies', + 'set': 'set_striping_policy'} } @@ -37,11 +36,12 @@ def __init__(self, xtreemfs_parser, client): self._add_set_policy() # self._add_toggle_persistent() self._add_set_osd_size() + self._add_help(xtreemfs_parser) # defined in base class (ServiceCmd) # ========== list_xfs_volumes def _add_list_xfs_volumes(self): subparser = self.add_parser('list_xfs_volumes', - help="list volumes of an XtreemFS service") + help="list XtreemFS volumes") subparser.set_defaults(run_cmd=self.list_xfs_volumes, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -58,7 +58,7 @@ def list_xfs_volumes(self, args): # ========== add_xfs_volume def _add_add_xfs_volume(self): subparser = self.add_parser('add_xfs_volume', - help="add a volume to XtreemFS service") + help="add an XtreemFS volume") subparser.set_defaults(run_cmd=self.add_xfs_volume, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -72,12 +72,12 @@ def add_xfs_volume(self, args): data = {'volumeName': args.volume_name} self.client.call_manager_post(app_id, service_id, "createVolume", data) - print("Volume %s has been added." % args.volume_name) + print("XtreemFS volume '%s' has been successfully added." % args.volume_name) # ========== remove_xfs_volume def _add_remove_xfs_volume(self): subparser = self.add_parser('remove_xfs_volume', - help="remove volume from XtreemFS service") + help="remove an XtreemFS volume") subparser.set_defaults(run_cmd=self.remove_xfs_volume, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -91,8 +91,7 @@ def remove_xfs_volume(self, args): data = {'volumeName': args.volume_name} self.client.call_manager_post(app_id, service_id, "deleteVolume", data) - print("Volume %s has been successfully removed from XtreemFS service %d." - % (args.volume_name, service_id)) + print("XtreemFS volume '%s' has been successfully removed." % args.volume_name) # ========== get_client_cert def _add_get_client_cert(self): @@ -119,8 +118,8 @@ def get_client_cert(self, args): res = self.client.call_manager_post(app_id, service_id, "get_client_cert", data) open(filename, 'wb').write(base64.b64decode(res['cert'])) - print("Client certificate '%s' has been successfully created from XtreemFS service %d." - % (args.filename, service_id)) + print("Client certificate '%s' has been successfully created." + % args.filename) # ========== get_user_cert def _add_get_user_cert(self): @@ -153,13 +152,13 @@ def get_user_cert(self, args): res = self.client.call_manager_post(app_id, service_id, "get_user_cert", data) open(filename, 'wb').write(base64.b64decode(res['cert'])) - print("User certificate '%s' has been successfully created from XtreemFS service %d." - % (args.filename, service_id)) + print("User certificate '%s' has been successfully created." + % args.filename) # ========== list_policies def _add_list_policies(self): subparser = self.add_parser('list_policies', - help="List XtreemFS policies") + help="list XtreemFS policies") subparser.set_defaults(run_cmd=self.list_policies, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -178,7 +177,7 @@ def list_policies(self, args): # ========== set_policy def _add_set_policy(self): subparser = self.add_parser('set_policy', - help="Set an XtreemFS policy") + help="set an XtreemFS policy") subparser.set_defaults(run_cmd=self.set_policy, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -197,7 +196,7 @@ def set_policy(self, args): # ========== toggle_persistent def _add_toggle_persistent(self): subparser = self.add_parser('toggle_persistent', - help="Toggle persistency of an XtreemFS service") + help="toggle persistency of an XtreemFS service") subparser.set_defaults(run_cmd=self.toggle_persistent, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -214,7 +213,7 @@ def toggle_persistent(self, args): # ========== set_osd_size def _add_set_osd_size(self): subparser = self.add_parser('set_osd_size', - help="Set a new size for an XtreemFS volume") + help="set a new size for the storage volume") subparser.set_defaults(run_cmd=self.set_osd_size, parser=subparser) subparser.add_argument('app_name_or_id', help="Name or identifier of an application") @@ -232,7 +231,7 @@ def set_osd_size(self, args): data = {'size': args.volume_size} res = self.client.call_manager_post(app_id, service_id, 'set_osd_size', data) - print "OSD volume size is now %s MBs" % res['osd_volume_size'] + print "OSD volume size is now %s MBs." % res['osd_volume_size'] def main():