Jacopo Rota has proposed merging ~r00ta/maas-site-manager:MAASENG-1627 into maas-site-manager:main.
Commit message: add other_machines column and total_machines property in response object Requested reviews: MAAS Committers (maas-committers) For more details, see: https://code.launchpad.net/~r00ta/maas-site-manager/+git/site-manager/+merge/443087 This PR aims to add `other_machines` column and `total_machines` property in the response object as per https://warthogs.atlassian.net/browse/MAASENG-1627 -- Your team MAAS Committers is requested to review the proposed merge of ~r00ta/maas-site-manager:MAASENG-1627 into maas-site-manager:main.
diff --git a/backend/msm/db/_tables.py b/backend/msm/db/_tables.py index 1fa9662..e4c4677 100644 --- a/backend/msm/db/_tables.py +++ b/backend/msm/db/_tables.py @@ -69,5 +69,6 @@ SiteData = Table( Column("deployed_machines", Integer), Column("ready_machines", Integer), Column("error_machines", Integer), + Column("other_machines", Integer), Column("last_seen", DateTime), ) diff --git a/backend/msm/db/models.py b/backend/msm/db/models.py index ff3806f..078946a 100644 --- a/backend/msm/db/models.py +++ b/backend/msm/db/models.py @@ -14,10 +14,12 @@ from ..schema import TimeZone class SiteData(BaseModel): """Data for a site.""" + total_machines: int allocated_machines: int deployed_machines: int ready_machines: int error_machines: int + other_machines: int last_seen: datetime diff --git a/backend/msm/db/queries.py b/backend/msm/db/queries.py index bb2e1a3..77b173e 100644 --- a/backend/msm/db/queries.py +++ b/backend/msm/db/queries.py @@ -164,6 +164,14 @@ async def get_sites( ( SiteData.c.site_id != None, # noqa: E711 func.json_build_object( + "total_machines", + ( + SiteData.c.allocated_machines + + SiteData.c.deployed_machines + + SiteData.c.ready_machines + + SiteData.c.error_machines + + SiteData.c.other_machines + ).label("total_machines"), "allocated_machines", SiteData.c.allocated_machines, "deployed_machines", @@ -172,6 +180,8 @@ async def get_sites( SiteData.c.ready_machines, "error_machines", SiteData.c.error_machines, + "other_machines", + SiteData.c.other_machines, "last_seen", SiteData.c.last_seen, ), diff --git a/backend/tests/user_api/test_handlers.py b/backend/tests/user_api/test_handlers.py index a74ab8f..b4ae28c 100644 --- a/backend/tests/user_api/test_handlers.py +++ b/backend/tests/user_api/test_handlers.py @@ -158,6 +158,7 @@ class TestSitesHandler: "deployed_machines": 20, "ready_machines": 30, "error_machines": 40, + "other_machines": 5, "last_seen": datetime.utcnow(), } ], @@ -165,6 +166,7 @@ class TestSitesHandler: del site_data["id"] del site_data["site_id"] site_data["last_seen"] = site_data["last_seen"].isoformat() + site_data["total_machines"] = 105 site["stats"] = site_data del site["created"] del site["accepted"] diff --git a/test-data/import.sh b/test-data/import.sh index f0163b1..c446345 100755 --- a/test-data/import.sh +++ b/test-data/import.sh @@ -38,5 +38,5 @@ fi copy_cmd sites.csv 'site(id, city, country, latitude, longitude, name, name_unique, note, region, street, timezone, url, accepted, created)' copy_cmd tokens.csv 'token(site_id, value, expired, created)' copy_cmd users.csv '"user"(email, full_name, password)' - copy_cmd site_data.csv 'site_data(site_id, allocated_machines, deployed_machines, ready_machines, error_machines, last_seen)' + copy_cmd site_data.csv 'site_data(site_id, allocated_machines, deployed_machines, ready_machines, error_machines, other_machines, last_seen)' ) | psql --single-transaction "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" diff --git a/test-data/site_data.csv b/test-data/site_data.csv index e6a4960..bc9d7d7 100644 --- a/test-data/site_data.csv +++ b/test-data/site_data.csv @@ -1,7 +1,7 @@ -site_id, allocated_machines, deployed_machines, ready_machines, error_machines, last_seen -1,10,1,8,1,"01-01-2023 08:00" -2,11,0,8,3,"01-01-2023 09:00" -3,12,2,4,6,"01-01-2023 10:00" -4,13,0,13,0,"01-01-2023 11:00" -5,14,13,1,0,"01-01-2023 12:00" -6,15,2,10,3,"01-01-2023 13:00" +site_id, allocated_machines, deployed_machines, ready_machines, error_machines, other_machines, last_seen +1,10,1,8,1,2,"01-01-2023 08:00" +2,11,0,8,3,0,"01-01-2023 09:00" +3,12,2,4,6,1,"01-01-2023 10:00" +4,13,0,13,0,0,"01-01-2023 11:00" +5,14,13,1,0,4,"01-01-2023 12:00" +6,15,2,10,3,7,"01-01-2023 13:00"
-- Mailing list: https://launchpad.net/~sts-sponsors Post to : sts-sponsors@lists.launchpad.net Unsubscribe : https://launchpad.net/~sts-sponsors More help : https://help.launchpad.net/ListHelp