add secondary address variable for public HAproxy config
This change adds the variable .... Test plan TBD Story: XXXXXX task: YYYYY Change-Id: I1b79f4e462ab34ab2aa7187d92460202fa15ae7e Signed-off-by: Andre Kantek <andrefernandozanella.kantek@windriver.com>
This commit is contained in:
parent
64021ed7da
commit
91eb494ebf
|
@ -3726,7 +3726,7 @@ def get_primary_address_by_name(dbapi, db_address_name, networktype, raise_exc=F
|
|||
LOG.info(f"address {db_address_name} not found, returning")
|
||||
if raise_exc:
|
||||
raise exception.AddressNotFoundByName(name=db_address_name)
|
||||
return address
|
||||
return None
|
||||
|
||||
# if there is a single entry, return here
|
||||
if len(address) == 1:
|
||||
|
@ -3759,6 +3759,67 @@ def get_primary_address_by_name(dbapi, db_address_name, networktype, raise_exc=F
|
|||
return address
|
||||
|
||||
|
||||
def get_secondary_address_by_name(dbapi, db_address_name, networktype, raise_exc=False):
|
||||
"""Search address by database name to retrieve the relevant address from
|
||||
the secondary pool, if multipĺe entries for the same name are found, the
|
||||
query will use the network's pool_uuid to get the address family (IPv4 or
|
||||
IPv6) related to the secondary.
|
||||
|
||||
:param dbapi: the database api reference
|
||||
:param db_address_name: the address name in the database
|
||||
:param networktype: the network type
|
||||
:param raise_exc: raise AddressNotFoundByName instead of returning None
|
||||
|
||||
:return: the address object if found, None otherwise
|
||||
"""
|
||||
address = None
|
||||
secondary_pool = None
|
||||
|
||||
if not db_address_name or not networktype:
|
||||
LOG.info(f"no db_address_name={db_address_name} or networktype={networktype} provided")
|
||||
return address
|
||||
|
||||
try:
|
||||
networks = dbapi.networks_get_by_type(networktype)
|
||||
if networks and len(networks) == 1:
|
||||
primary_pool = None
|
||||
if networks[0].pool_uuid:
|
||||
primary_pool = dbapi.address_pool_get(networks[0].pool_uuid)
|
||||
else:
|
||||
LOG.info(f"cannot find primary pool for {networks[0].name}:{networks[0].type}")
|
||||
|
||||
net_pools = dbapi.network_addrpool_get_by_network_id(networks[0].id)
|
||||
if len(net_pools) == 2 and primary_pool:
|
||||
for net_pool in net_pools:
|
||||
if net_pool.address_pool_uuid != primary_pool.uuid:
|
||||
# this is the secondary
|
||||
secondary_pool = dbapi.address_pool_get(net_pool.address_pool_uuid)
|
||||
else:
|
||||
LOG.info(f"network {networks[0].type} have {len(net_pools)} pools")
|
||||
else:
|
||||
LOG.info(f"we should only have one network obj for networktype={networktype}")
|
||||
|
||||
if secondary_pool:
|
||||
address = dbapi.address_get_by_name_and_family(db_address_name,
|
||||
secondary_pool.family)
|
||||
|
||||
except exception.AddressPoolNotFound:
|
||||
LOG.info(f"cannot find address pool for name={db_address_name} with"
|
||||
f" network type={networktype}")
|
||||
pass
|
||||
except exception.AddressNotFoundByNameAndFamily:
|
||||
LOG.info(f"cannot find address for name={db_address_name} with"
|
||||
f" network type={networktype}")
|
||||
pass
|
||||
except Exception as ex:
|
||||
LOG.info(f"get_secondary_address_by_name general exception: {str(ex)}")
|
||||
pass
|
||||
|
||||
if not address and raise_exc:
|
||||
raise exception.AddressNotFoundByName(name=db_address_name)
|
||||
return address
|
||||
|
||||
|
||||
def update_config_file(config_filepath: str, values_to_update: list):
|
||||
"""Update a config file with the desired information
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ class BasePuppet(object):
|
|||
|
||||
def _get_address_by_name(self, name, networktype):
|
||||
"""
|
||||
Retrieve an address entry by name and scoped by network type
|
||||
Retrieve a primary address entry by name and scoped by network type
|
||||
"""
|
||||
addresses = self.context.setdefault('_address_names', {})
|
||||
address_name = utils.format_address_name(name, networktype)
|
||||
|
@ -183,6 +183,21 @@ class BasePuppet(object):
|
|||
|
||||
return address
|
||||
|
||||
def _get_secondary_address_by_name(self, name, networktype):
|
||||
"""
|
||||
Retrieve a secondary address entry by name and scoped by network type
|
||||
"""
|
||||
addresses = self.context.setdefault('_sec_address_names', {})
|
||||
address_name = utils.format_address_name(name, networktype)
|
||||
address = addresses.get(address_name)
|
||||
if address is None:
|
||||
address = utils.get_secondary_address_by_name(self.dbapi,
|
||||
address_name,
|
||||
networktype, True)
|
||||
addresses[address_name] = address
|
||||
|
||||
return address
|
||||
|
||||
def _get_address_by_name_and_family(self, name, family, networktype):
|
||||
"""
|
||||
Retrieve an address entry by name and scoped by network type
|
||||
|
|
|
@ -321,6 +321,16 @@ class PlatformPuppet(base.BasePuppet):
|
|||
except exception.NotFound:
|
||||
pass
|
||||
|
||||
# add the secondary public address if exists
|
||||
try:
|
||||
sec_public_address = self._get_secondary_address_by_name(
|
||||
constants.CONTROLLER, constants.NETWORK_TYPE_OAM)
|
||||
if sec_public_address:
|
||||
config.update({'platform::haproxy::params::public_secondary_ip_address':
|
||||
sec_public_address.address})
|
||||
except exception.AddressNotFoundByName:
|
||||
pass
|
||||
|
||||
return config
|
||||
|
||||
def _get_sdn_config(self):
|
||||
|
|
Loading…
Reference in New Issue