From 09dd74b36b95b68b315580dc392a83db8e4e58f1 Mon Sep 17 00:00:00 2001 From: Daniel Valent Date: Tue, 24 Oct 2023 23:14:40 +0200 Subject: [PATCH] SIMPLE-5974 Support for locked_compute_id (#64) --- virl2_client/models/lab.py | 2 ++ virl2_client/models/node.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/virl2_client/models/lab.py b/virl2_client/models/lab.py index b67eac7..c44011f 100644 --- a/virl2_client/models/lab.py +++ b/virl2_client/models/lab.py @@ -576,6 +576,7 @@ def _create_node_local( compute_id: str | None = None, resource_pool: ResourcePool | None = None, parameters: dict = {}, + locked_compute_id: str | None = None, ) -> Node: """Helper function to add a node to the client library.""" if tags is None: @@ -599,6 +600,7 @@ def _create_node_local( tags, resource_pool, parameters, + locked_compute_id, ) if compute_id is not None: node._compute_id = compute_id diff --git a/virl2_client/models/node.py b/virl2_client/models/node.py index 99ca51a..e0bcb3e 100644 --- a/virl2_client/models/node.py +++ b/virl2_client/models/node.py @@ -78,6 +78,7 @@ def __init__( tags: list[str], resource_pool: str | None, parameters: dict, + locked_compute_id: str | None, ) -> None: """ A VIRL2 node object representing a virtual machine that serves @@ -102,6 +103,8 @@ def __init__( :param tags: A list of tags associated with the node. :param resource_pool: The ID of the resource pool if the node is part of a resource pool. + :param locked_compute_id: The ID of the compute this node is locked to. + The node will not run on any other compute. """ self.lab = lab self._id = nid @@ -122,6 +125,7 @@ def __init__( self._tags = tags self._compute_id: str | None = None self._resource_pool = resource_pool + self._locked_compute_id = locked_compute_id self._stale = False self._last_sync_l3_address_time = 0.0 self._parameters = parameters @@ -494,6 +498,18 @@ def resource_pool(self) -> str: self.lab.sync_operational_if_outdated() return self._resource_pool + @property + def locked_compute_id(self) -> str | None: + """Return the ID of the compute this node is locked to.""" + self.lab.sync_operational_if_outdated() + return self._locked_compute_id + + @locked_compute_id.setter + def locked_compute_id(self, value) -> None: + """Set the ID of the compute this node should be locked to.""" + self._set_node_property("locked_compute_id", value) + self._locked_compute_id = value + @property def cpu_usage(self) -> int | float: """Return the CPU usage of this node.""" @@ -793,6 +809,7 @@ def sync_operational(self, response: dict[str, Any] = None): if response is None: url = self._url_for("operational") response = self._session.get(url).json() + self._locked_compute_id = response.get("locked_compute_id") operational = response.get("operational", {}) self._compute_id = operational.get("compute_id") self._resource_pool = operational.get("resource_pool")