Skip to content

Commit

Permalink
Update hyperv.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SRIKKANTH committed Feb 2, 2025
1 parent fbfcb60 commit 9e76932
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lisa/tools/hyperv.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,8 @@ def create_nat(self, name: str, ip_range: str) -> None:
)

def add_nat_mapping(self, nat_name: str, internal_ip: str) -> int:
# get next available NAT port
external_port = self._get_next_available_nat_port()
if self.get_nat_mapping_id(external_port):
raise LisaException(f"Mapping for port {external_port} already exists")

# create a new NAT
self.node.tools[PowerShell].run_cmdlet(
f"Add-NetNatStaticMapping -NatName {nat_name} -Protocol TCP "
Expand Down Expand Up @@ -551,7 +549,7 @@ def _get_next_available_nat_port(self) -> int:
# Start checking from the external forwarding port start and
# find the first available one
port = self._external_forwarding_port_start
while port in self._assigned_nat_ports:
while self.get_nat_mapping_id(port):
port += 1
self._assigned_nat_ports.add(port) # Assign this port
return port
Expand Down

0 comments on commit 9e76932

Please sign in to comment.