@@ -104,8 +104,8 @@ def process_expiring_vms_task():
104104 vm .stop ()
105105 elif days <= - 7 :
106106 print (
107- "Deleting {} ({}) as it has been at least a week since expiration." .
108- format (vm .name , vm .id ))
107+ "Deleting {} ({}) as it has been at least a week since expiration."
108+ . format (vm .name , vm .id ))
109109 send_stop_ssh_tunnel (vm .id )
110110 delete_vm_task (vm .id )
111111 if expiring_vms :
@@ -135,15 +135,29 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory):
135135 job .meta ['status' ] = 'cloning template'
136136 job .save_meta ()
137137 vmid , mac = clone_vm (proxmox , template_id , name , user )
138+ print ("[{}] Waiting until Proxmox is done provisioning." .format (name ))
139+ job .meta ['status' ] = 'waiting for Proxmox'
140+ job .save_meta ()
141+ timeout = 200
142+ retry = 0
143+ while retry < timeout :
144+ if not VM (vmid ).is_provisioned ():
145+ retry += 1
146+ time .sleep (3 )
147+ continue
148+ break
149+ if retry == timeout :
150+ print ("[{}] Failed to provision, deleting." .format (name ))
151+ job .meta ['status' ] = 'failed to provision'
152+ job .save_meta ()
153+ delete_vm_task (vmid )
154+ return
138155 print ("[{}] Registering in STARRS." .format (name ))
139156 job .meta ['status' ] = 'registering in STARRS'
140157 job .save_meta ()
141158 ip = get_next_ip (starrs , app .config ['STARRS_IP_RANGE' ])
142159 register_starrs (starrs , name , app .config ['STARRS_USER' ], mac , ip )
143160 get_vm_expire (db , vmid , app .config ['VM_EXPIRE_MONTHS' ])
144- print ("[{}] Giving Proxmox some time to finish cloning." .format (name ))
145- job .meta ['status' ] = 'waiting for Proxmox'
146- time .sleep (15 )
147161 print ("[{}] Setting CPU and memory." .format (name ))
148162 job .meta ['status' ] = 'setting CPU and memory'
149163 job .save_meta ()
@@ -152,12 +166,12 @@ def setup_template_task(template_id, name, user, ssh_key, cores, memory):
152166 vm .set_mem (memory )
153167 print ("[{}] Applying cloud-init config." .format (name ))
154168 job .meta ['status' ] = 'applying cloud-init'
169+ job .save_meta ()
155170 vm .set_ci_user (user )
156171 vm .set_ci_ssh_key (ssh_key )
157172 vm .set_ci_network ()
158- print (
159- "[{}] Waiting for STARRS to propogate before starting VM." .format (
160- name ))
173+ print ("[{}] Waiting for STARRS to propogate before starting VM." .
174+ format (name ))
161175 job .meta ['status' ] = 'waiting for STARRS'
162176 job .save_meta ()
163177 time .sleep (90 )
0 commit comments