From fe072c0559932d671362d1dce0e432223894f34b Mon Sep 17 00:00:00 2001 From: Matthew Farrellee Date: Tue, 21 Jan 2014 14:30:32 -0500 Subject: [PATCH] Add cluster-create to CLI cluster-create takes a json data structure and passes it on to the Savanna API. The data structure is read from stdin by default or from a file provided by the --json parameter. Implements: blueprint python-savannaclient-cli Change-Id: I08cd3a38df81e78c71cfbc7cdb4bd59902b2d374 --- savannaclient/api/shell.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/savannaclient/api/shell.py b/savannaclient/api/shell.py index 8e45f18b..20e5531f 100644 --- a/savannaclient/api/shell.py +++ b/savannaclient/api/shell.py @@ -208,7 +208,7 @@ def do_image_remove_tag(cs, args): # # cluster-show --name |--id [--json] # -# TODO(mattf): cluster-create +# cluster-create [--json ] # # TODO(mattf): cluster-scale # @@ -247,6 +247,22 @@ def do_cluster_show(cs, args): _show_cluster(cluster) +@utils.arg('--json', + default=sys.stdin, + type=argparse.FileType('r'), + help='JSON representation of cluster') +def do_cluster_create(cs, args): + """Create a cluster.""" + # TODO(mattf): improve template validation, e.g. template w/o name key + template = json.loads(args.json.read()) + valid_args = inspect.getargspec(cs.clusters.create).args + for name in template.keys(): + if name not in valid_args: + # TODO(mattf): make this verbose - bug/1271147 + del template[name] + _show_cluster(cs.clusters.create(**template)) + + # TODO(mattf): Add --name #@utils.arg('--name', # metavar='',