Merge "Add export of cluster templates"
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user