gui/cgcs_dashboard/dashboards/admin/inventory/memorys/tables.py

100 lines
3.2 KiB
Python

#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# The right to copy, distribute, modify, or otherwise make use
# of this software may be licensed only pursuant to the terms
# of an applicable Wind River license agreement.
#
import logging
from django.core.urlresolvers import reverse # noqa
from django import template
from django.utils.translation import ugettext_lazy as _
from horizon import tables
from openstack_dashboard import api
LOG = logging.getLogger(__name__)
class UpdateMemory(tables.LinkAction):
name = "updatememory"
verbose_name = _("Update Memory")
url = "horizon:admin:inventory:updatememory"
classes = ("ajax-modal", "btn-create")
def get_link_url(self, memory=None):
host_id = self.table.kwargs['host_id']
return reverse(self.url, args=(host_id,))
def allowed(self, request, memory=None):
host = self.table.kwargs['host']
return (host._administrative == 'locked' and
host.subfunctions and
'compute' in host.subfunctions)
class CreateMemoryProfile(tables.LinkAction):
name = "createMemoryProfile"
verbose_name = _("Create Memory Profile")
url = "horizon:admin:inventory:addmemoryprofile"
classes = ("ajax-modal", "btn-create")
def get_link_url(self, datum=None):
host_id = self.table.kwargs['host_id']
return reverse(self.url, args=(host_id,))
def allowed(self, request, datum):
host = self.table.kwargs['host']
if host.subfunctions and 'compute' not in host.subfunctions:
return False
return (host.invprovision == 'provisioned' and
not api.sysinv.is_system_mode_simplex(request))
def get_processor_memory(memory):
if memory.hugepages_configured == 'True':
template_name = \
'admin/inventory/memorys/_memoryfunction_hugepages.html'
else:
template_name = \
'admin/inventory/memorys/_memoryfunction_hugepages_other.html'
context = {"memory": memory}
return template.loader.render_to_string(template_name, context)
def get_vswitch_hugepages(memory):
template_name = 'admin/inventory/memorys/_vswitchfunction_hugepages.html'
context = {"memory": memory}
return template.loader.render_to_string(template_name, context)
def get_vm_hugepages(memory):
template_name = 'admin/inventory/memorys/_vmfunction_hugepages.html'
context = {"memory": memory}
return template.loader.render_to_string(template_name, context)
class MemorysTable(tables.DataTable):
processor = tables.Column('numa_node',
verbose_name=_('Processor'))
memory = tables.Column(get_processor_memory,
verbose_name=_('Memory'))
vswitch_huge = tables.Column(get_vswitch_hugepages,
verbose_name=_('VSwitch Huge Pages'))
vm_huge = tables.Column(get_vm_hugepages,
verbose_name=_('VM Pages'))
def get_object_id(self, datum):
return unicode(datum.uuid)
class Meta(object):
name = "memorys"
verbose_name = _("Memory")
multi_select = False
table_actions = (UpdateMemory, CreateMemoryProfile,)