Add export of node group templates

Partially-Implements: bp portable-node-group-and-cluster-templates

Depends-On: I33c3b6daa5b9e2be218a84efdb6113a4ce9a86df

This change adds functions to saharaclient to enable export of ngt
to JSON.

Change-Id: Ic5d9dffd0a3ae21a28ecbcfdd88f5cd1194551bb
This commit is contained in:
Iwona Kotlarska 2017-07-19 15:56:19 +02:00
parent fc2b57b121
commit d6056d1ab6
3 changed files with 24 additions and 0 deletions

View File

@ -8,6 +8,7 @@ Django<2.0,>=1.8 # BSD
django-compressor>=2.0 # MIT
django-openstack-auth>=3.5.0 # Apache-2.0
oslo.log>=3.30.0 # Apache-2.0
oslo.serialization!=2.19.1,>=1.10.0 # Apache-2.0
python-designateclient>=1.5.0 # Apache-2.0
python-keystoneclient>=3.8.0 # Apache-2.0
python-manilaclient>=1.12.0 # Apache-2.0

View File

@ -259,6 +259,10 @@ def nodegroup_update_acl_rules(request, nid,
nid, **prepare_acl_update_dict(is_public, is_protected))
def nodegroup_template_export(request, object_id):
return client(request).node_group_templates.export(object_id)
def cluster_template_create(request, name, plugin_name, hadoop_version,
description=None, cluster_configs=None,
node_groups=None, anti_affinity=None,

View File

@ -11,12 +11,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django import http
from django.template import defaultfilters as filters
from django.utils.translation import ugettext_lazy as _
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 \
@ -65,6 +67,22 @@ class EditTemplate(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.nodegroup_template_export(
request, object_id)._info)
response = http.HttpResponse(content, content_type="application/json")
filename = '%s-node-group-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 DeleteTemplate(tables.DeleteAction):
@staticmethod
def action_present(count):
@ -138,5 +156,6 @@ class NodegroupTemplatesTable(sahara_table.SaharaPaginateTabbedTable):
MakeUnProtected)
row_actions = (EditTemplate,
CopyTemplate,
ExportTemplate,
DeleteTemplate, MakePublic, MakePrivate, MakeProtected,
MakeUnProtected)