Fix time growing in case of using salt maas.machines state.
We used to get full list of nodes via MAAS API for any operation with maas.
It caused growing run time in case of large envs.
The module is patched to get info of one node only so that we decrease
run time.
Closes-bug: PROD-36199
Change-Id: I2d88dfa5cc95eeb396beed6a01bb6e592dde1c7a
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 06d9ef6..d07f9bd 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -165,14 +165,14 @@
Error codes:
0 : Machine not found
"""
+ maas = _create_maas_client()
try:
- return list_machines()[hostname]
- except KeyError:
+ return json.loads(maas.get(u'api/2.0/machines/?hostname='+hostname).read())[0]
+ except IndexError:
return {"error":
{ 0: "Machine not found" }
}
-
def list_machines(status_filter=None):
"""
Get list of all machines from maas server