diff --git a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/network.py b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/network.py index a3b5df7ec6..32042f018a 100644 --- a/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/network.py +++ b/sysinv/sysinv/sysinv/sysinv/api/controllers/v1/network.py @@ -183,7 +183,7 @@ class NetworkController(rest.RestController): if network['type'] == constants.NETWORK_TYPE_MGMT: addresses = self._create_mgmt_network_address(pool) elif network['type'] == constants.NETWORK_TYPE_ADMIN: - addresses = self._create_admin_network_address() + addresses = self._create_admin_network_address(pool) elif network['type'] == constants.NETWORK_TYPE_PXEBOOT: addresses = self._create_pxeboot_network_address() elif network['type'] == constants.NETWORK_TYPE_CLUSTER_HOST: @@ -220,11 +220,22 @@ class NetworkController(rest.RestController): pool.gateway_address return addresses - def _create_admin_network_address(self): + def _create_admin_network_address(self, pool): addresses = collections.OrderedDict() addresses[constants.CONTROLLER_HOSTNAME] = None addresses[constants.CONTROLLER_0_HOSTNAME] = None addresses[constants.CONTROLLER_1_HOSTNAME] = None + + if pool.gateway_address is not None: + if utils.get_distributed_cloud_role() == \ + constants.DISTRIBUTED_CLOUD_ROLE_SUBCLOUD: + # In subcloud configurations, the admin gateway is used + # to communicate with the central cloud. + addresses[constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME] =\ + pool.gateway_address + else: + addresses[constants.CONTROLLER_GATEWAY] =\ + pool.gateway_address return addresses def _create_pxeboot_network_address(self): diff --git a/sysinv/sysinv/sysinv/sysinv/common/utils.py b/sysinv/sysinv/sysinv/sysinv/common/utils.py index 984adc3637..65b32853ec 100644 --- a/sysinv/sysinv/sysinv/sysinv/common/utils.py +++ b/sysinv/sysinv/sysinv/sysinv/common/utils.py @@ -1821,12 +1821,14 @@ def perform_distributed_cloud_config(dbapi, mgmt_iface_id): # the system controller gateway into the database. try: # Prefer admin network - dbapi.network_get_by_type( + sc_network = dbapi.network_get_by_type( constants.NETWORK_TYPE_ADMIN) cc_gtwy_addr_name = '%s-%s' % ( constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME, constants.NETWORK_TYPE_ADMIN) except exception.NetworkTypeNotFound: + sc_network = dbapi.network_get_by_type( + constants.NETWORK_TYPE_MGMT) cc_gtwy_addr_name = '%s-%s' % ( constants.SYSTEM_CONTROLLER_GATEWAY_IP_NAME, constants.NETWORK_TYPE_MGMT) @@ -1859,6 +1861,14 @@ def perform_distributed_cloud_config(dbapi, mgmt_iface_id): 'metric': 1 } + for ifnet in dbapi.interface_network_get_by_interface(mgmt_iface_id): + if ifnet.network_id == sc_network.id: + break + else: + LOG.warning("DC Config: Failed to retrieve network for interface " + "id %s", mgmt_iface_id) + return + try: dbapi.route_create(mgmt_iface_id, route) except exception.RouteAlreadyExists: diff --git a/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/api.py b/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/api.py index b2b16e7460..daeec3c0bd 100644 --- a/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/api.py +++ b/sysinv/sysinv/sysinv/sysinv/db/sqlalchemy/api.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Copyright (c) 2013-2022 Wind River Systems, Inc. +# Copyright (c) 2013-2023 Wind River Systems, Inc. # """SQLAlchemy storage backend.""" @@ -5515,7 +5515,10 @@ class Connection(api.Connection): session.add(route) session.flush() except db_exc.DBDuplicateEntry: - raise exception.RouteAlreadyExists(uuid=values['uuid']) + raise exception.RouteAlreadyExists( + network=route['network'], + prefix=route['prefix'], + gateway=route['gateway']) return self._route_get(values['uuid']) @db_objects.objectify(objects.route)