Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add hypervisor uptime property #4

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user_docs/query_docs/HYPERVISORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ from enums.query.props.hypervisor_properties import HypervisorProperties
| HYPERVISOR_VCPUS | `int` | "vcpus" | The number of vCPUs on this hypervisor. |
| HYPERVISOR_VCPUS_USED | `int` | "vcpus_used" | The number of vCPUs currently being used on this hypervisor. |
| HYPERVISOR_DISABLED_REASON | `string` | "disabled_reason" | Comment of why the hypervisor is disabled, None if not disabled |
| HYPERVISOR_UPTIME_DAYS | `int` | "uptime" | The number of days the hypervisor has been up |


Any of these properties can be used for any of the API methods that takes a property - like `select`, `where`, `sort_by` etc
Expand Down
5 changes: 5 additions & 0 deletions openstackquery/enums/props/hypervisor_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HypervisorProperties(PropEnum):
HYPERVISOR_VCPUS = auto()
HYPERVISOR_VCPUS_USED = auto()
HYPERVISOR_DISABLED_REASON = auto()
HYPERVISOR_UPTIME_DAYS = auto()

@staticmethod
def _get_aliases() -> Dict:
Expand Down Expand Up @@ -63,6 +64,7 @@ def _get_aliases() -> Dict:
HypervisorProperties.HYPERVISOR_VCPUS: ["vcpus"],
HypervisorProperties.HYPERVISOR_VCPUS_USED: ["vcpus_used"],
HypervisorProperties.HYPERVISOR_DISABLED_REASON: ["disabled_reason"],
HypervisorProperties.HYPERVISOR_UPTIME_DAYS: ["uptime"],
}

@staticmethod
Expand Down Expand Up @@ -110,6 +112,9 @@ def get_prop_mapping(prop) -> Optional[PropFunc]:
HypervisorProperties.HYPERVISOR_DISABLED_REASON: lambda a: a["service"][
"disabled_reason"
],
HypervisorProperties.HYPERVISOR_UPTIME_DAYS: lambda a: int(
a["uptime"].strip().split(" ")[2]
),
}
try:
return mapping[prop]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="openstackquery",
version="0.1.2",
version="0.1.3",
author="Anish Mudaraddi",
author_email="<anish.mudaraddi@stfc.ac.uk>",
description=DESCRIPTION,
Expand Down
18 changes: 18 additions & 0 deletions tests/enums/props/test_hypervisor_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,21 @@ def test_hypervisor_disabled_reason_serialization(val):
HypervisorProperties.from_string(val)
is HypervisorProperties.HYPERVISOR_DISABLED_REASON
)


@pytest.mark.parametrize(
"val",
[
"HYPERVISOR_UPTIME_DAYS",
"Hypervisor_Uptime_Days",
"HyPeRvIsOr_UpTiMe_DaYs",
],
)
def test_hypervisor_uptime_days_serialization(val):
"""
Tests that variants of HYPERVISOR_UPTIME_DAYS can be serialized
"""
assert (
HypervisorProperties.from_string(val)
is HypervisorProperties.HYPERVISOR_UPTIME_DAYS
)
Loading