@@ -49,11 +49,13 @@ def parse_json(self):
4949
5050 endpoint = host .get ("endpoint" ) or extension .get ("endpoint" )
5151 apikey = host .get ("apikey" ) or extension .get ("apikey" )
52- distro_series = (
53- json_data .get ("cloudstack.vm.details" , {})
54- .get ("details" , {})
55- .get ("distro_series" , None )
56- )
52+
53+ details = json_data .get ("cloudstack.vm.details" , {}).get ("details" , {})
54+
55+ distro_series = details .get ("distro_series" , None )
56+ os_name = details .get ("os" ) # "ubuntu" or "centos"
57+ release = details .get ("release" ) # "20.04", "22.04", "8", etc.
58+ architecture = details .get ("architecture" ) # "amd64/ga-20.04", "amd64/generic", etc.
5759
5860 if not endpoint or not apikey :
5961 fail ("Missing MAAS endpoint or apikey" )
@@ -68,12 +70,7 @@ def parse_json(self):
6870
6971 consumer , token , secret = parts
7072
71- system_id = (
72- json_data .get ("cloudstack.vm.details" , {})
73- .get ("details" , {})
74- .get ("maas_system_id" )
75- or vm .get ("maas_system_id" , "" )
76- )
73+ system_id = details .get ("maas_system_id" ) or vm .get ("maas_system_id" , "" )
7774
7875 vm_name = vm .get ("vm_name" ) or json_data .get ("cloudstack.vm.details" , {}).get ("name" )
7976 if not vm_name :
@@ -85,6 +82,9 @@ def parse_json(self):
8582 "token" : token ,
8683 "secret" : secret ,
8784 "distro_series" : distro_series or "ubuntu/focal" ,
85+ "os" : os_name ,
86+ "release" : release ,
87+ "architecture" : architecture ,
8888 "system_id" : system_id ,
8989 "vm_name" : vm_name ,
9090 }
@@ -163,17 +163,30 @@ def create(self):
163163 if not sysid :
164164 fail ("system_id missing for create" )
165165
166- ds = self .data .get ("distro_series" , "ubuntu/focal" )
167- self .call_maas (
168- "POST" ,
169- f"/machines/{ sysid } /" ,
170- {
171- "op" : "deploy" ,
172- "distro_series" : ds ,
173- "net-setup-method" : "curtin" ,
174- },
175- )
176- succeed ({"status" : "success" , "message" : f"Instance created with { ds } " })
166+ ds = self .data .get ("distro_series" , None )
167+ os_name = self .data .get ("os" )
168+ release = self .data .get ("release" )
169+ arch = self .data .get ("architecture" )
170+
171+ deploy_payload = {"op" : "deploy" }
172+
173+ if os_name or release or arch :
174+ if os_name :
175+ deploy_payload ["os" ] = os_name
176+ if release :
177+ deploy_payload ["release" ] = release
178+ if arch :
179+ deploy_payload ["architecture" ] = arch
180+ if ds :
181+ deploy_payload ["distro_series" ] = ds
182+ else :
183+ deploy_payload ["distro_series" ] = ds or "ubuntu/focal"
184+
185+ deploy_payload ["net-setup-method" ] = "curtin"
186+
187+ self .call_maas ("POST" , f"/machines/{ sysid } /" , deploy_payload )
188+
189+ succeed ({"status" : "success" , "message" : "Instance created" , "requested" : deploy_payload })
177190
178191 def delete (self ):
179192 sysid = self .data .get ("system_id" )
0 commit comments