Refactor ping_ok from datacenterlight.utils to utils.hosting_utils
This commit is contained in:
		
					parent
					
						
							
								a55587dbf3
							
						
					
				
			
			
				commit
				
					
						3b07687d3e
					
				
			
		
					 2 changed files with 19 additions and 19 deletions
				
			
		| 
						 | 
					@ -1,5 +1,4 @@
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import subprocess
 | 
					 | 
				
			||||||
from django.contrib.sites.models import Site
 | 
					from django.contrib.sites.models import Site
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from datacenterlight.tasks import create_vm_task
 | 
					from datacenterlight.tasks import create_vm_task
 | 
				
			||||||
| 
						 | 
					@ -95,21 +94,3 @@ def create_vm(billing_address_data, stripe_customer_id, specs,
 | 
				
			||||||
                        'token', 'customer']:
 | 
					                        'token', 'customer']:
 | 
				
			||||||
        if session_var in request.session:
 | 
					        if session_var in request.session:
 | 
				
			||||||
            del request.session[session_var]
 | 
					            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
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import decimal
 | 
					import decimal
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
from oca.pool import WrongIdError
 | 
					from oca.pool import WrongIdError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from datacenterlight.models import VMPricing
 | 
					from datacenterlight.models import VMPricing
 | 
				
			||||||
| 
						 | 
					@ -130,6 +131,24 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0,
 | 
				
			||||||
    return float(price), float(vat), float(vat_percent), discount
 | 
					    return float(price), float(vat), float(vat_percent), discount
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HostingUtils:
 | 
					class HostingUtils:
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def clear_items_from_list(from_list, items_list):
 | 
					    def clear_items_from_list(from_list, items_list):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue