From 0709b05024d5bac19fe58a0fde3b13e0f14fe3e4 Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Thu, 2 Jan 2025 14:43:31 +0530 Subject: [PATCH] Simplify 'hyperv_preparation' tranformer --- lisa/transformers/hyperv_preparation.py | 29 ++++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lisa/transformers/hyperv_preparation.py b/lisa/transformers/hyperv_preparation.py index e2ec20b7ca..1f49baa5d9 100644 --- a/lisa/transformers/hyperv_preparation.py +++ b/lisa/transformers/hyperv_preparation.py @@ -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, @@ -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 {}