From a1777e7658f979183639e1b28a5ffef8328feb47 Mon Sep 17 00:00:00 2001 From: Iwona Kotlarska Date: Tue, 15 Aug 2017 16:36:54 +0200 Subject: [PATCH] Add export of cluster templates to UI Partially-Implements: bp portable-node-group-and-cluster-templates Depends-On: I027169ace70929318990a4225d456bf1cf8a83b2 This chande adds an option to GUI to enable user export a cluster template Change-Id: If1c1b055c3f03b656853db1b35c42a422b08de7f --- sahara_dashboard/api/sahara.py | 4 ++++ .../clusters/cluster_templates/tables.py | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/sahara_dashboard/api/sahara.py b/sahara_dashboard/api/sahara.py index a0b11378..52f54533 100644 --- a/sahara_dashboard/api/sahara.py +++ b/sahara_dashboard/api/sahara.py @@ -334,6 +334,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)