Add cluster-template-create to CLI

cluster-template-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.

Change-Id: Ia824eb54b1f255ead8ea1a3e9cdff9ad8bdb07a9
Implements: blueprint python-savannaclient-cli
This commit is contained in:
Matthew Farrellee
2014-01-21 14:28:36 -05:00
parent 0decd46dd0
commit f4c3a2986d

View File

@@ -342,7 +342,7 @@ def do_node_group_template_delete(cs, args):
#
# cluster-template-show --name <template>|--id <template_id> [--json]
#
# TODO(mattf): cluster-template-create
# cluster-template-create [--json <file>]
#
# cluster-template-delete --name <template>|--id <template_id>
#
@@ -377,6 +377,22 @@ def do_cluster_template_show(cs, args):
_show_cluster_template(template)
@utils.arg('--json',
default=sys.stdin,
type=argparse.FileType('r'),
help='JSON representation of cluster template')
def do_cluster_template_create(cs, args):
"""Create a cluster template."""
# TODO(mattf): improve template validation, e.g. template w/o name key
template = json.loads(args.json.read())
valid_args = inspect.getargspec(cs.cluster_templates.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_template(cs.cluster_templates.create(**template))
# TODO(mattf): Add --name
#@utils.arg('--name',
# metavar='<template>',