Add ping_ok utility method
This commit is contained in:
		
					parent
					
						
							
								cda6c60e02
							
						
					
				
			
			
				commit
				
					
						91021d7612
					
				
			
		
					 1 changed files with 22 additions and 0 deletions
				
			
		|  | @ -1,3 +1,5 @@ | |||
| import logging | ||||
| import subprocess | ||||
| from django.contrib.sites.models import Site | ||||
| 
 | ||||
| from datacenterlight.tasks import create_vm_task | ||||
|  | @ -8,6 +10,8 @@ from utils.models import BillingAddress | |||
| from .cms_models import CMSIntegration | ||||
| from .models import VMPricing, VMTemplate | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
| 
 | ||||
| 
 | ||||
| def get_cms_integration(name): | ||||
|     current_site = Site.objects.get_current() | ||||
|  | @ -91,3 +95,21 @@ def create_vm(billing_address_data, stripe_customer_id, specs, | |||
|                         'token', 'customer']: | ||||
|         if session_var in request.session: | ||||
|             del request.session[session_var] | ||||
| 
 | ||||
| 
 | ||||
| def ping_ok(host_ipv6): | ||||
|     """ | ||||
|     A utility method to check if a host responds to ping requests. Note: the | ||||
|     function relies on `ping6` utility of debian to check. | ||||
| 
 | ||||
|     :param host_ipv6 str type parameter that represets the ipv6 of the host to | ||||
|            checked | ||||
|     :return True if the host responds to ping else returns False | ||||
|     """ | ||||
|     try: | ||||
|         output = subprocess.check_output("ping6 -c 1 -w 2 " + host_ipv6, | ||||
|                                          shell=True) | ||||
|     except Exception as ex: | ||||
|         logger.debug(host_ipv6 + " not reachable via ping. Error = " + str(ex)) | ||||
|         return False | ||||
|     return True | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue