From 4b840b31dc78947a79437a09c9d8426fb37b8060 Mon Sep 17 00:00:00 2001 From: Iwona Kotlarska Date: Wed, 16 Aug 2017 11:49:36 +0200 Subject: Add export of cluster templates Partially-Implements: bp portable-node-group-and-cluster-templates Depends-On: Ib5a2df4013840050b8034bcefd68040f508d0b31 This change adds command 'dataprocessing cluster template export' to OpenStack CLI. Change-Id: I027169ace70929318990a4225d456bf1cf8a83b2 --- saharaclient/api/cluster_templates.py | 4 ++++ saharaclient/osc/v1/cluster_templates.py | 37 +++++++++++++++++++++++++++++++- setup.cfg | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) 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="", + help="Name or id of the cluster template to export", + ) + parser.add_argument( + "--file", + metavar="", + 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) diff --git a/setup.cfg b/setup.cfg index d1fa15a..fd0c8c5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,6 +62,7 @@ openstack.data_processing.v1 = dataprocessing_cluster_template_update = saharaclient.osc.v1.cluster_templates:UpdateClusterTemplate dataprocessing_cluster_template_delete = saharaclient.osc.v1.cluster_templates:DeleteClusterTemplate dataprocessing_cluster_template_import = saharaclient.osc.v1.cluster_templates:ImportClusterTemplate + dataprocessing_cluster_template_export = saharaclient.osc.v1.cluster_templates:ExportClusterTemplate dataprocessing_cluster_create = saharaclient.osc.v1.clusters:CreateCluster dataprocessing_cluster_list = saharaclient.osc.v1.clusters:ListClusters -- cgit v1.2.1