Skip to content

Commit

Permalink
fix(oracle): fix subnet selection logic
Browse files Browse the repository at this point in the history
When a subnet is not associated with an availability domain (AD),
we should not ignore the subnet just because it does not match our
configured AD. This change fixes the subnet selection logic to first
check if the subnet is associated with an AD before checking if it
matches the configured AD.

Before this change, the subnet selection logic was flawed and would
say it was using a certain subnet, but due to this bad AD logic, it
would actually not actually use the subnet it said it was using.
  • Loading branch information
a-dubs committed Jan 29, 2025
1 parent fb7af6d commit ab70e6b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions pycloudlib/oci/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,33 @@ def get_subnet_id(
if len(vcns) > 1:
raise PycloudlibError(f"Found multiple vcns with name: {vcn_name}")
vcn_id = vcns[0].id
chosen_vcn_name = vcns[0].display_name
else: # if no vcn_name specified, use most recently created vcn
vcn_id = network_client.list_vcns(compartment_id, retry_strategy=retry_strategy).data[0].id
vcns = network_client.list_vcns(compartment_id, retry_strategy=retry_strategy).data
if len(vcns) == 0:
raise PycloudlibError("No VCNs found in compartment")
vcn_id = vcns[0].id
chosen_vcn_name = vcns[0].display_name


subnets = network_client.list_subnets(
compartment_id, vcn_id=vcn_id, retry_strategy=retry_strategy
).data
subnet_id = None
for subnet in subnets:
if subnet.prohibit_internet_ingress: # skip subnet if it's private
log.debug("Ignoring private subnet: %s", subnet.id)
log.debug("Ignoring private subnet: %s [id: %s]", subnet.display_name, subnet.id,)
continue
if subnet.availability_domain and subnet.availability_domain != availability_domain:
log.debug(
"Ignoring public subnet in different availability domain: %s [id: %s]",
subnet.display_name,
subnet.id,
)
continue
log.debug("Using public subnet: %s", subnet.id)
if subnet.availability_domain == availability_domain:
subnet_id = subnet.id
break
else:
subnet_id = subnets[0].id
log.info("Using public subnet: %s [id: %s]", subnet.display_name, subnet.id)
subnet_id = subnet.id
break
if not subnet_id:
raise PycloudlibError(f"Unable to determine subnet id for domain: {availability_domain}")
raise PycloudlibError(f"Unable to find suitable subnet in VCN {chosen_vcn_name}")
return subnet_id

0 comments on commit ab70e6b

Please sign in to comment.