Skip to content

Commit e551ba1

Browse files
Add VM name to MaaS deploy API
1 parent 3498519 commit e551ba1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

extensions/MaaS/maas.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,19 @@ def parse_json(self):
6767
fail("Invalid apikey format. Expected consumer:token:secret")
6868

6969
consumer, token, secret = parts
70+
vm_name = (
71+
json_data.get("externaldetails", {}).get("virtualmachine", {}).get("vm_name")
72+
or json_data.get("cloudstack.vm.details", {}).get("name", "")
73+
)
74+
7075
return {
7176
"endpoint": endpoint,
7277
"consumer": consumer,
7378
"token": token,
7479
"secret": secret,
7580
"distro_series": distro_series,
7681
"system_id": json_data.get("cloudstack.vm.details", {}).get("details", {}).get("maas_system_id", ""),
77-
"vm_name": json_data.get("cloudstack.vm.details", {}).get("name", ""),
82+
"vm_name": vm_name,
7883
"memory": json_data.get("cloudstack.vm.details", {}).get("minRam", ""),
7984
"cpus": json_data.get("cloudstack.vm.details", {}).get("cpus", ""),
8085
"nics": json_data.get("cloudstack.vm.details", {}).get("nics", []),
@@ -131,11 +136,16 @@ def create(self):
131136
sysid = self.data.get("system_id")
132137
if not sysid:
133138
fail("system_id missing for create")
134-
self.call_maas(
135-
"POST",
136-
f"/machines/{sysid}/",
137-
{"op": "deploy", "distro_series": self.data["distro_series"]},
138-
)
139+
140+
payload = {
141+
"op": "deploy",
142+
"distro_series": self.data["distro_series"],
143+
}
144+
145+
if self.data.get("vm_name"):
146+
payload["name"] = self.data["vm_name"]
147+
148+
self.call_maas("POST", f"/machines/{sysid}/", payload)
139149
succeed({"status": "success", "message": f"Instance created with {self.data['distro_series']}"})
140150

141151
def delete(self):

0 commit comments

Comments
 (0)