Add node refresh functionality to NodeView
- Implemented a private `_updater` method to fetch the next node's status. - Added `last_status` and `last_check` properties to retrieve the latest node status and check time. - Introduced a `refresh` property to update the node status and handle errors appropriately.
This commit is contained in:
20
oxi/view.py
20
oxi/view.py
@@ -14,6 +14,11 @@ class NodeView:
|
|||||||
self._base_url = base_url
|
self._base_url = base_url
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
|
def _updater(self) -> None:
|
||||||
|
response = self._session.get(f"{self._base_url}/node/next/{self.full_name}")
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.status_code
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ip(self):
|
def ip(self):
|
||||||
return self._data.get("ip")
|
return self._data.get("ip")
|
||||||
@@ -30,6 +35,21 @@ class NodeView:
|
|||||||
def model(self):
|
def model(self):
|
||||||
return self._data.get("model")
|
return self._data.get("model")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_status(self):
|
||||||
|
return self._data.get("last").get("status")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_check(self):
|
||||||
|
return self._data.get("last").get("start")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def refresh(self):
|
||||||
|
result = self._updater()
|
||||||
|
if result != 200:
|
||||||
|
raise ValueError(f"Failed to refresh node {self.full_name}")
|
||||||
|
return "OK"
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def config(self):
|
def config(self):
|
||||||
return NodeConfig(self._session, self.full_name, self.model, self._base_url)
|
return NodeConfig(self._session, self.full_name, self.model, self._base_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user