Support configuration of system-controller address pools post-install

During migrating a subcloud to a new central cloud, the system
controller's network configuration needs to be re-configured in the
subcloud. This commit removes the check of is_initial_config_complete
flag during modification/deletion of the system-controller-subnet and
system-controller-oam-subnet address pools. After this commit, the two
types of address pools can be re-configured after the initial
bootstrap.

Test:
Delete the system-controller-subnet and
system-controller-oam-subnet in a subcloud after bootstrap.

Change-Id: Ied68bbfd83a0cc1c3bb0fb31ee55f924353fb4b5
Story: 2008774
Task: 42291
Signed-off-by: Yuxing Jiang <yuxing.jiang@windriver.com>
This commit is contained in:
Yuxing Jiang 2021-04-16 08:19:25 -04:00
parent 658d556fe9
commit a9fc0be4e5
1 changed files with 25 additions and 12 deletions

View File

@ -15,7 +15,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
# Copyright (c) 2015-2017 Wind River Systems, Inc. # Copyright (c) 2015-2021 Wind River Systems, Inc.
# #
@ -55,6 +55,11 @@ ADDRPOOL_CONTROLLER1_ADDRESS_ID = 'controller1_address_id'
ADDRPOOL_FLOATING_ADDRESS_ID = 'floating_address_id' ADDRPOOL_FLOATING_ADDRESS_ID = 'floating_address_id'
ADDRPOOL_GATEWAY_ADDRESS_ID = 'gateway_address_id' ADDRPOOL_GATEWAY_ADDRESS_ID = 'gateway_address_id'
# Address pool for system controller in the subcloud are
# allowed to be deleted/modified post install
SYSTEM_CONTROLLER_ADDRPOOLS = ['system-controller-subnet',
'system-controller-oam-subnet']
class AddressPoolPatchType(types.JsonPatchType): class AddressPoolPatchType(types.JsonPatchType):
"""A complex type that represents a single json-patch operation.""" """A complex type that represents a single json-patch operation."""
@ -332,14 +337,17 @@ class AddressPoolController(rest.RestController):
self._check_valid_range(network, start, end, ipset) self._check_valid_range(network, start, end, ipset)
ipset.update(netaddr.IPRange(start, end)) ipset.update(netaddr.IPRange(start, end))
def _check_pool_readonly(self, address_pool_id): def _check_pool_readonly(self, addrpool):
networks = pecan.request.dbapi.networks_get_by_pool(address_pool_id) # The system controller's network pools are expected writeable for re-home
# Pool is considered readonly after the initial configuration is # a subcloud to new system controllers.
# complete. During bootstrap it should be modifiable even though if addrpool.name not in SYSTEM_CONTROLLER_ADDRPOOLS:
# it is allocated to a network. networks = pecan.request.dbapi.networks_get_by_pool(addrpool.id)
if networks and cutils.is_initial_config_complete(): # An addresspool except the system controller's pools, is considered
# network managed address pool, no changes permitted # readonly after the initial configuration is complete. During bootstrap
raise exception.AddressPoolReadonly() # it should be modifiable even though it is allocated to a network.
if networks and cutils.is_initial_config_complete():
# network managed address pool, no changes permitted
raise exception.AddressPoolReadonly()
def _make_default_range(self, addrpool): def _make_default_range(self, addrpool):
ipset = netaddr.IPSet([addrpool['network'] + "/" + str(addrpool['prefix'])]) ipset = netaddr.IPSet([addrpool['network'] + "/" + str(addrpool['prefix'])])
@ -550,7 +558,7 @@ class AddressPoolController(rest.RestController):
"""Updates attributes of an IP address pool.""" """Updates attributes of an IP address pool."""
addrpool = self._get_one(address_pool_uuid) addrpool = self._get_one(address_pool_uuid)
updates = self._get_updates(patch) updates = self._get_updates(patch)
self._check_pool_readonly(addrpool.id) self._check_pool_readonly(addrpool)
self._validate_updates(addrpool, updates) self._validate_updates(addrpool, updates)
return pecan.request.dbapi.address_pool_update( return pecan.request.dbapi.address_pool_update(
address_pool_uuid, updates) address_pool_uuid, updates)
@ -560,11 +568,16 @@ class AddressPoolController(rest.RestController):
def delete(self, address_pool_uuid): def delete(self, address_pool_uuid):
"""Delete an IP address pool.""" """Delete an IP address pool."""
addrpool = self._get_one(address_pool_uuid) addrpool = self._get_one(address_pool_uuid)
self._check_pool_readonly(addrpool.id) self._check_pool_readonly(addrpool)
addresses = pecan.request.dbapi.addresses_get_by_pool( addresses = pecan.request.dbapi.addresses_get_by_pool(
addrpool.id) addrpool.id)
if addresses: if addresses:
if cutils.is_initial_config_complete(): # All the initial configured addresspools are not deleteable,
# except the system controller's network addresspool, which
# can be deleted/re-added during re-homing a subcloud to new
# system controllers
if cutils.is_initial_config_complete() and \
(addrpool.name not in SYSTEM_CONTROLLER_ADDRPOOLS):
raise exception.AddressPoolInUseByAddresses() raise exception.AddressPoolInUseByAddresses()
else: else:
# Must be a request as a result of network reconfiguration # Must be a request as a result of network reconfiguration