List default Address pools row actions as disabled
Default address pools are read-only by design, any attempt to delete or update them will fail. Default address pools row actions dropdown menu has been disabled in order to prevent the unwanted behaviour. Test Plan: PASS: Go to Admin > System Configuration > Address Pools. Create one custom Address pool, save changes and wait until the address pools list is updated properly. PASS: Go to Admin > System Configuration > Address Pools. Select and update custom Address pool, save changes and wait until the address pools list is updated properly. PASS: Go to Admin > System Configuration > Address Pools. Select and delete custom Address pool, wait until the address pools list is updated properly. PASS: Go to Admin > System Configuration > Address Pools. Try to update default Address pool, actions is not allowed. PASS: Go to Admin > System Configuration > Address Pools. Try to delete default Address pool using dropdown option, actions is not allowed. Closes-bug: 2030350 Depends-On: https://review.opendev.org/c/starlingx/upstream/+/891042 Change-Id: I6219e958cf56eef588e0de07911180c9f6bfc55a Signed-off-by: Rafael Moyano <rafael.moyano@windriver.com>
This commit is contained in:
parent
81e85845f0
commit
26d37f6eb6
@ -2169,13 +2169,41 @@ class AddressPool(base.APIResourceWrapper):
|
||||
|
||||
_attrs = ['uuid', 'name', 'network', 'prefix', 'order', 'ranges']
|
||||
|
||||
def add_attr(self, attr):
|
||||
self._attrs.append(attr)
|
||||
|
||||
def __init__(self, apiresource):
|
||||
super(AddressPool, self).__init__(apiresource)
|
||||
|
||||
|
||||
def address_pool_check_readonly(request, pools):
|
||||
ro_msg = "Address pool is read-only and cannot be modified or removed"
|
||||
nPools = []
|
||||
if not isinstance(pools, list):
|
||||
nPools.append(pools)
|
||||
else:
|
||||
nPools = pools
|
||||
|
||||
updates = {}
|
||||
for pool in nPools:
|
||||
curr_pool = nPools.index(pool)
|
||||
updates['name'] = pool.name
|
||||
read_only_pool = AddressPool(pool)
|
||||
read_only_pool.add_attr('readonly')
|
||||
try:
|
||||
address_pool_update(request, pool.uuid, **updates)
|
||||
read_only_pool.readonly = False
|
||||
except Exception as e:
|
||||
if str(e) == ro_msg:
|
||||
read_only_pool.readonly = True
|
||||
nPools[curr_pool] = read_only_pool
|
||||
return nPools
|
||||
|
||||
|
||||
def address_pool_list(request):
|
||||
pools = cgtsclient(request).address_pool.list()
|
||||
return [AddressPool(p) for p in pools]
|
||||
pools = address_pool_check_readonly(request, pools)
|
||||
return pools
|
||||
|
||||
|
||||
def address_pool_get(request, address_pool_uuid):
|
||||
@ -2183,12 +2211,17 @@ def address_pool_get(request, address_pool_uuid):
|
||||
if not pool:
|
||||
raise ValueError(
|
||||
'No match found for address pool uuid "%s".' % address_pool_uuid)
|
||||
return AddressPool(pool)
|
||||
pool = address_pool_check_readonly(request, pool)
|
||||
return pool[0]
|
||||
|
||||
|
||||
def address_pool_create(request, **kwargs):
|
||||
pool = cgtsclient(request).address_pool.create(**kwargs)
|
||||
return AddressPool(pool)
|
||||
read_only_pool = AddressPool(pool)
|
||||
read_only_pool.add_attr('readonly')
|
||||
# Address pools created post bootstrap are not read-only.
|
||||
read_only_pool.readonly = False
|
||||
return read_only_pool
|
||||
|
||||
|
||||
def address_pool_delete(request, address_pool_uuid):
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2015 Wind River Systems, Inc
|
||||
# Copyright 2015-2023 Wind River Systems, Inc
|
||||
#
|
||||
# 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
|
||||
@ -67,6 +67,12 @@ class UpdateAddressPool(tables.LinkAction):
|
||||
url = "horizon:admin:system_config:updateaddrpool"
|
||||
classes = ("ajax-modal", "btn-edit")
|
||||
|
||||
def allowed(self, request, pool):
|
||||
if pool.readonly is True:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
return True
|
||||
|
||||
def get_link_url(self, pool):
|
||||
return reverse(self.url, args=(pool.uuid,))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user