summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwona Kotlarska <iwona260909@gmail.com>2017-07-24 20:46:12 +0200
committerIwona Kotlarska <pinus314@gmail.com>2017-11-02 00:24:25 +0100
commit9b9ff62e1891b7ca31aad2f5cf5043fc729027df (patch)
tree8a679fe36eac3bae4d009e584e497b9d2e822ff3
parent955e7b5bc8cf4c4bc8c71d365d664bb3474d6b50 (diff)
downloadpython-saharaclient-9b9ff62e1891b7ca31aad2f5cf5043fc729027df.tar.gz
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
-rw-r--r--saharaclient/osc/v1/node_group_templates.py35
-rw-r--r--setup.cfg1
2 files changed, 36 insertions, 0 deletions
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="<node-group-template>",
+ help="Name or id of the node group template to export",
+ )
+ parser.add_argument(
+ "--file",
+ metavar="<filename>",
+ 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