Skip to content

Commit

Permalink
Restructure config to prepare for MAC address changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erl-hpe committed Feb 21, 2025
1 parent d025bb7 commit 3d40ae1
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 78 deletions.
20 changes: 11 additions & 9 deletions vtds_cluster_kvm/private/api_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,20 @@ def __network_by_name(self, network_name):
)
return self.networks_by_name[network_name]

def __l3_config(self, network_name, family):
"""Get the l3_info block for the specified address family from
def __address_family(self, network_name, family):
"""Get the address_family block for the specified address family from
the network of the specified name. If the network doesn't
exist raise an exception. If there is no matching l3_info,
exist raise an exception. If there is no matching address_family,
return None.
"""
network = self.__network_by_name(network_name)
candidates = [
l3_info
for _, l3_info in network.get('l3_configs', {}).items()
if l3_info.get('family', None) == family
address_family
for _, address_family in network.get(
'address_families', {}
).items()
if address_family.get('family', None) == family
]
return candidates[0] if candidates else None

Expand All @@ -212,10 +214,10 @@ def application_metadata(self, network_name):
return network.get('application_metadata', {})

def ipv4_cidr(self, network_name):
l3_config = self.__l3_config(network_name, 'AF_INET')
if l3_config is None:
address_family = self.__address_family(network_name, 'AF_INET')
if address_family is None:
return None
return l3_config.get('cidr', None)
return address_family.get('cidr', None)

def non_cluster_network(self, network_name):
network = self.__network_by_name(network_name)
Expand Down
27 changes: 15 additions & 12 deletions vtds_cluster_kvm/private/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,21 @@ def __net_name(network):
)
return netname

def __get_l3_config(self, network, family):
def __get_address_family(self, network, family):
"""Look up the L3 configuration for the specified address
family in the specified network.
"""
l3_configs = network.get('l3_configs', None)
if l3_configs is None:
address_families = network.get('address_families', None)
if address_families is None:
raise ContextualError(
"configuration error: network '%s' has no "
"'l3_configs' section" % self.__net_name(network)
"'address_families' section" % self.__net_name(network)
)
candidates = [
l3_config
for _, l3_config in l3_configs.items()
if l3_config.get('family', None) == family
address_family
for _, address_family in address_families.items()
if address_family.get('family', None) == family
]
if not candidates:
raise ContextualError(
Expand All @@ -223,8 +223,8 @@ def __get_ipv4_cidr(self, network):
there is none.
"""
l3_config = self.__get_l3_config(network, 'AF_INET')
cidr = l3_config.get('cidr', None)
address_family = self.__get_address_family(network, 'AF_INET')
cidr = address_family.get('cidr', None)
if cidr is None:
raise ContextualError(
"configuration error: AF_INET L3 configuration for "
Expand Down Expand Up @@ -272,8 +272,10 @@ def __add_host_blade_net(self):
)
# Connect the host_blade_network to all blades of all classes.
blade_classes = virtual_blades.blade_classes()
l3_config = self.__get_l3_config(host_blade_network, 'AF_INET')
l3_config['connected_blades'] = [
address_family = self.__get_address_family(
host_blade_network, 'AF_INET'
)
address_family['connected_blades'] = [
{
'blade_class': blade_class,
'blade_instances': [
Expand Down Expand Up @@ -343,7 +345,8 @@ def __random_mac(prefix="52:54:00"):
"""Generate a MAC address using a specified prefix specified
as a string containing colon separated hexadecimal octet
values for the length of the desired prefix. By default use
the KVM reserved prefix '52:54:00'.
the KVM reserved, locally administered, unicast prefix
'52:54:00'.
"""
try:
Expand Down
32 changes: 19 additions & 13 deletions vtds_cluster_kvm/private/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ cluster:
# Virtual Network. Since this is a blade_local network, there is
# no underlying interconnect. Set this to null.
blade_interconnect: null
l3_configs:
address_families:
ipv4:
family: AF_INET
# By default we take a /16 network from a (hopefully) low
Expand Down Expand Up @@ -117,7 +117,22 @@ cluster:
# The name of the Blade Interconnect network underlying this
# Virtual Network. Set this to null for blade-local networks.
blade_interconnect: base-interconnect
l3_configs:
# Connected blades lists the blades that are connected to
# the Virtual Network (by default no blade is connected). If
# you are going to have a blade provided DHCP server on one
# of the blades for this network, that blade (class and
# instance) must be a connected blade. For a blade-local
# network to exist on a blade, that blade (class and
# instance) must be in the set of connected blades.
connected_blades:
# Connected blades are grouped by blade class and
# identified by instance numbers.
- blade_class: base-blade
blade_instances:
- 0
# Configuration for things that are specific to a given address
# family being used on the network.
address_families:
ipv4:
family: AF_INET
cidr: 10.254.0.0/16
Expand All @@ -126,19 +141,10 @@ cluster:
- 10.1.1.1
- 10.1.1.2
- 10.1.1.3
# Connected blades lists the blades that are connected to
# the Virtual Network (by default no blade is connected). If
# you are going to have a blade provided DHCP server on one
# of the blades for this network, that blade (class and
# instance) must be a connected blade. For a blade-local
# network to exist on a blade, that blade (class and
# instance) must be in the set of connected blades.
# Connected blades are assigned IP addresses by blade class
# which are indexed by instance number.
connected_blades:
# Connected blades are grouped by blade class and
# identified by instance numbers.
- blade_class: base-blade
blade_instances:
- 0
# Each connected blade instance is assigned an IP
# address on the Virtual Network using the following
# list of blade IPs matched one-to-one with blade
Expand Down
Loading

0 comments on commit 3d40ae1

Please sign in to comment.