Skip to content

Commit

Permalink
Configuration cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmikuska committed Dec 18, 2024
1 parent b8f8dac commit 1a49173
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion virl2_client/models/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _request(self, *args, **kwargs):
raise api_error from None


def make_session(base_url: str, ssl_verify: bool = True) -> httpx.Client:
def make_session(base_url: str, ssl_verify: bool | str = True) -> httpx.Client:
"""
Create an httpx Client object with the specified base URL
and SSL verification setting.
Expand Down
10 changes: 5 additions & 5 deletions virl2_client/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_from_file(virlrc_parent: Path, prop_name: str) -> str | None:
return None


def _get_prop(prop_name: str) -> str:
def _get_prop(prop_name: str) -> str | None:
"""
Get the value of a variable.
Expand Down Expand Up @@ -91,8 +91,8 @@ def _get_prop(prop_name: str) -> str:


def get_configuration(
host: str, username: str, password: str, ssl_verify: bool | str
) -> tuple[str, str, str, str]:
host: str | None, username: str | None, password: str | None, ssl_verify: bool | str
) -> tuple[str, str, str, bool | str]:
"""
Get the login configuration.
Expand Down Expand Up @@ -137,9 +137,9 @@ def get_configuration(
raise InitializationError(message)

if ssl_verify is True:
ssl_verify = _get_prop("CA_BUNDLE") or _get_prop("CML_VERIFY_CERT")
ssl_verify = _get_prop("CA_BUNDLE") or _get_prop("CML_VERIFY_CERT") or True
# to match the behavior of virlutils, we allow to disable the SSL check via ENV
if ssl_verify and ssl_verify.lower() == "false":
if isinstance(ssl_verify, str) and ssl_verify.lower() == "false":
ssl_verify = False

return host, username, password, ssl_verify
6 changes: 4 additions & 2 deletions virl2_client/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,9 @@ def map_l3_addresses_to_interfaces(

@check_stale
@locked
def sync_operational(self, response: dict[str, Any] = None) -> dict[str, Any]:
def sync_operational(
self, response: dict[str, Any] | None = None
) -> dict[str, Any]:
"""
Synchronize the operational state of the node.
Expand All @@ -934,7 +936,7 @@ def sync_operational(self, response: dict[str, Any] = None) -> dict[str, Any]:
"""
if response is None:
url = self._url_for("operational")
response = self._session.get(url).json()
assert (response := self._session.get(url).json())
self._pinned_compute_id = response.get("pinned_compute_id")
operational = response.get("operational", {})
self._compute_id = operational.get("compute_id")
Expand Down
7 changes: 3 additions & 4 deletions virl2_client/virl2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def check_controller_version(self) -> Version | None:
Raise exception if versions are incompatible, or print warning
if the client minor version is lower than the controller minor version.
"""
controller_version = self.system_info().get("version")
controller_version = self.system_info().get("version", "")
try:
controller_version_obj = Version(controller_version)
except (TypeError, ValueError):
Expand Down Expand Up @@ -628,7 +628,7 @@ def all_labs(self, show_all: bool = False) -> list[Lab]:
:param show_all: Whether to get only labs owned by the admin or all user labs.
:returns: A list of Lab objects.
"""
url = {"url": self._url_for("labs")}
url: dict[str, str | dict] = {"url": self._url_for("labs")}
if show_all:
url["params"] = {"show_all": True}
lab_ids = self._session.get(**url).json()
Expand Down Expand Up @@ -740,7 +740,6 @@ def remove_lab(self, lab_id: str | Lab) -> None:
elif lab_id in self._labs:
self._labs[lab_id].remove()
self._remove_lab_local(self._labs[lab_id])

else:
self._remove_unjoined_lab(lab_id)

Expand Down Expand Up @@ -877,7 +876,7 @@ def get_lab_list(self, show_all: bool = False) -> list[str]:
owned by the admin (False).
:returns: A list of lab IDs.
"""
url = {"url": self._url_for("labs")}
url: dict[str, str | dict] = {"url": self._url_for("labs")}
if show_all:
url["params"] = {"show_all": True}
return self._session.get(**url).json()
Expand Down

0 comments on commit 1a49173

Please sign in to comment.