# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
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 openstack_dashboard.contrib.sahara.api import sahara as saharaclient
from openstack_dashboard.contrib.sahara.content.data_processing.utils \
import acl as acl_utils
LOG = logging.getLogger(__name__)
[docs]class NodeGroupTemplatesFilterAction(tables.FilterAction):
filter_type = "server"
filter_choices = (('name', _("Name"), True),
('plugin', _("Plugin"), True),
('hadoop_version', _("Version"), True))
[docs]class CreateNodegroupTemplate(tables.LinkAction):
name = "create"
verbose_name = _("Create Template")
url = ("horizon:project:data_processing.nodegroup_templates:"
"create-nodegroup-template")
classes = ("ajax-modal", "create-nodegrouptemplate-btn")
icon = "plus"
[docs]class CopyTemplate(tables.LinkAction):
name = "copy"
verbose_name = _("Copy Template")
url = "horizon:project:data_processing.nodegroup_templates:copy"
classes = ("ajax-modal", )
[docs]class EditTemplate(tables.LinkAction):
name = "edit"
verbose_name = _("Edit Template")
url = "horizon:project:data_processing.nodegroup_templates:edit"
classes = ("ajax-modal", )
[docs]class DeleteTemplate(tables.DeleteAction):
@staticmethod
[docs] def action_present(count):
return ungettext_lazy(
u"Delete Template",
u"Delete Templates",
count
)
@staticmethod
[docs] def action_past(count):
return ungettext_lazy(
u"Deleted Template",
u"Deleted Templates",
count
)
[docs] def delete(self, request, template_id):
saharaclient.nodegroup_template_delete(request, template_id)
[docs]def change_node_group_templates_rules_method(request, ngt_id, **kwargs):
ngt = saharaclient.nodegroup_template_get(request, ngt_id)
update_required_fields = ('name', 'plugin_name',
'hadoop_version', 'flavor_id')
for field in update_required_fields:
kwargs[field] = getattr(ngt, field)
saharaclient.nodegroup_template_update(request, ngt_id, **kwargs)
[docs]class MakePublic(acl_utils.MakePublic):
[docs] def change_rule_method(self, request, datum_id, **update_kwargs):
change_node_group_templates_rules_method(
request, datum_id, **update_kwargs)
[docs]class MakePrivate(acl_utils.MakePrivate):
[docs] def change_rule_method(self, request, datum_id, **update_kwargs):
change_node_group_templates_rules_method(
request, datum_id, **update_kwargs)
[docs]class MakeProtected(acl_utils.MakeProtected):
[docs] def change_rule_method(self, request, datum_id, **update_kwargs):
change_node_group_templates_rules_method(
request, datum_id, **update_kwargs)
[docs]class MakeUnProtected(acl_utils.MakeUnProtected):
[docs] def change_rule_method(self, request, datum_id, **update_kwargs):
change_node_group_templates_rules_method(
request, datum_id, **update_kwargs)
[docs]class NodegroupTemplatesTable(tables.DataTable):
name = tables.Column(
"name",
verbose_name=_("Name"),
link="horizon:project:data_processing.nodegroup_templates:details")
plugin_name = tables.Column("plugin_name",
verbose_name=_("Plugin"))
hadoop_version = tables.Column("hadoop_version",
verbose_name=_("Version"))
node_processes = tables.Column("node_processes",
verbose_name=_("Node Processes"),
wrap_list=True,
filters=(filters.unordered_list,))