From 9b9ff62e1891b7ca31aad2f5cf5043fc729027df Mon Sep 17 00:00:00 2001 From: Iwona Kotlarska Date: Mon, 24 Jul 2017 20:46:12 +0200 Subject: Add export of node group templates to CLI Partially-Implements: bp portable-node-group-and-cluster-templates Depends-On: I33c3b6daa5b9e2be218a84efdb6113a4ce9a86df This change adds command 'dataprocessing node group template export' to OpenStack CLI. Change-Id: If795b21bacf497d7198c9d33f6da70873d5c8ede --- saharaclient/osc/v1/node_group_templates.py | 35 +++++++++++++++++++++++++++++ setup.cfg | 1 + 2 files changed, 36 insertions(+) diff --git a/saharaclient/osc/v1/node_group_templates.py b/saharaclient/osc/v1/node_group_templates.py index 3b0c7dd..9cfe282 100644 --- a/saharaclient/osc/v1/node_group_templates.py +++ b/saharaclient/osc/v1/node_group_templates.py @@ -768,3 +768,38 @@ class ImportNodeGroupTemplate(command.ShowOne): data = utils.prepare_data(data, NGT_FIELDS) return self.dict2columns(data) + + +class ExportNodeGroupTemplate(command.Command): + """Export node group template to JSON""" + + log = logging.getLogger(__name__ + ".ExportNodeGroupTemplate") + + def get_parser(self, prog_name): + parser = super(ExportNodeGroupTemplate, self).get_parser(prog_name) + parser.add_argument( + "node_group_template", + metavar="", + help="Name or id of the node group template to export", + ) + parser.add_argument( + "--file", + metavar="", + help="Name of the file node group template should be exported to." + "If not provided, print to stdout", + ) + + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + client = self.app.client_manager.data_processing + ngt_id = utils.get_resource_id( + client.node_group_templates, parsed_args.node_group_template) + response = client.node_group_templates.export(ngt_id) + result = json.dumps(response._info, indent=4)+"\n" + if parsed_args.file: + with open(parsed_args.file, "w+") as file: + file.write(result) + else: + sys.stdout.write(result) diff --git a/setup.cfg b/setup.cfg index c6a3329..08eb024 100644 --- a/setup.cfg +++ b/setup.cfg @@ -56,6 +56,7 @@ openstack.data_processing.v1 = dataprocessing_node_group_template_update = saharaclient.osc.v1.node_group_templates:UpdateNodeGroupTemplate dataprocessing_node_group_template_delete = saharaclient.osc.v1.node_group_templates:DeleteNodeGroupTemplate dataprocessing_node_group_template_import = saharaclient.osc.v1.node_group_templates:ImportNodeGroupTemplate + dataprocessing_node_group_template_export = saharaclient.osc.v1.node_group_templates:ExportNodeGroupTemplate dataprocessing_cluster_template_create = saharaclient.osc.v1.cluster_templates:CreateClusterTemplate dataprocessing_cluster_template_list = saharaclient.osc.v1.cluster_templates:ListClusterTemplates -- cgit v1.2.1