-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WindowsFeature tool for managing Windows features
WindowsFeature tool for managing Windows features
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
from typing import Any, List | ||
|
||
from lisa.executable import Tool | ||
from lisa.tools.powershell import PowerShell | ||
|
||
|
||
# WindowsFeature management tool for Windows. | ||
# It can install, uninstall, and check the status of Windows features. | ||
# This tool uses PowerShell to manage Windows features. | ||
class WindowsFeature(Tool): | ||
@property | ||
def command(self) -> str: | ||
return "" | ||
|
||
@property | ||
def can_install(self) -> bool: | ||
return False | ||
|
||
def _check_exists(self) -> bool: | ||
return True | ||
|
||
def _initialize(self, *args: Any, **kwargs: Any) -> None: | ||
self._powershell = self.node.tools[PowerShell] | ||
|
||
def install_feature(self, name: str) -> None: | ||
if self.is_installed(name): | ||
self._log.debug(f"Feature {name} is already installed.") | ||
return | ||
self._powershell.run_cmdlet( | ||
f"Install-WindowsFeature -Name {name} -IncludeManagementTools", | ||
force_run=True, | ||
) | ||
|
||
def uninstall_feature(self, name: str) -> None: | ||
if not self.is_installed(name): | ||
self._log.debug(f"Feature {name} is not installed.") | ||
return | ||
self._powershell.run_cmdlet( | ||
f"Uninstall-WindowsFeature -Name {name}", | ||
force_run=True, | ||
) | ||
|
||
def is_installed(self, name: str) -> bool: | ||
return ( | ||
self._powershell.run_cmdlet( | ||
f"Get-WindowsFeature -Name {name} | Select-Object -ExpandProperty Installed", # noqa: E501 | ||
force_run=True, | ||
).strip() | ||
== "True" | ||
) | ||
|
||
def get_installed_features(self) -> List[str]: | ||
return ( | ||
self._powershell.run_cmdlet( | ||
"Get-WindowsFeature | Where-Object { $_.Installed -eq $true } | Select-Object -ExpandProperty Name", # noqa: E501 | ||
force_run=True, | ||
) | ||
.strip() | ||
.split("\n") | ||
) | ||
|
||
def get_available_features(self) -> List[str]: | ||
return ( | ||
self._powershell.run_cmdlet( | ||
"Get-WindowsFeature | Where-Object { $_.Installed -eq $false } | Select-Object -ExpandProperty Name", # noqa: E501 | ||
force_run=True, | ||
) | ||
.strip() | ||
.split("\n") | ||
) |