Refactor polling time to terminate VM
This commit is contained in:
		
					parent
					
						
							
								6131270b1d
							
						
					
				
			
			
				commit
				
					
						4bff49dab6
					
				
			
		
					 2 changed files with 10 additions and 3 deletions
				
			
		| 
						 | 
					@ -768,6 +768,9 @@ UPDATED_TEMPLATES_DICT = {}
 | 
				
			||||||
if UPDATED_TEMPLATES_STR:
 | 
					if UPDATED_TEMPLATES_STR:
 | 
				
			||||||
    UPDATED_TEMPLATES_DICT = eval(UPDATED_TEMPLATES_STR)
 | 
					    UPDATED_TEMPLATES_DICT = eval(UPDATED_TEMPLATES_STR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MAX_TIME_TO_WAIT_FOR_VM_TERMINATE = int_env(
 | 
				
			||||||
 | 
					        'MAX_TIME_TO_WAIT_FOR_VM_TERMINATE', 15)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if DEBUG:
 | 
					if DEBUG:
 | 
				
			||||||
    from .local import *  # flake8: noqa
 | 
					    from .local import *  # flake8: noqa
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1783,11 +1783,11 @@ class VirtualMachineView(LoginRequiredMixin, View):
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            response['text'] = str(_('Error terminating VM')) + str(vm.id)
 | 
					            response['text'] = str(_('Error terminating VM')) + str(vm.id)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            for t in range(15):
 | 
					            for t in range(settings.MAX_TIME_TO_WAIT_FOR_VM_TERMINATE):
 | 
				
			||||||
                try:
 | 
					                try:
 | 
				
			||||||
                    manager.get_vm(vm.id)
 | 
					                    manager.get_vm(vm.id)
 | 
				
			||||||
                except WrongIdError:
 | 
					                except WrongIdError:
 | 
				
			||||||
                    logger.error(
 | 
					                    logger.debug(
 | 
				
			||||||
                        "VM {} not found. So, its terminated.".format(vm.id)
 | 
					                        "VM {} not found. So, its terminated.".format(vm.id)
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                    response['status'] = True
 | 
					                    response['status'] = True
 | 
				
			||||||
| 
						 | 
					@ -1798,7 +1798,7 @@ class VirtualMachineView(LoginRequiredMixin, View):
 | 
				
			||||||
                    vm_detail_obj.terminated_at = datetime.utcnow()
 | 
					                    vm_detail_obj.terminated_at = datetime.utcnow()
 | 
				
			||||||
                    vm_detail_obj.save()
 | 
					                    vm_detail_obj.save()
 | 
				
			||||||
                except BaseException as base_exception:
 | 
					                except BaseException as base_exception:
 | 
				
			||||||
                    logger.error(
 | 
					                    logger.debug(
 | 
				
			||||||
                        "manager.get_vm({vm_id}) returned exception: "
 | 
					                        "manager.get_vm({vm_id}) returned exception: "
 | 
				
			||||||
                        "{details}.".format(
 | 
					                        "{details}.".format(
 | 
				
			||||||
                            details=str(base_exception), vm_id=vm.id
 | 
					                            details=str(base_exception), vm_id=vm.id
 | 
				
			||||||
| 
						 | 
					@ -1806,6 +1806,10 @@ class VirtualMachineView(LoginRequiredMixin, View):
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                    break
 | 
					                    break
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
 | 
					                    logger.debug(
 | 
				
			||||||
 | 
					                        'Sleeping 2 seconds for terminate action on VM %s' %
 | 
				
			||||||
 | 
					                        vm.id
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
                    sleep(2)
 | 
					                    sleep(2)
 | 
				
			||||||
            if not response['status']:
 | 
					            if not response['status']:
 | 
				
			||||||
                response['text'] = str(_("VM terminate action timed out. "
 | 
					                response['text'] = str(_("VM terminate action timed out. "
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue