diff options
Diffstat (limited to 'saharaclient')
-rw-r--r-- | saharaclient/api/cluster_templates.py | 4 | ||||
-rw-r--r-- | saharaclient/osc/v1/cluster_templates.py | 37 |
2 files changed, 40 insertions, 1 deletions
diff --git a/saharaclient/api/cluster_templates.py b/saharaclient/api/cluster_templates.py index 9c7bd43..da9b3fe 100644 --- a/saharaclient/api/cluster_templates.py +++ b/saharaclient/api/cluster_templates.py @@ -97,3 +97,7 @@ class ClusterTemplateManager(base.ResourceManager): def delete(self, cluster_template_id): """Delete a Cluster Template.""" self._delete('/cluster-templates/%s' % cluster_template_id) + + def export(self, cluster_template_id): + """Export a Cluster Template.""" + return self._get('/cluster-templates/%s/export' % cluster_template_id) diff --git a/saharaclient/osc/v1/cluster_templates.py b/saharaclient/osc/v1/cluster_templates.py index e3154df..6441c17 100644 --- a/saharaclient/osc/v1/cluster_templates.py +++ b/saharaclient/osc/v1/cluster_templates.py @@ -509,7 +509,7 @@ class UpdateClusterTemplate(command.ShowOne): class ImportClusterTemplate(command.ShowOne): - """Imports node group template""" + """Imports cluster template""" log = logging.getLogger(__name__ + ".ImportClusterTemplate") @@ -588,3 +588,38 @@ class ImportClusterTemplate(command.ShowOne): data = utils.prepare_data(data, CT_FIELDS) return self.dict2columns(data) + + +class ExportClusterTemplate(command.Command): + """Export cluster template to JSON""" + + log = logging.getLogger(__name__ + ".ExportClusterTemplate") + + def get_parser(self, prog_name): + parser = super(ExportClusterTemplate, self).get_parser(prog_name) + parser.add_argument( + "cluster_template", + metavar="<cluster-template>", + help="Name or id of the cluster template to export", + ) + parser.add_argument( + "--file", + metavar="<filename>", + help="Name of the file cluster 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.cluster_templates, parsed_args.cluster_template) + response = client.cluster_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) |