mirror of
https://github.com/Break27/kvmd.git
synced 2026-02-06 10:26:38 +08:00
fix: host state update
This commit is contained in:
parent
20d57f45db
commit
c9f909add2
@ -9,13 +9,7 @@ from ... import aiotools
|
|||||||
|
|
||||||
|
|
||||||
class RemoteHost:
|
class RemoteHost:
|
||||||
def __init__(
|
def __init__(self, name, address='', encoding='utf-8', **kwargs) -> None:
|
||||||
self,
|
|
||||||
name,
|
|
||||||
address='',
|
|
||||||
encoding='utf-8',
|
|
||||||
**kwargs
|
|
||||||
) -> None:
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.address = address
|
self.address = address
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
@ -26,6 +20,7 @@ class RemoteHost:
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.online = False
|
self.online = False
|
||||||
|
self.outdated = True
|
||||||
self.last_seen = 0
|
self.last_seen = 0
|
||||||
|
|
||||||
def get_state(self) -> dict:
|
def get_state(self) -> dict:
|
||||||
@ -45,8 +40,9 @@ class RemoteHost:
|
|||||||
await process.wait()
|
await process.wait()
|
||||||
online = process.returncode == 0
|
online = process.returncode == 0
|
||||||
|
|
||||||
changed = self.online != online
|
changed = self.online != online or self.outdated
|
||||||
self.online = online
|
self.online = online
|
||||||
|
self.outdated = False
|
||||||
|
|
||||||
if self.online:
|
if self.online:
|
||||||
self.last_seen = time()
|
self.last_seen = time()
|
||||||
@ -95,9 +91,12 @@ class RemoteControl:
|
|||||||
await process.wait()
|
await process.wait()
|
||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
|
|
||||||
|
code = process.returncode
|
||||||
message = stdout.decode(host.encoding)
|
message = stdout.decode(host.encoding)
|
||||||
error = stderr.decode(host.encoding)
|
error = stderr.decode(host.encoding)
|
||||||
return (process.returncode, message, error)
|
|
||||||
|
if code == 0: host.outdated = True
|
||||||
|
return (code, message, error)
|
||||||
|
|
||||||
async def update(self) -> list[dict]:
|
async def update(self) -> list[dict]:
|
||||||
return [
|
return [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user