from cloudmesh.shell.clusters import Clusters clusterobj = Clusters() # list clusters # show a group of cluster group = clusterobj.group("deef")
def do_cluster(self, args, arguments): """ :: Usage: cluster list [--format=FORMAT] cluster create <name> [--count=<count>] [--ln=<LoginName>] [--cloud=<CloudName>] [--image=<imgName>|--imageid=<imgId>] [--flavor=<flavorName>|--flavorid=<flavorId>] [--force] cluster show <name> [--format=FORMAT] [--column=COLUMN] [--detail] cluster remove <name> [--grouponly] Description: Cluster Management cluster list list the clusters cluster create <name> --count=<count> --ln=<LoginName> [options...] Start a cluster of VMs, and each of them can log into all others. CAUTION: you sould do some default setting before using this command: 1. select cloud to work on, e.g. cloud select india 2. activate the cloud, e.g. cloud on india 3. set the default key to start VMs, e.g. key default [NAME] 4. set the start name of VMs, which is prefix and index, e.g. label --prefix=test --id=1 5. set image of VMs, e.g. default image 6. set flavor of VMs, e.g. default flavor Also, it is better to choose a unused group name cluster show <name> show the detailed information about the cluster VMs cluster remove <name> [--grouponly] remove the cluster and its VMs, if you want to remove the cluster(group name) without removing the VMs, use --grouponly flag Arguments: <name> cluster name or group name Options: --count=<count> give the number of VMs to add into the cluster --ln=<LoginName> give a login name for the VMs, e.g. ubuntu --cloud=<CloudName> give a cloud to work on --flavor=<flavorName> give the name of the flavor --flavorid=<flavorId> give the id of the flavor --image=<imgName> give the name of the image --imageid=<imgId> give the id of the image --force if a group exists and there are VMs in it, the program will ask user to proceed or not, use this flag to respond yes as default(if there are VMs in the group before creating this cluster, the program will include the exist VMs into the cluster) --grouponly remove the group only without removing the VMs, otherwise cluster remove command will remove all the VMs of this cluster FORMAT output format: table, json, csv COLUMN customize what information to display, for example: --column=status,addresses prints the columns status and addresses --detail for table print format, a brief version is used as default, use this flag to print detailed table """ #pprint(arguments) # defer the import of Clusters, as this further imports classes from cloudmesh.experiment.group, # which connects to mongo automatically due to the using of mongoengine. from cloudmesh.shell.clusters import Clusters # cannot move up at the beginning. clusterobj = Clusters() userobj = cm_user() config = cm_config() username = config.username() if arguments['list']: try: clusters_list = clusterobj.list_clusters() except Exception, err: Console.error(str(err)) return if arguments['--format']: if arguments['--format'] not in ALLOWED_PRINT_FORMAT: Console.error("wrong print format: {0}. (allowed print format: {1})".format(format_type, ", ".join(ALLOWED_PRINT_FORMAT))) return else: p_format = arguments['--format'] else: p_format = None shell_commands_dict_output(username, clusters_list, print_format=p_format, firstheader="cluster", header=[["num of nodes", "num_of_nodes"], ["num of active nodes", "num_of_active_nodes"]])
def do_cluster(self, args, arguments): """ :: Usage: cluster list [--format=FORMAT] cluster create <name> [--count=<count>] [--ln=<LoginName>] [--cloud=<CloudName>] [--image=<imgName>|--imageid=<imgId>] [--flavor=<flavorName>|--flavorid=<flavorId>] [--force] cluster show <name> [--format=FORMAT] [--column=COLUMN] [--detail] cluster remove <name> [--grouponly] Description: Cluster Management cluster list list the clusters cluster create <name> --count=<count> --ln=<LoginName> [options...] Start a cluster of VMs, and each of them can log into all others. CAUTION: you sould do some default setting before using this command: 1. select cloud to work on, e.g. cloud select india 2. activate the cloud, e.g. cloud on india 3. set the default key to start VMs, e.g. key default [NAME] 4. set the start name of VMs, which is prefix and index, e.g. label --prefix=test --id=1 5. set image of VMs, e.g. default image 6. set flavor of VMs, e.g. default flavor Also, it is better to choose a unused group name cluster show <name> show the detailed information about the cluster VMs cluster remove <name> [--grouponly] remove the cluster and its VMs, if you want to remove the cluster(group name) without removing the VMs, use --grouponly flag Arguments: <name> cluster name or group name Options: --count=<count> give the number of VMs to add into the cluster --ln=<LoginName> give a login name for the VMs, e.g. ubuntu --cloud=<CloudName> give a cloud to work on --flavor=<flavorName> give the name of the flavor --flavorid=<flavorId> give the id of the flavor --image=<imgName> give the name of the image --imageid=<imgId> give the id of the image --force if a group exists and there are VMs in it, the program will ask user to proceed or not, use this flag to respond yes as default(if there are VMs in the group before creating this cluster, the program will include the exist VMs into the cluster) --grouponly remove the group only without removing the VMs, otherwise cluster remove command will remove all the VMs of this cluster FORMAT output format: table, json, csv COLUMN customize what information to display, for example: --column=status,addresses prints the columns status and addresses --detail for table print format, a brief version is used as default, use this flag to print detailed table """ #pprint(arguments) # defer the import of Clusters, as this further imports classes from cloudmesh.experiment.group, # which connects to mongo automatically due to the using of mongoengine. from cloudmesh.shell.clusters import Clusters # cannot move up at the beginning. clusterobj = Clusters() userobj = cm_user() config = cm_config() username = config.username() if arguments['list']: try: clusters_list = clusterobj.list_clusters() except Exception, err: Console.error(str(err)) return if arguments['--format']: if arguments['--format'] not in ALLOWED_PRINT_FORMAT: Console.error( "wrong print format: {0}. (allowed print format: {1})". format(format_type, ", ".join(ALLOWED_PRINT_FORMAT))) return else: p_format = arguments['--format'] else: p_format = None shell_commands_dict_output( username, clusters_list, print_format=p_format, firstheader="cluster", header=[["num of nodes", "num_of_nodes"], ["num of active nodes", "num_of_active_nodes"]])