summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwona Kotlarska <iwona260909@gmail.com>2017-08-16 11:49:36 +0200
committerIwona Kotlarska <pinus314@gmail.com>2017-11-02 00:17:52 +0100
commit4b840b31dc78947a79437a09c9d8426fb37b8060 (patch)
tree4c621868ae212d70a90189718323ec26aa947ad5
parent15d3a9e21644b4707d6d865be2d6ee5ab620681a (diff)
downloadpython-saharaclient-4b840b31dc78947a79437a09c9d8426fb37b8060.tar.gz
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
-rw-r--r--saharaclient/api/cluster_templates.py4
-rw-r--r--saharaclient/osc/v1/cluster_templates.py37
-rw-r--r--setup.cfg1
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)
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