-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adcli: adding class and methods for adcli
Adding adcli class, and methods including info, discovery, join
- Loading branch information
1 parent
7bcb65e
commit dfdf2a7
Showing
2 changed files
with
86 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,80 @@ | ||
"""Perform actions on Active Directory.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pytest_mh import MultihostHost, MultihostUtility | ||
from pytest_mh.cli import CLIBuilder, CLIBuilderArgs | ||
from pytest_mh.conn import ProcessResult | ||
from pytest_mh.utils.fs import LinuxFileSystem | ||
|
||
__all__ = [ | ||
"ADCLIUtils", | ||
] | ||
|
||
|
||
class ADCLI(MultihostUtility[MultihostHost]): | ||
""" | ||
Call commands from adcli | ||
""" | ||
|
||
def __init__(self, host: MultihostHost, fs: LinuxFileSystem) -> None: | ||
super().__init__(host) | ||
|
||
self.cli: CLIBuilder = self.host.cli | ||
"""Command line builder.""" | ||
|
||
self.fs: LinuxFileSystem = fs | ||
"""Filesystem utils.""" | ||
|
||
def info( | ||
self, | ||
domain: str, | ||
) -> str: | ||
""" | ||
Call ``adcli info `` with given arguments. | ||
:param domain: Displays discovered information about an Active Directory domain, defaults to None | ||
:type domain: str | None, | ||
:param domain_controller: Domain controller to connect, defaults to None | ||
:type domain_controller: str | None, optional | ||
""" | ||
args: CLIBuilderArgs = { | ||
"domain": (self.cli.option.POSITIONAL, domain), | ||
"domain_controller": (self.cli.option.POSITIONAL, domain_controller), | ||
} | ||
|
||
return self.host.conn.exec(["adcli", "info"] + self.cli.args(args)) | ||
|
||
def testjoin( | ||
self, | ||
domain: str| None = None, | ||
) -> ProcessResult: | ||
""" | ||
call ``adcli testjoin `` with given arguments. | ||
:param domain: Target Active Directory domain, defaults to None | ||
:type domain: str | None, optional | ||
:param domain_controller: Domain controller to connect | ||
:type domain_controller: str | None, optional | ||
""" | ||
args: CLIBuilderArgs = { | ||
"domain": (self.cli.option.VALUE, domain), | ||
"domain_controller": (self.cli.option.VALUE, domain_controller), | ||
"host_keytab": (self.cli.option.VALUE, host_keytab), | ||
} | ||
return self.host.conn.exec(["adcli", "testjoin"] + self.cli.args(args)) | ||
|
||
def join( | ||
self, | ||
domain: str, | ||
) -> str: | ||
""" | ||
call ``adcli join`` with given arguments. | ||
:param domain: Target Active Directory domain, defaults to None | ||
:type domain: str | None, optional | ||
""" | ||
args: CLIBuilderArgs = { | ||
"domain": (self.cli.option.POSITIONAL, domain), | ||
} | ||
self.host.conn.exec(["adcli", "join"] + self.cli.args(args)) |