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

Update 'containers` data key #21

Merged
merged 4 commits into from
Oct 20, 2023
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
7 changes: 5 additions & 2 deletions glances_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ async def get_ha_sensor_data(self) -> dict[str, Any] | None:
"tx": round(network["tx"] / 1024, 1),
"speed": round(network["speed"] / 1024**3, 1),
}
if "docker" in self.data and (data := self.data["docker"].get("containers")):
data = self.data.get("dockers") or self.data.get("containers")
if data and (containers_data := data.get("containers")):
active_containers = [
container for container in data if container["Status"] == "running"
container
for container in containers_data
if container["Status"] == "running"
]
sensor_data["docker"] = {"docker_active": len(active_containers)}
cpu_use = 0.0
Expand Down
14 changes: 8 additions & 6 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"key": "disk_name",
},
],
"docker": {
"containers": {
"version": {},
"version_podman": {},
"containers": [
{
"key": "name",
Expand Down Expand Up @@ -69,7 +71,7 @@
},
"memory_usage": 50126848,
},
]
],
},
"fs": [
{
Expand Down Expand Up @@ -283,10 +285,10 @@ async def test_ha_sensor_data_with_incomplete_container_information(
):
"""Test the return value for ha sensors when container memory and cpu data is not exposed by glances."""
TEST_RESPONSE = RESPONSE
del TEST_RESPONSE["docker"]["containers"][0]["memory"]["usage"]
del TEST_RESPONSE["docker"]["containers"][0]["cpu"]["total"]
del TEST_RESPONSE["docker"]["containers"][1]["memory"]["usage"]
del TEST_RESPONSE["docker"]["containers"][1]["cpu"]["total"]
del TEST_RESPONSE["containers"]["containers"][0]["memory"]["usage"]
del TEST_RESPONSE["containers"]["containers"][0]["cpu"]["total"]
del TEST_RESPONSE["containers"]["containers"][1]["memory"]["usage"]
del TEST_RESPONSE["containers"]["containers"][1]["cpu"]["total"]

TEST_HA_SENSOR_DATA = HA_SENSOR_DATA
TEST_HA_SENSOR_DATA["docker"]["docker_memory_use"] = 0
Expand Down
Loading