-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(opennebula): support ETHx_ALIASn_IP/MASK for anycast addresses #6876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,43 @@ def get_field( | |
| # allow empty string to return the default. | ||
| return default if val in (None, "") else val | ||
|
|
||
| def get_alias_addresses(self, c_dev: str) -> List[str]: | ||
| """Return list of alias IP/prefix strings for context device c_dev. | ||
|
|
||
| Scans context for ETHx_ALIASn_IP / ETHx_ALIASn_MASK keys, where x | ||
| matches c_dev (e.g. 'ETH0'). Missing MASK defaults to /32. | ||
| Stops at the first gap in the alias index sequence and warns if | ||
| further alias indices exist beyond that gap, since that likely | ||
| indicates a misconfigured context. | ||
| """ | ||
| aliases: List[str] = [] | ||
| prefix = c_dev.upper() + "_ALIAS" | ||
| idx = 0 | ||
| while True: | ||
| ip_key = "%s%d_IP" % (prefix, idx) | ||
| ip = self.context.get(ip_key) | ||
| if not ip: | ||
| break | ||
| mask_key = "%s%d_MASK" % (prefix, idx) | ||
| mask = self.context.get(mask_key) or "255.255.255.255" | ||
| net_prefix = str(net.ipv4_mask_to_net_prefix(mask)) | ||
| aliases.append("%s/%s" % (ip, net_prefix)) | ||
| idx += 1 | ||
|
|
||
| key_re = re.compile(r"^%s(\d+)_IP$" % re.escape(prefix)) | ||
| skipped = sorted( | ||
| int(m.group(1)) for m in map(key_re.match, self.context) if m | ||
| ) | ||
| skipped = [i for i in skipped if i >= idx] | ||
|
Comment on lines
+303
to
+319
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels a bit like we are processing the data in self.context twice through two separate loops which makes it a teeny bit harder to maintain when we look at this in the future. Could we instead try processing these keys once? |
||
| if skipped: | ||
| LOG.warning( | ||
| "Ignoring %s: found gap at %s%d_IP", | ||
| ", ".join("%s%d_IP" % (prefix, i) for i in skipped), | ||
|
Comment on lines
+322
to
+323
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| prefix, | ||
| idx, | ||
| ) | ||
| return aliases | ||
|
|
||
| def gen_conf(self) -> Dict[str, Any]: | ||
| netconf: Dict[str, Any] = {"version": 2, "ethernets": {}} | ||
|
|
||
|
|
@@ -311,6 +348,11 @@ def gen_conf(self) -> Dict[str, Any]: | |
| prefix = str(net.ipv4_mask_to_net_prefix(mask)) | ||
| devconf["addresses"].append(self.get_ip(c_dev, mac) + "/" + prefix) | ||
|
|
||
| # Set alias (anycast) IPv4 addresses | ||
| alias_addresses: List[str] = self.get_alias_addresses(c_dev) | ||
| if alias_addresses: | ||
| devconf["addresses"].extend(alias_addresses) | ||
|
|
||
| # Set IPv6 Global and ULA address | ||
| addresses6 = self.get_ip6(c_dev) | ||
| if addresses6: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.