Skip to content

Commit

Permalink
Merge pull request #119 from knopki/feat-new-os-checks
Browse files Browse the repository at this point in the history
Support more OS checks
  • Loading branch information
blokhin committed Jul 27, 2023
2 parents 0f92ef1 + 1acb022 commit 68d8dc3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 38 deletions.
47 changes: 41 additions & 6 deletions yascheduler/remote_machine/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@

from .checks import (
check_is_debian,
check_is_debian_bullseye,
check_is_debian_buster,
check_is_debian_10,
check_is_debian_11,
check_is_debian_12,
check_is_debian_13,
check_is_debian_14,
check_is_debian_15,
check_is_debian_like,
check_is_linux,
check_is_windows,
check_is_windows7,
check_is_windows8,
check_is_windows10,
check_is_windows11,
check_is_windows12,
)
from .common import run, run_bg
from .linux_methods import (
Expand Down Expand Up @@ -90,16 +95,40 @@ class RemoteMachineAdapter(PRemoteMachineAdapter):
checks=(*debian_like_adapter.checks, check_is_debian),
)

debian_buster_adapter = evolve(
debian_10_adapter = evolve(
debian_adapter,
platform="debian-10",
checks=(*debian_adapter.checks, check_is_debian_buster),
checks=(*debian_adapter.checks, check_is_debian_10),
)

debian_bullseye_adapter = evolve(
debian_11_adapter = evolve(
debian_adapter,
platform="debian-11",
checks=(*debian_adapter.checks, check_is_debian_bullseye),
checks=(*debian_adapter.checks, check_is_debian_11),
)

debian_12_adapter = evolve(
debian_adapter,
platform="debian-12",
checks=(*debian_adapter.checks, check_is_debian_12),
)

debian_13_adapter = evolve(
debian_adapter,
platform="debian-13",
checks=(*debian_adapter.checks, check_is_debian_13),
)

debian_14_adapter = evolve(
debian_adapter,
platform="debian-14",
checks=(*debian_adapter.checks, check_is_debian_14),
)

debian_15_adapter = evolve(
debian_adapter,
platform="debian-15",
checks=(*debian_adapter.checks, check_is_debian_15),
)

windows_adapter = RemoteMachineAdapter(
Expand Down Expand Up @@ -138,3 +167,9 @@ class RemoteMachineAdapter(PRemoteMachineAdapter):
platform="windows-11",
checks=(*windows_adapter.checks, check_is_windows11),
)

windows12_adapter = evolve(
windows_adapter,
platform="windows-12",
checks=(*windows_adapter.checks, check_is_windows12),
)
46 changes: 20 additions & 26 deletions yascheduler/remote_machine/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"OS checks"

from functools import partial
from typing import Optional, Tuple

from asyncssh.connection import SSHClientConnection
Expand Down Expand Up @@ -38,16 +39,18 @@ async def check_is_debian(conn: SSHClientConnection) -> bool:
return os_release[0] == "debian" if os_release else False


async def check_is_debian_buster(conn: SSHClientConnection) -> bool:
"Check for Debian 10"
async def _check_debian_version(version: str, conn: SSHClientConnection) -> bool:
"Check for Debian version"
os_release = await _get_os_release(conn)
return os_release[2] == "10" if os_release else False
return os_release[2] == version if os_release else False


async def check_is_debian_bullseye(conn: SSHClientConnection) -> bool:
"Check for Debian 11"
os_release = await _get_os_release(conn)
return os_release[2] == "11" if os_release else False
check_is_debian_10 = partial(_check_debian_version, "10")
check_is_debian_11 = partial(_check_debian_version, "11")
check_is_debian_12 = partial(_check_debian_version, "12")
check_is_debian_13 = partial(_check_debian_version, "13")
check_is_debian_14 = partial(_check_debian_version, "14")
check_is_debian_15 = partial(_check_debian_version, "15")


@lru_cache
Expand All @@ -65,25 +68,16 @@ async def get_wmi_w32_os_caption(conn: SSHClientConnection) -> Optional[str]:
return str(proc.stdout)


async def check_is_windows7(conn: SSHClientConnection) -> bool:
"Check for Windows 7"
caption = await get_wmi_w32_os_caption(conn)
return "7" in caption if caption else False


async def check_is_windows8(conn: SSHClientConnection) -> bool:
"Check for Windows 8"
async def _check_is_windows_caption_version(
version: str, conn: SSHClientConnection
) -> bool:
"Check for Windows version in caption"
caption = await get_wmi_w32_os_caption(conn)
return "8" in caption if caption else False
return version in caption if caption else False


async def check_is_windows10(conn: SSHClientConnection) -> bool:
"Check for Windows 10"
caption = await get_wmi_w32_os_caption(conn)
return "10" in caption if caption else False


async def check_is_windows11(conn: SSHClientConnection) -> bool:
"Check for Windows 11"
caption = await get_wmi_w32_os_caption(conn)
return "11" in caption if caption else False
check_is_windows7 = partial(_check_is_windows_caption_version, "7")
check_is_windows8 = partial(_check_is_windows_caption_version, "8")
check_is_windows10 = partial(_check_is_windows_caption_version, "10")
check_is_windows11 = partial(_check_is_windows_caption_version, "11")
check_is_windows12 = partial(_check_is_windows_caption_version, "12")
22 changes: 16 additions & 6 deletions yascheduler/remote_machine/remote_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
from typing_extensions import Self

from .adapters import (
debian_10_adapter,
debian_11_adapter,
debian_12_adapter,
debian_13_adapter,
debian_14_adapter,
debian_15_adapter,
debian_adapter,
debian_bullseye_adapter,
debian_buster_adapter,
debian_like_adapter,
linux_adapter,
windows7_adapter,
windows8_adapter,
windows10_adapter,
windows11_adapter,
windows12_adapter,
windows_adapter,
)
from .exc import PlatformGuessFailed
Expand All @@ -47,15 +52,20 @@
)

ADAPTERS: Sequence[PRemoteMachineAdapter] = [
debian_bullseye_adapter,
debian_buster_adapter,
debian_10_adapter,
debian_11_adapter,
debian_12_adapter,
debian_13_adapter,
debian_14_adapter,
debian_15_adapter,
debian_adapter,
debian_like_adapter,
linux_adapter,
windows11_adapter,
windows10_adapter,
windows8_adapter,
windows11_adapter,
windows12_adapter,
windows7_adapter,
windows8_adapter,
windows_adapter,
]

Expand Down

0 comments on commit 68d8dc3

Please sign in to comment.