diff --git a/sahara_dashboard/api/sahara.py b/sahara_dashboard/api/sahara.py index 365def55..c07d4594 100644 --- a/sahara_dashboard/api/sahara.py +++ b/sahara_dashboard/api/sahara.py @@ -338,6 +338,10 @@ def cluster_template_update_acl_rules(request, ct_id, ct_id, **prepare_acl_update_dict(is_public, is_protected)) +def cluster_template_export(request, object_id): + return client(request).cluster_templates.export(object_id) + + def cluster_create(request, name, plugin_name, hadoop_version, cluster_template_id=None, default_image_id=None, is_transient=None, description=None, cluster_configs=None, diff --git a/sahara_dashboard/content/data_processing/clusters/cluster_templates/tables.py b/sahara_dashboard/content/data_processing/clusters/cluster_templates/tables.py index 0e4cbc4b..978ee4ef 100644 --- a/sahara_dashboard/content/data_processing/clusters/cluster_templates/tables.py +++ b/sahara_dashboard/content/data_processing/clusters/cluster_templates/tables.py @@ -12,6 +12,7 @@ # limitations under the License. from django.core import urlresolvers +from django import http as http_response from django.template import defaultfilters as filters from django.utils import http from django.utils.translation import ugettext_lazy as _ @@ -19,6 +20,7 @@ from django.utils.translation import ungettext_lazy from horizon import tables from horizon.tabs import base as tabs_base +from oslo_serialization import jsonutils as json from sahara_dashboard.api import sahara as saharaclient from sahara_dashboard.content.data_processing \ @@ -58,6 +60,23 @@ class CopyTemplate(tables.LinkAction): classes = ("ajax-modal", ) +class ExportTemplate(tables.Action): + name = "export" + verbose_name = _("Export Template") + classes = ("ajax-modal", ) + + def single(self, data_table, request, object_id): + content = json.dumps(saharaclient.cluster_template_export( + request, object_id)._info) + response = http_response.HttpResponse( + content, content_type="application/json") + filename = '%s-cluster-template.json' % object_id + disposition = 'attachment; filename="%s"' % filename + response['Content-Disposition'] = disposition.encode('utf-8') + response['Content-Length'] = str(len(response.content)) + return response + + class EditTemplate(tables.LinkAction): name = "edit" verbose_name = _("Edit Template") @@ -165,5 +184,6 @@ class ClusterTemplatesTable(sahara_table.SaharaPaginateTabbedTable): row_actions = (CreateCluster, EditTemplate, CopyTemplate, + ExportTemplate, DeleteTemplate, MakePublic, MakePrivate, MakeProtected, MakeUnProtected)