Tabbity quota default update workflow

Part of blueprint horizon-plugin-tab-for-info-and-quotas
Change-Id: Ieead15fe24cdc5cea94aea29d7fc0051ba33fb71
This commit is contained in:
Akihiro Motoki 2018-01-15 08:15:59 +09:00
parent f5802ce28b
commit 2ad9f81483
3 changed files with 62 additions and 28 deletions

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.translation import ugettext_lazy as _
from horizon import tables
@ -37,6 +39,13 @@ class UpdateDefaultQuotas(tables.LinkAction):
url = "horizon:admin:defaults:update_defaults"
classes = ("ajax-modal",)
icon = "pencil"
step = None
def get_link_url(self, datum=None):
url = [reverse(self.url)]
if self.step:
url.append(urlencode({'step': self.step}))
return '?'.join(url)
def allowed(self, request, _=None):
return quotas.enabled_quotas(request)
@ -119,7 +128,7 @@ class VolumeQuotasTable(tables.DataTable):
class Meta(object):
name = "volume_quotas"
verbose_name = _("Volume Quotas")
table_actions = (QuotaFilterAction, UpdateDefaultQuotas)
table_actions = (QuotaFilterAction, UpdateDefaultVolumeQuotas)
multi_select = False

View File

@ -40,9 +40,9 @@ class UpdateDefaultQuotasView(workflows.WorkflowView):
quota_defaults = quotas.get_default_quota_data(self.request)
for field in quotas.QUOTA_FIELDS:
initial[field] = quota_defaults.get(field).limit
except Exception:
error_msg = _('Unable to retrieve default quota values.')
self.add_error_to_step(error_msg, 'update_default_quotas')
initial['disabled_quotas'] = quotas.get_disabled_quotas(self.request)
return initial

View File

@ -27,47 +27,71 @@ from openstack_dashboard.usage import quotas
LOG = logging.getLogger(__name__)
class UpdateDefaultQuotasAction(workflows.Action):
ifcb_label = _("Injected File Content Bytes")
ifpb_label = _("Length of Injected File Path")
injected_file_content_bytes = forms.IntegerField(min_value=-1,
label=ifcb_label)
class UpdateDefaultComputeQuotasAction(workflows.Action):
instances = forms.IntegerField(min_value=-1, label=_("Instances"))
cores = forms.IntegerField(min_value=-1, label=_("VCPUs"))
ram = forms.IntegerField(min_value=-1, label=_("RAM (MB)"))
metadata_items = forms.IntegerField(min_value=-1,
label=_("Metadata Items"))
ram = forms.IntegerField(min_value=-1, label=_("RAM (MB)"))
key_pairs = forms.IntegerField(min_value=-1, label=_("Key Pairs"))
injected_file_path_bytes = forms.IntegerField(min_value=-1,
label=ifpb_label)
instances = forms.IntegerField(min_value=-1, label=_("Instances"))
injected_files = forms.IntegerField(min_value=-1,
label=_("Injected Files"))
cores = forms.IntegerField(min_value=-1, label=_("VCPUs"))
gigabytes = forms.IntegerField(
injected_file_content_bytes = forms.IntegerField(
min_value=-1,
label=_("Total Size of Volumes and Snapshots (GiB)"))
snapshots = forms.IntegerField(min_value=-1, label=_("Volume Snapshots"))
volumes = forms.IntegerField(min_value=-1, label=_("Volumes"))
label=_("Injected File Content Bytes"))
injected_file_path_bytes = forms.IntegerField(
min_value=-1,
label=_("Length of Injected File Path"))
def __init__(self, request, *args, **kwargs):
super(UpdateDefaultQuotasAction, self).__init__(request,
*args,
**kwargs)
disabled_quotas = quotas.get_disabled_quotas(request)
def __init__(self, request, context, *args, **kwargs):
super(UpdateDefaultComputeQuotasAction, self).__init__(
request, context, *args, **kwargs)
disabled_quotas = context['disabled_quotas']
for field in disabled_quotas:
if field in self.fields:
self.fields[field].required = False
self.fields[field].widget = forms.HiddenInput()
class Meta(object):
name = _("Default Quotas")
slug = 'update_default_quotas'
help_text = _("From here you can update the default quotas "
name = _("Compute")
slug = 'update_default_compute_quotas'
help_text = _("From here you can update the default compute quotas "
"(max limits).")
class UpdateDefaultQuotasStep(workflows.Step):
action_class = UpdateDefaultQuotasAction
contributes = quotas.QUOTA_FIELDS
class UpdateDefaultComputeQuotasStep(workflows.Step):
action_class = UpdateDefaultComputeQuotasAction
contributes = quotas.NOVA_QUOTA_FIELDS
depends_on = ('disabled_quotas',)
class UpdateDefaultVolumeQuotasAction(workflows.Action):
volumes = forms.IntegerField(min_value=-1, label=_("Volumes"))
gigabytes = forms.IntegerField(
min_value=-1,
label=_("Total Size of Volumes and Snapshots (GiB)"))
snapshots = forms.IntegerField(min_value=-1, label=_("Volume Snapshots"))
def __init__(self, request, context, *args, **kwargs):
super(UpdateDefaultVolumeQuotasAction, self).__init__(
request, context, *args, **kwargs)
disabled_quotas = context['disabled_quotas']
for field in disabled_quotas:
if field in self.fields:
self.fields[field].required = False
self.fields[field].widget = forms.HiddenInput()
class Meta(object):
name = _("Volume")
slug = 'update_default_volume_quotas'
help_text = _("From here you can update the default volume quotas "
"(max limits).")
class UpdateDefaultVolumeQuotasStep(workflows.Step):
action_class = UpdateDefaultVolumeQuotasAction
contributes = quotas.CINDER_QUOTA_FIELDS
depends_on = ('disabled_quotas',)
class UpdateDefaultQuotas(workflows.Workflow):
@ -77,7 +101,8 @@ class UpdateDefaultQuotas(workflows.Workflow):
success_message = _('Default quotas updated.')
failure_message = _('Unable to update default quotas.')
success_url = "horizon:admin:defaults:index"
default_steps = (UpdateDefaultQuotasStep,)
default_steps = (UpdateDefaultComputeQuotasStep,
UpdateDefaultVolumeQuotasStep)
def handle(self, request, data):
# Update the default quotas.