diff options
author | Zuul <zuul@review.openstack.org> | 2017-11-06 05:18:32 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2017-11-06 05:18:32 +0000 |
commit | 6697f43e15900611a34321cb0506bcb3f500ac22 (patch) | |
tree | 13b2801152f6c3a5a71116f138b5eaa780d98408 | |
parent | b1c541581fc3a8465ddd79e381db8cec15717743 (diff) | |
parent | 4b840b31dc78947a79437a09c9d8426fb37b8060 (diff) | |
download | python-saharaclient-6697f43e15900611a34321cb0506bcb3f500ac22.tar.gz |
Merge "Add export of cluster templates"
-rw-r--r-- | saharaclient/api/cluster_templates.py | 4 | ||||
-rw-r--r-- | saharaclient/osc/v1/cluster_templates.py | 37 | ||||
-rw-r--r-- | setup.cfg | 1 |
3 files changed, 41 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) @@ -63,6 +63,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 |