Skip to content

Commit

Permalink
Simplify 'hyperv_preparation' tranformer
Browse files Browse the repository at this point in the history
  • Loading branch information
SRIKKANTH committed Jan 2, 2025
1 parent d225696 commit 0709b05
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lisa/transformers/hyperv_preparation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from retry import retry
from typing import Any, Dict, List, Type

from lisa import schema
from lisa.tools import PowerShell
from lisa.tools.hyperv import HyperV
from lisa.transformers.deployment_transformer import (
DeploymentTransformer,
DeploymentTransformerSchema,
Expand Down Expand Up @@ -29,22 +31,13 @@ def _internal_run(self) -> Dict[str, Any]:
runbook: DeploymentTransformerSchema = self.runbook
assert isinstance(runbook, DeploymentTransformerSchema)
node = self._node
powershell = node.tools[PowerShell]
powershell.run_cmdlet(
"Install-WindowsFeature -Name DHCP,Hyper-V -IncludeManagementTools",
force_run=True,
)
node.reboot()
powershell.run_cmdlet(
"New-VMSwitch -Name 'InternalNAT' -SwitchType Internal",
force_run=True,
)
powershell.run_cmdlet(
"New-NetNat -Name 'InternalNAT' -InternalIPInterfaceAddressPrefix '192.168.0.0/24'", # noqa: E501
force_run=True,
)
powershell.run_cmdlet(
'New-NetIPAddress -IPAddress 192.168.0.1 -InterfaceIndex (Get-NetAdapter | Where-Object { $_.Name -like "*InternalNAT)" } | Select-Object -ExpandProperty ifIndex) -PrefixLength 24', # noqa: E501
force_run=True,
)

# Install Hyper-V feature and reboot the server.
hv = node.tools[HyperV]

# Setup Hyper-V networking
hv.setup_nat_networking(switch_name="InternalNAT", nat_name="InternalNAT")

# Configure DHCP
hv.configure_dhcp()
return {}

0 comments on commit 0709b05

Please sign in to comment.