def schedule_vm(vm_details,host,live_migration):
    try:
        logger.debug("Entering into scheduleVM")
        retVal=True
       
        retVal=is_same_host(vm_details,host)
        if (retVal == False):
            logger.debug("VM is on the same host")
            return False

        if (live_migration == 1):
            retVal=is_migration_possible(vm_details,host)
         
        if (retVal == True):
            logger.debug("Going to migrate VM:"+vm_details.vm_name+ " on host: "+ str(host['host_ip'].private_ip))
            ret=migrate_domain(vm_details.id,host.id,live_migration) 
            #ret=(TASK_QUEUE_STATUS_SUCCESS,'msg') #when uncomment this, comment the line above
            logger.debug("Value returned from migrate_domain is:"+str(ret[0]))
            if(ret[0] == TASK_QUEUE_STATUS_SUCCESS):
                return True
            else:
                return False
        else:
            logger.debug("VM:"+vm_details.vm_name+" cannot be migrated to host:"+str(host['host_ip'].private_ip))  
            return False
    except:
        logger.exception('Exception in scheduleVM')         
        return False
Exemple #2
0
def schedule_vm(vm_details, host, live_migration):
    """
    Migrate a vm on host if affinity is correct and migration is possible.
    """
    try:
        logger.debug("Entering into scheduleVM")
        retVal = True

        retVal = is_same_host(vm_details, host)
        if (retVal == False):
            logger.debug("VM is on the same host")
            return False

        if (live_migration == 1):
            retVal = is_migration_possible(vm_details, host)

        if (retVal == True):
            logger.debug("Going to migrate VM:" + vm_details.vm_name +
                         " on host: " + str(host['host_ip'].private_ip))
            ret = migrate_domain(vm_details.id, host.id, live_migration)
            #ret=(TASK_QUEUE_STATUS_SUCCESS,'msg') #when uncomment this, comment the line above
            logger.debug("Value returned from migrate_domain is:" +
                         str(ret[0]))
            if (ret[0] == TASK_QUEUE_STATUS_SUCCESS):
                return True
            else:
                return False
        else:
            logger.debug("VM:" + vm_details.vm_name +
                         " cannot be migrated to host:" +
                         str(host['host_ip'].private_ip))
            return False
    except:
        logger.exception('Exception in scheduleVM')
        return False
def is_migration_possible(guest_info,host_info):
    try:
        logger.debug("Entering into is_migration_possible")
        #host mem usage used_mem_in_kb

        host_ip = host_info['host_ip'].private_ip
        host_mem_utilization = get_host_mem_usage(host_ip)
        memhog_usage = get_memhog_usage(host_ip)

        logger.debug("For host:"+str(host_ip)+" PSS Value from memhog="+str(memhog_usage))
        host_mem_utilization=((host_mem_utilization * 1024 ) - memhog_usage) 

        logger.debug("For host:"+str(host_ip)+" host_mem_utilization="+str(host_mem_utilization))

        # guest mem usage
        guest_present_host = guest_info['host_id'].host_ip.private_ip 
        guest_domain = getVirshDomain(guest_info)
        guest_mem_utilization = get_dom_mem_usage(guest_domain, guest_present_host)
        host_utilization_if_migrated = (host_mem_utilization + guest_mem_utilization)/(host_info['RAM']*1024*1024*1024)

        host_utilization_if_migrated = host_utilization_if_migrated * 100
        logger.debug("host_mem_utilization is " +str(host_mem_utilization))
        logger.debug("guest_mem_utilization is " +str(guest_mem_utilization))
        logger.debug("host_info['RAM']*1024*1024*1024 is " +str(host_info['RAM']*1024*1024*1024))
        logger.debug("host_utilization_if_migrated is " +str(host_utilization_if_migrated))
   
        if(host_utilization_if_migrated > 90):
            return False
        else:
            return True
    except:
        logger.exception('Exception in is_migration_possible')
        return False
Exemple #4
0
def check_affinity(vm_details,host):
    try:
        logger.debug("Entering into check_affinity")
        return True 
    except:
        logger.exception('Exception in check_affinity') 
        return False
Exemple #5
0
def is_migration_possible(guest_info,host_info):
    try:
        logger.debug("Entering into is_migration_possible")
        #host mem usage used_mem_in_kb
        host_ip = host_info['host_ip'].private_ip
        host_mem_utilization = get_host_mem_usage(host_ip)
        host_mem_utilization = host_mem_utilization * 1024

        # guest mem usage
        guest_present_host = guest_info['host_id'].host_ip.private_ip
        guest_mem_utilization = get_dom_mem_usage(guest_info['vm_identity'], guest_present_host)
        host_utilization_if_migrated = (host_mem_utilization + guest_mem_utilization)/(host_info['RAM']*1024*1024*1024)

        host_utilization_if_migrated = host_utilization_if_migrated * 100
        logger.debug("host_mem_utilization is " +str(host_mem_utilization))
        logger.debug("guest_mem_utilization is " +str(guest_mem_utilization))
        logger.debug("host_utilization_if_migrated is " +str(host_utilization_if_migrated))
   
        if(host_utilization_if_migrated > 90):
            return False
        else:
            return True
    except:
        logger.exception('Exception in is_migration_possible')
        return False
def check_affinity(vm_details,host):
    try:
        logger.debug("Entering into check_affinity for vm:"+str(vm_details.vm_name)) 
        if(vm_details.vm_name in ('superopt','largevm','NeuroImaging2','sniper-big','csl788-1','NeuroImaging','sniper-large', 'mooc_6')):
           return False 
        else:
           return True 
    except:
        logger.exception('Exception in check_affinity') 
        return False
Exemple #7
0
def loadbalance_vm(host_list=[], vm_list=[]):
    if (host_list == [] and vm_list == []):
        logger.debug("host list or vm list is empty")
        return False
    else:
        host_list_for_host_status = host_list[:]
        try:
            shutdown_vm_list = {}
            guests_map = {}
            for guest in vm_list:
                guests_map[guest] = False

            for vm_details in guests_map:
                if (vm_details.status == current.VM_STATUS_SHUTDOWN
                        or vm_details.status == current.VM_STATUS_SUSPENDED):
                    logger.debug("VM: " + vm_details.vm_name +
                                 " is shutoff, no need to migrate VM")
                    shutdown_vm_list[vm_details] = False
                elif (vm_details.status == current.VM_STATUS_RUNNING):
                    logger.debug("VM:" + vm_details.vm_name +
                                 " is running, need live migration")
                    for host in host_list:
                        if (check_affinity(vm_details, host)
                                and schedule_vm(vm_details, host, 1)):
                            logger.debug(host)
                            logger.debug(
                                "VM:" + vm_details.vm_name +
                                " migration is successful on the host " +
                                str(host['host_ip'].private_ip))
                            guests_map[vm_details] = True
                            break
                        else:
                            logger.debug("VM:" + vm_details.vm_name +
                                         " failed to migrate on the host " +
                                         str(host['host_ip'].private_ip))

            #move the shutdown VM to the least loaded host.
            for shutdown_vm in shutdown_vm_list:
                for host in host_list:
                    if (check_affinity(shutdown_vm, host)
                            and schedule_vm(shutdown_vm, host, 0)):
                        logger.debug(host)
                        logger.debug("VM migration successful on the host " +
                                     str(host['host_ip'].private_ip))
                        shutdown_vm_list[shutdown_vm] = True
                        break
                    else:
                        logger.debug("VM failed to migrate on the host " +
                                     str(host['host_ip'].private_ip))

            logger.debug("loadbalance_vm is done....")
            shutdown_nonactive_hosts(host_list_for_host_status)
        except:
            logger.exception('Exception in process_schedule_vm')
            return False
Exemple #8
0
def loadbalance_vm(host_list=[], vm_list=[]):
    if host_list == [] and vm_list == []:
        logger.debug("host list or vm list is empty")
        return False
    else:
        host_list_for_host_status = host_list[:]
        try:
            shutdown_vm_list = {}
            guests_map = {}
            for guest in vm_list:
                guests_map[guest] = False

            for vm_details in guests_map:
                if vm_details.status == VM_STATUS_SHUTDOWN or vm_details.status == VM_STATUS_SUSPENDED:
                    logger.debug("VM: " + vm_details.vm_name + " is shutoff, no need to migrate VM")
                    shutdown_vm_list[vm_details] = False
                elif vm_details.status == VM_STATUS_RUNNING:
                    logger.debug("VM:" + vm_details.vm_name + " is running, need live migration")
                    for host in host_list:
                        if check_affinity(vm_details, host) and schedule_vm(vm_details, host, 1):
                            logger.debug(host)
                            logger.debug(
                                "VM:"
                                + vm_details.vm_name
                                + " migration is successful on the host "
                                + str(host["host_ip"].private_ip)
                            )
                            guests_map[vm_details] = True
                            break
                        else:
                            logger.debug(
                                "VM:"
                                + vm_details.vm_name
                                + " failed to migrate on the host "
                                + str(host["host_ip"].private_ip)
                            )

            # move the shutdown VM to the least loaded host.
            for shutdown_vm in shutdown_vm_list:
                for host in host_list:
                    if check_affinity(shutdown_vm, host) and schedule_vm(shutdown_vm, host, 0):
                        logger.debug(host)
                        logger.debug("VM migration successful on the host " + str(host["host_ip"].private_ip))
                        shutdown_vm_list[shutdown_vm] = True
                        break
                    else:
                        logger.debug("VM failed to migrate on the host " + str(host["host_ip"].private_ip))

            logger.debug("loadbalance_vm is done....")
            shutdown_nonactive_hosts(host_list_for_host_status)
        except:
            logger.exception("Exception in process_schedule_vm")
            return False
Exemple #9
0
def is_same_host(guest_info, host_info):
    """
    Checks guest_present_host and selected host are same or not.
    """
    try:
        logger.debug("Entering into is_same_host")
        host_ip = host_info['host_ip'].private_ip
        guest_present_host = guest_info['host_id'].host_ip.private_ip

        return False if (host_ip == guest_present_host) else True

    except:
        logger.exception('Exception in is_same_host')
        return False
def is_same_host(guest_info,host_info):
    try:
        logger.debug("Entering into is_same_host")
        host_ip = host_info['host_ip'].private_ip
        guest_present_host = guest_info['host_id'].host_ip.private_ip
 
        if(host_ip == guest_present_host): 
            return False
        else:
	    return True
          
    except:
        logger.exception('Exception in is_same_host')
        return False
Exemple #11
0
def is_same_host(guest_info, host_info):
    """
    Checks guest_present_host and selected host are same or not.
    """
    try:
        logger.debug("Entering into is_same_host")
        host_ip = host_info["host_ip"].private_ip
        guest_present_host = guest_info["host_id"].host_ip.private_ip

        return False if (host_ip == guest_present_host) else True

    except:
        logger.exception("Exception in is_same_host")
        return False
Exemple #12
0
def check_affinity(vm_details, host):
    """
    Check affinity of vm with host. Affinity gives list of host on which vm can be migrated.
    """
    try:
        logger.debug("Entering into check_affinity for vm:" +
                     str(vm_details.vm_name))
        if (vm_details.vm_name
                in ('superopt', 'largevm', 'NeuroImaging2', 'sniper-big',
                    'csl788-1', 'NeuroImaging', 'sniper-large', 'mooc_6')):
            return False
        else:
            return True
    except:
        logger.exception('Exception in check_affinity')
        return False
Exemple #13
0
def is_migration_possible(guest_info, host_info):
    """
    Checks whether migration on the host is possible or not and criteria is host utilization should not 
    go above 90% after migration.
    """
    try:
        logger.debug("Entering into is_migration_possible")
        #host mem usage used_mem_in_kb

        host_ip = host_info['host_ip'].private_ip
        host_mem_utilization = get_host_mem_usage(host_ip)
        memhog_usage = get_memhog_usage(host_ip)

        logger.debug("For host:" + str(host_ip) + " PSS Value from memhog=" +
                     str(memhog_usage))
        host_mem_utilization = ((host_mem_utilization * 1024) - memhog_usage)

        logger.debug("For host:" + str(host_ip) + " host_mem_utilization=" +
                     str(host_mem_utilization))

        # guest mem usage
        guest_present_host = guest_info['host_id'].host_ip.private_ip
        guest_domain = getVirshDomain(guest_info)  # @UndefinedVariable
        guest_mem_utilization = get_dom_mem_usage(guest_domain,
                                                  guest_present_host)
        host_utilization_if_migrated = (
            host_mem_utilization +
            guest_mem_utilization) / (host_info['RAM'] * 1024 * 1024 * 1024)

        host_utilization_if_migrated = host_utilization_if_migrated * 100
        logger.debug("host_mem_utilization is " + str(host_mem_utilization))
        logger.debug("guest_mem_utilization is " + str(guest_mem_utilization))
        logger.debug("host_info['RAM']*1024*1024*1024 is " +
                     str(host_info['RAM'] * 1024 * 1024 * 1024))
        logger.debug("host_utilization_if_migrated is " +
                     str(host_utilization_if_migrated))

        if (host_utilization_if_migrated > 90):
            return False
        else:
            return True
    except:
        logger.exception('Exception in is_migration_possible')
        return False
Exemple #14
0
def check_affinity(vm_details, host):
    """
    Check affinity of vm with host. Affinity gives list of host on which vm can be migrated.
    """
    try:
        logger.debug("Entering into check_affinity for vm:" + str(vm_details.vm_name))
        if vm_details.vm_name in (
            "superopt",
            "largevm",
            "NeuroImaging2",
            "sniper-big",
            "csl788-1",
            "NeuroImaging",
            "sniper-large",
            "mooc_6",
        ):
            return False
        else:
            return True
    except:
        logger.exception("Exception in check_affinity")
        return False
Exemple #15
0
def is_migration_possible(guest_info, host_info):
    """
    Checks whether migration on the host is possible or not and criteria is host utilization should not 
    go above 90% after migration.
    """
    try:
        logger.debug("Entering into is_migration_possible")
        # host mem usage used_mem_in_kb

        host_ip = host_info["host_ip"].private_ip
        host_mem_utilization = get_host_mem_usage(host_ip)
        memhog_usage = get_memhog_usage(host_ip)

        logger.debug("For host:" + str(host_ip) + " PSS Value from memhog=" + str(memhog_usage))
        host_mem_utilization = (host_mem_utilization * 1024) - memhog_usage

        logger.debug("For host:" + str(host_ip) + " host_mem_utilization=" + str(host_mem_utilization))

        # guest mem usage
        guest_present_host = guest_info["host_id"].host_ip.private_ip
        guest_domain = getVirshDomain(guest_info)  # @UndefinedVariable
        guest_mem_utilization = get_dom_mem_usage(guest_domain, guest_present_host)
        host_utilization_if_migrated = (host_mem_utilization + guest_mem_utilization) / (
            host_info["RAM"] * 1024 * 1024 * 1024
        )

        host_utilization_if_migrated = host_utilization_if_migrated * 100
        logger.debug("host_mem_utilization is " + str(host_mem_utilization))
        logger.debug("guest_mem_utilization is " + str(guest_mem_utilization))
        logger.debug("host_info['RAM']*1024*1024*1024 is " + str(host_info["RAM"] * 1024 * 1024 * 1024))
        logger.debug("host_utilization_if_migrated is " + str(host_utilization_if_migrated))

        if host_utilization_if_migrated > 90:
            return False
        else:
            return True
    except:
        logger.exception("Exception in is_migration_possible")
        return False