Skip to content

Commit

Permalink
SIMPLE-5974 Support for locked_compute_id (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-valent authored Oct 24, 2023
1 parent 9e0cc94 commit 09dd74b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions virl2_client/models/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions virl2_client/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 09dd74b

Please sign in to comment.