Skip to content

Commit 2b64d5a

Browse files
SIMPLE-6506 removed/deprecated offline mode leftovers (#97)
1 parent a1f0975 commit 2b64d5a

10 files changed

+119
-61
lines changed

tests/test_client_library.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def test_import_lab_from_path_virl(
7777

7878
cl._session.post.assert_called_once_with(
7979
"import/virl-1x",
80+
params=None,
8081
content="<?xml version='1.0' encoding='UTF-8'?>",
8182
)
8283
cl._session.post.assert_called_once()

virl2_client/event_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def _handle_element_created(self, event: Event) -> None:
305305

306306
def _handle_element_modified(self, event: Event) -> None:
307307
if event.element_type == "node":
308-
event.element.update(
308+
event.element._update(
309309
event.data, exclude_configurations=False, push_to_server=False
310310
)
311311

virl2_client/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
node and image definition and helper classes for automation
2323
and authentication."""
2424

25+
from .annotation import Annotation
2526
from .auth_management import AuthManagement
2627
from .authentication import TokenAuth
2728
from .groups import GroupManagement
@@ -48,4 +49,5 @@
4849
"TokenAuth",
4950
"ResourcePoolManagement",
5051
"AuthManagement",
52+
"Annotation",
5153
)

virl2_client/models/annotation.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from typing import TYPE_CHECKING, Any, Literal
2525

2626
from ..exceptions import InvalidProperty
27-
from ..utils import check_stale, get_url_from_template, locked
27+
from ..utils import _deprecated_argument, check_stale, get_url_from_template, locked
2828
from ..utils import property_s as property
2929

3030
if TYPE_CHECKING:
@@ -353,17 +353,25 @@ def _remove_on_server(self) -> None:
353353
url = self._url_for("annotation")
354354
self._session.delete(url)
355355

356+
def update(self, annotation_data: dict[str, Any], push_to_server=None) -> None:
357+
"""
358+
Update annotation properties.
359+
360+
:param annotation_data: JSON dict with new annotation property:value pairs.
361+
:param push_to_server: DEPRECATED: Was only used by internal methods
362+
and should otherwise always be True.
363+
"""
364+
_deprecated_argument(self.update, push_to_server, "push_to_server")
365+
self._update(annotation_data, push_to_server=True)
366+
356367
@check_stale
357368
@locked
358-
def update(
359-
self, annotation_data: dict[str, Any], push_to_server: bool = True
360-
) -> None:
369+
def _update(self, annotation_data: dict[str, Any], push_to_server: bool) -> None:
361370
"""
362371
Update annotation properties.
363372
364373
:param annotation_data: JSON dict with new annotation property:value pairs.
365374
:param push_to_server: Whether to push the changes to the server.
366-
Defaults to True; should only be False when used by internal methods.
367375
"""
368376
if annotation_data.get("type") not in (None, self._type):
369377
raise ValueError("Can't change annotation type.")
@@ -424,7 +432,7 @@ def __init__(
424432
self._y2 = 100
425433
self._rotation = 0
426434
if annotation_data:
427-
self.update(annotation_data, push_to_server=False)
435+
self._update(annotation_data, push_to_server=False)
428436

429437
@property
430438
def border_radius(self) -> int:
@@ -499,7 +507,7 @@ def __init__(
499507
self._y2 = 100
500508
self._rotation = 0
501509
if annotation_data:
502-
self.update(annotation_data, push_to_server=False)
510+
self._update(annotation_data, push_to_server=False)
503511

504512
@property
505513
def x2(self) -> int:
@@ -562,7 +570,7 @@ def __init__(
562570
self._line_start = None
563571
self._line_end = None
564572
if annotation_data:
565-
self.update(annotation_data, push_to_server=False)
573+
self._update(annotation_data, push_to_server=False)
566574

567575
@property
568576
def x2(self) -> int:
@@ -643,7 +651,7 @@ def __init__(
643651
self._text_size = 12
644652
self._text_unit = "pt"
645653
if annotation_data:
646-
self.update(annotation_data, push_to_server=False)
654+
self._update(annotation_data, push_to_server=False)
647655

648656
@property
649657
def rotation(self) -> int:

virl2_client/models/lab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ def _update_elements(
17361736
for node_id in kept_nodes:
17371737
node = self._find_node_in_topology(node_id, topology)
17381738
lab_node = self._nodes[node_id]
1739-
lab_node.update(node, exclude_configurations, push_to_server=False)
1739+
lab_node._update(node, exclude_configurations, push_to_server=False)
17401740

17411741
# For now, can't update interface data server-side, this will change with tags
17421742
# for interface_id in kept_interfaces:
@@ -1750,7 +1750,7 @@ def _update_elements(
17501750
for ann_id in kept_annotations:
17511751
annotation = self._find_annotation_in_topology(ann_id, topology)
17521752
lab_annotation = self._annotations[ann_id]
1753-
lab_annotation.update(annotation, push_to_server=False)
1753+
lab_annotation._update(annotation, push_to_server=False)
17541754

17551755
@locked
17561756
def update_lab_properties(self, properties: dict[str, Any]):

virl2_client/models/node.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from typing import TYPE_CHECKING, Any
2929

3030
from ..exceptions import InterfaceNotFound
31-
from ..utils import check_stale, get_url_from_template, locked
31+
from ..utils import _deprecated_argument, check_stale, get_url_from_template, locked
3232
from ..utils import property_s as property
3333

3434
if TYPE_CHECKING:
@@ -879,9 +879,26 @@ def map_l3_addresses_to_interfaces(
879879
}
880880
self._last_sync_l3_address_time = time.time()
881881

882+
def update(
883+
self,
884+
node_data: dict[str, Any],
885+
exclude_configurations: bool,
886+
push_to_server=None,
887+
) -> None:
888+
"""
889+
Update the node with the provided data.
890+
891+
:param node_data: The data to update the node with.
892+
:param exclude_configurations: Whether to exclude configuration updates.
893+
:param push_to_server: DEPRECATED: Was only used by internal methods
894+
and should otherwise always be True.
895+
"""
896+
_deprecated_argument(self.update, push_to_server, "push_to_server")
897+
self._update(node_data, exclude_configurations, push_to_server=True)
898+
882899
@check_stale
883900
@locked
884-
def update(
901+
def _update(
885902
self,
886903
node_data: dict[str, Any],
887904
exclude_configurations: bool,
@@ -893,7 +910,6 @@ def update(
893910
:param node_data: The data to update the node with.
894911
:param exclude_configurations: Whether to exclude configuration updates.
895912
:param push_to_server: Whether to push the changes to the server.
896-
Defaults to True; should only be False when used by internal methods.
897913
"""
898914
if push_to_server:
899915
self._set_node_properties(node_data)

virl2_client/models/resource_pools.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from typing import TYPE_CHECKING, Any, Dict, Iterable
2727

2828
from ..exceptions import InvalidProperty
29-
from ..utils import get_url_from_template
29+
from ..utils import _deprecated_argument, get_url_from_template
3030

3131
if TYPE_CHECKING:
3232
import httpx
@@ -93,7 +93,7 @@ def sync_resource_pools(self) -> None:
9393
pool_id = res_pool.pop("id")
9494
res_pool["pool_id"] = pool_id
9595
if pool_id in self._resource_pools:
96-
self._resource_pools[pool_id].update(res_pool, push_to_server=False)
96+
self._resource_pools[pool_id]._update(res_pool, push_to_server=False)
9797
else:
9898
self._add_resource_pool_local(**res_pool)
9999
res_pool_ids.append(pool_id)
@@ -417,13 +417,23 @@ def remove(self) -> None:
417417
url = self._url_for("resource_pool")
418418
self._session.delete(url)
419419

420-
def update(self, pool_data: dict[str, Any], push_to_server: bool = True):
420+
def update(self, pool_data: dict[str, Any], push_to_server=None) -> None:
421+
"""
422+
Update multiple properties of the pool at once.
423+
424+
:param pool_data: A dictionary of the properties to update.
425+
:param push_to_server: DEPRECATED: Was only used by internal methods
426+
and should otherwise always be True.
427+
"""
428+
_deprecated_argument(self.update, push_to_server, "push_to_server")
429+
self._update(pool_data, push_to_server=True)
430+
431+
def _update(self, pool_data: dict[str, Any], push_to_server: bool = True) -> None:
421432
"""
422433
Update multiple properties of the pool at once.
423434
424435
:param pool_data: A dictionary of the properties to update.
425436
:param push_to_server: Whether to push the changes to the server.
426-
Defaults to True; should only be False when used by internal methods.
427437
"""
428438
if push_to_server:
429439
self._set_resource_pool_properties(pool_data)

virl2_client/models/system.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from virl2_client.exceptions import ControllerNotFound, InvalidMacAddressBlock
2828

29-
from ..utils import get_url_from_template
29+
from ..utils import _deprecated_argument, get_url_from_template
3030

3131
if TYPE_CHECKING:
3232
import httpx
@@ -136,7 +136,7 @@ def maintenance_notice(self, notice: SystemNotice | None) -> None:
136136
else:
137137
notice = self._system_notices.get(resolved["id"])
138138
if notice is not None and resolved is not None:
139-
notice.update(resolved, push_to_server=False)
139+
notice._update(resolved, push_to_server=False)
140140
self._maintenance_notice = notice
141141

142142
def sync_compute_hosts_if_outdated(self) -> None:
@@ -167,7 +167,7 @@ def sync_compute_hosts(self) -> None:
167167
compute_id = compute_host.pop("id")
168168
compute_host["compute_id"] = compute_id
169169
if compute_id in self._compute_hosts:
170-
self._compute_hosts[compute_id].update(
170+
self._compute_hosts[compute_id]._update(
171171
compute_host, push_to_server=False
172172
)
173173
else:
@@ -188,7 +188,7 @@ def sync_system_notices(self) -> None:
188188
for system_notice in system_notices:
189189
notice_id = system_notice.get("id")
190190
if notice_id in self._system_notices:
191-
self._system_notices[notice_id].update(
191+
self._system_notices[notice_id]._update(
192192
system_notice, push_to_server=False
193193
)
194194
else:
@@ -512,13 +512,23 @@ def remove(self) -> None:
512512
url = self._url_for("compute_host")
513513
self._session.delete(url)
514514

515-
def update(self, host_data: dict[str, Any], push_to_server: bool = True) -> None:
515+
def update(self, host_data: dict[str, Any], push_to_server=None) -> None:
516+
"""
517+
Update the compute host with the given data.
518+
519+
:param host_data: The data to update the compute host.
520+
:param push_to_server: DEPRECATED: Was only used by internal methods
521+
and should otherwise always be True.
522+
"""
523+
_deprecated_argument(self.update, push_to_server, "push_to_server")
524+
self._update(host_data, push_to_server=True)
525+
526+
def _update(self, host_data: dict[str, Any], push_to_server: bool = True) -> None:
516527
"""
517528
Update the compute host with the given data.
518529
519530
:param host_data: The data to update the compute host.
520531
:param push_to_server: Whether to push the changes to the server.
521-
Defaults to True; should only be False when used by internal methods.
522532
"""
523533
if push_to_server:
524534
self._set_compute_host_properties(host_data)
@@ -545,7 +555,7 @@ def _set_compute_host_properties(self, host_data: dict[str, Any]) -> None:
545555
"""
546556
url = self._url_for("compute_host")
547557
new_data = self._session.patch(url, json=host_data).json()
548-
self.update(new_data, push_to_server=False)
558+
self._update(new_data, push_to_server=False)
549559

550560

551561
class SystemNotice:
@@ -642,13 +652,23 @@ def remove(self) -> None:
642652
url = self._url_for("notice")
643653
self._session.delete(url)
644654

645-
def update(self, notice_data: dict[str, Any], push_to_server: bool = True) -> None:
655+
def update(self, notice_data: dict[str, Any], push_to_server=None) -> None:
656+
"""
657+
Update the system notice with the given data.
658+
659+
:param notice_data: The data to update the system notice with.
660+
:param push_to_server: DEPRECATED: Was only used by internal methods
661+
and should otherwise always be True.
662+
"""
663+
_deprecated_argument(self.update, push_to_server, "push_to_server")
664+
self._update(notice_data, push_to_server=True)
665+
666+
def _update(self, notice_data: dict[str, Any], push_to_server: bool = True) -> None:
646667
"""
647668
Update the system notice with the given data.
648669
649670
:param notice_data: The data to update the system notice with.
650671
:param push_to_server: Whether to push the changes to the server.
651-
Defaults to True; should only be False when used by internal methods.
652672
"""
653673
if push_to_server:
654674
self._set_notice_properties(notice_data)
@@ -675,4 +695,4 @@ def _set_notice_properties(self, notice_data: dict[str, Any]) -> None:
675695
"""
676696
url = self._url_for("notice")
677697
new_data = self._session.patch(url, json=notice_data).json()
678-
self.update(new_data, push_to_server=False)
698+
self._update(new_data, push_to_server=False)

virl2_client/utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
from __future__ import annotations
2222

23+
import warnings
2324
from contextlib import nullcontext
2425
from functools import wraps
25-
from typing import TYPE_CHECKING, Callable, Type, TypeVar, Union, cast
26+
from typing import TYPE_CHECKING, Any, Callable, Type, TypeVar, Union, cast
2627

2728
import httpx
2829

@@ -178,3 +179,19 @@ def get_url_from_template(
178179
values = {}
179180
values["CONFIG_MODE"] = _CONFIG_MODE
180181
return endpoint_url_template.format(**values)
182+
183+
184+
_DEPRECATION_MESSAGES = {
185+
"push_to_server": "meant to be used only by internal methods",
186+
"offline": "offline mode has been removed",
187+
}
188+
189+
190+
def _deprecated_argument(func, argument: Any, argument_name: str):
191+
if argument is not None:
192+
reason = _DEPRECATION_MESSAGES[argument_name]
193+
warnings.warn(
194+
f"{type(func.__self__).__name__}.{func.__name__}: "
195+
f"The argument '{argument_name}' is deprecated. Reason: {reason}",
196+
DeprecationWarning,
197+
)

0 commit comments

Comments
 (0)