diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py index f5ca0528..c1dd705b 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/api/sysinv.py @@ -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): diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/address_pools/tables.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/address_pools/tables.py index 1056704d..edd71035 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/address_pools/tables.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/system_config/address_pools/tables.py @@ -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,))