Skip to content

Commit

Permalink
Azure_hyperv transformer (#3402)
Browse files Browse the repository at this point in the history
* HyperVPreparationTransformer transformer added

hyperv_preparation transformer added

* Update hyperv_preparation.py

* Update hyperv_preparation.py

* Update hyperv_preparation.py
  • Loading branch information
SRIKKANTH authored Sep 5, 2024
1 parent e54c632 commit a104988
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions lisa/mixin_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import lisa.sut_orchestrator.azure.notifiers # noqa: F401
import lisa.sut_orchestrator.azure.transformers # noqa: F401
import lisa.transformers.disable_cloud_components # noqa: F401
import lisa.transformers.hyperv_preparation # noqa: F401
except ModuleNotFoundError as e:
print(f"azure package is not installed. [{e}]")

Expand Down
50 changes: 50 additions & 0 deletions lisa/transformers/hyperv_preparation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import Any, Dict, List, Type

from lisa import schema
from lisa.tools import PowerShell
from lisa.transformers.deployment_transformer import (
DeploymentTransformer,
DeploymentTransformerSchema,
)


class HyperVPreparationTransformer(DeploymentTransformer):
"""
This Transformer configures Windows Azure VM as a Hyper-V environment.
"""

@classmethod
def type_name(cls) -> str:
return "hyperv_preparation"

@classmethod
def type_schema(cls) -> Type[schema.TypedSchema]:
return DeploymentTransformerSchema

@property
def _output_names(self) -> List[str]:
return []

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,
)
return {}

0 comments on commit a104988

Please sign in to comment.