Skip to content

Commit 2619f48

Browse files
committed
fixup! feat(oracle): allow for specifying network configuration
1 parent 02689c5 commit 2619f48

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

pycloudlib/oci/cloud.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ def find_compatible_subnet(self, networking_config: NetworkingConfig) -> str:
350350
`PycloudlibError` if unable to determine `subnet_id` for the given `networking_config`
351351
"""
352352
subnet_id = get_subnet_id(
353-
self.network_client,
354-
self.compartment_id,
355-
self.availability_domain,
353+
network_client=self.network_client,
354+
compartment_id=self.compartment_id,
355+
availability_domain=self.availability_domain,
356356
vcn_name=self.vcn_name,
357357
networking_config=networking_config,
358358
)

pycloudlib/oci/instance.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ def add_network_interface(
285285
found.
286286
subnet_name: Name of the subnet to add the NIC to. If provided, this subnet will
287287
blindly be selected and networking_config will be ignored.
288+
289+
Returns:
290+
str: The private IP address of the added network interface.
288291
"""
289292
if subnet_name:
290293
if networking_config:
@@ -321,13 +324,25 @@ def add_network_interface(
321324
"Newly attached vnic data:\n%s",
322325
vnic_data,
323326
)
327+
try:
328+
new_ip = vnic_data.private_ip or vnic_data.ipv6_addresses[0]
329+
except IndexError:
330+
err_msg = (
331+
"Unexpected error occurred when trying to retrieve local IP address of the "
332+
"newly attached NIC. No private IP or IPv6 address found."
333+
)
334+
self._log.error(
335+
err_msg + "Full vnic data for debugging purposes:\n%s",
336+
vnic_data,
337+
)
338+
raise PycloudlibError(err_msg)
324339
self._log.info(
325340
"Added network interface with IP %s to instance %s on nic #%s",
326-
vnic_data.private_ip or vnic_data.ipv6_addresses[0],
341+
new_ip,
327342
self.instance_id,
328343
nic_index,
329344
)
330-
return vnic_data.private_ip or vnic_data.ipv6_addresses[0]
345+
return new_ip
331346

332347
def remove_network_interface(self, ip_address: str):
333348
"""Remove network interface based on IP address.

pycloudlib/oci/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ def _subnet_is_compatible(
149149
From the networking_config, we have the following restrictions:
150150
151151
private:
152-
- if private is true, then `prohibit_internet_ingress` must be True
153-
- if false (public), then `prohibit_internet_ingress` must be False
152+
- the subnet must match the given privacy setting
154153
155154
networking_type:
156155
- if None or AUTO, then the subnet is compatible
@@ -234,12 +233,12 @@ def get_subnet_id(
234233
Returns:
235234
id of the subnet selected
236235
Raises:
237-
`PycloudlibError` if unable to determine `subnet_id` for `availability_domain`,
236+
`PycloudlibError` if unable to determine `subnet_id` for `availabilitjy_domain`,
238237
or if no relevant VCNs are found in the compartment.
239238
"""
240239
if not networking_config:
241240
networking_config = NetworkingConfig()
242-
log.debug(
241+
log.warning(
243242
"No networking config provided. Using default networking config of "
244243
"networking_type: %s, private: %s",
245244
networking_config.networking_type,

tests/integration_tests/oracle/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def oci_cloud():
2323
yield oracle_cloud
2424

2525

26-
# @a-dubs - These are pre-existing subnets that I have created in my Oracle Cloud account.
26+
# These are pre-existing subnets that I have created in my Oracle Cloud account.
2727
# this is not immediately reproducible by others, but all they need to do is create 3 subnets
2828
# that match the below configurations and update the following variables with the new subnet ids.
2929
# This is the only way I could feel confident that my subnet selection logic is working with the

tests/unit_tests/oci/test_utils.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -538,59 +538,56 @@ def test_get_subnet_id_parameterized(
538538

539539

540540
class TestGenerateCreateVnicDetails:
541+
subnet_id = "subnet_id"
542+
541543
def test_generate_create_vnic_details_default(self):
542544
"""Test generate_create_vnic_details with default parameters."""
543-
subnet_id = "subnet_id"
544-
vnic_details = generate_create_vnic_details(subnet_id)
545-
assert vnic_details.subnet_id == subnet_id
545+
546+
vnic_details = generate_create_vnic_details(self.subnet_id)
547+
assert vnic_details.subnet_id == self.subnet_id
546548
assert vnic_details.assign_ipv6_ip is False
547549
assert vnic_details.assign_public_ip is True
548550

549551
def test_generate_create_vnic_details_ipv4_public(self):
550552
"""Test generate_create_vnic_details with IPv4 public configuration."""
551-
subnet_id = "subnet_id"
552553
networking_config = NetworkingConfig(networking_type=NetworkingType.IPV4, private=False)
553-
vnic_details = generate_create_vnic_details(subnet_id, networking_config)
554-
assert vnic_details.subnet_id == subnet_id
554+
vnic_details = generate_create_vnic_details(self.subnet_id, networking_config)
555+
assert vnic_details.subnet_id == self.subnet_id
555556
assert vnic_details.assign_ipv6_ip is False
556557
assert vnic_details.assign_public_ip is True
557558

558559
def test_generate_create_vnic_details_ipv4_private(self):
559560
"""Test generate_create_vnic_details with IPv4 private configuration."""
560-
subnet_id = "subnet_id"
561561
networking_config = NetworkingConfig(networking_type=NetworkingType.IPV4, private=True)
562-
vnic_details = generate_create_vnic_details(subnet_id, networking_config)
563-
assert vnic_details.subnet_id == subnet_id
562+
vnic_details = generate_create_vnic_details(self.subnet_id, networking_config)
563+
assert vnic_details.subnet_id == self.subnet_id
564564
assert vnic_details.assign_ipv6_ip is False
565565
assert vnic_details.assign_public_ip is False
566566

567567
def test_generate_create_vnic_details_ipv6(self):
568568
"""Test generate_create_vnic_details with IPv6 configuration."""
569-
subnet_id = "subnet_id"
570569
networking_config = NetworkingConfig(networking_type=NetworkingType.IPV6)
571-
vnic_details = generate_create_vnic_details(subnet_id, networking_config)
572-
assert vnic_details.subnet_id == subnet_id
570+
vnic_details = generate_create_vnic_details(self.subnet_id, networking_config)
571+
assert vnic_details.subnet_id == self.subnet_id
573572
assert vnic_details.assign_ipv6_ip is True
574573
assert vnic_details.assign_public_ip is False
575574

576575
def test_generate_create_vnic_details_dual_stack_public(self):
577576
"""Test generate_create_vnic_details with dual stack public configuration."""
578-
subnet_id = "subnet_id"
579577
networking_config = NetworkingConfig(
580578
networking_type=NetworkingType.DUAL_STACK, private=False
581579
)
582-
vnic_details = generate_create_vnic_details(subnet_id, networking_config)
583-
assert vnic_details.subnet_id == subnet_id
580+
vnic_details = generate_create_vnic_details(self.subnet_id, networking_config)
581+
assert vnic_details.subnet_id == self.subnet_id
584582
assert vnic_details.assign_ipv6_ip is True
585583
assert vnic_details.assign_public_ip is True
586584

587585
def test_generate_create_vnic_details_dual_stack_private(self):
588586
"""Test generate_create_vnic_details with dual stack private configuration."""
589-
subnet_id = "subnet_id"
590587
networking_config = NetworkingConfig(
591588
networking_type=NetworkingType.DUAL_STACK, private=True
592589
)
593-
vnic_details = generate_create_vnic_details(subnet_id, networking_config)
594-
assert vnic_details.subnet_id == subnet_id
590+
vnic_details = generate_create_vnic_details(self.subnet_id, networking_config)
591+
assert vnic_details.subnet_id == self.subnet_id
595592
assert vnic_details.assign_ipv6_ip is True
596593
assert vnic_details.assign_public_ip is False

0 commit comments

Comments
 (0)