diff options
author | Iwona Kotlarska <iwona260909@gmail.com> | 2017-07-24 20:46:12 +0200 |
---|---|---|
committer | Iwona Kotlarska <pinus314@gmail.com> | 2017-11-02 00:24:25 +0100 |
commit | 9b9ff62e1891b7ca31aad2f5cf5043fc729027df (patch) | |
tree | 8a679fe36eac3bae4d009e584e497b9d2e822ff3 /saharaclient | |
parent | 955e7b5bc8cf4c4bc8c71d365d664bb3474d6b50 (diff) | |
download | python-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
Diffstat (limited to 'saharaclient')
-rw-r--r-- | saharaclient/osc/v1/node_group_templates.py | 35 |
1 files changed, 35 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) |