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
This commit is contained in:
Iwona Kotlarska 2017-08-15 16:36:54 +02:00
parent fc2b57b121
commit a1777e7658
2 changed files with 24 additions and 0 deletions

View File

@ -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,

View File

@ -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)