@@ -67,14 +67,19 @@ def parse_json(self):
67
67
fail ("Invalid apikey format. Expected consumer:token:secret" )
68
68
69
69
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
+
70
75
return {
71
76
"endpoint" : endpoint ,
72
77
"consumer" : consumer ,
73
78
"token" : token ,
74
79
"secret" : secret ,
75
80
"distro_series" : distro_series ,
76
81
"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 ,
78
83
"memory" : json_data .get ("cloudstack.vm.details" , {}).get ("minRam" , "" ),
79
84
"cpus" : json_data .get ("cloudstack.vm.details" , {}).get ("cpus" , "" ),
80
85
"nics" : json_data .get ("cloudstack.vm.details" , {}).get ("nics" , []),
@@ -131,11 +136,16 @@ def create(self):
131
136
sysid = self .data .get ("system_id" )
132
137
if not sysid :
133
138
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 )
139
149
succeed ({"status" : "success" , "message" : f"Instance created with { self .data ['distro_series' ]} " })
140
150
141
151
def delete (self ):
0 commit comments