コード例 #1
0
def check_for_migration(manager,host,contexta): 

    #La migrazione deve essere eseguita solamente dai compute node
    if host != FLAGS.cluster_name:
	    contexto = nova.context.get_admin_context()
	    results = db.service_get_all_compute_sorted_desc(contexto)
	    istanze_attive_nodo_locale = db.instance_get_all_by_host(contexto, host)
	    for result in results:
		(service, instance_cores) = result
		if service['host'] != host:
		    istanze_attive_nodo_remoto = db.instance_get_all_by_host(contexto, service['host'])
		    #condizione che abilita la migrazione
		    if len(istanze_attive_nodo_locale) <= len(istanze_attive_nodo_remoto):
		        for istanza in istanze_attive_nodo_locale:
			    repeat = True
			    while repeat:
				manager.live_migration(contexto, istanza['id'], service['host'])
		        	_instance_update(contexto, istanza['id'], vm_state=vm_states.MIGRATING)
				old_instance = istanza
				time.sleep(15)
				new_instances = db.instance_get_all_by_host(contexto, service['host'])
				for new_instance in new_instances:
					if new_instance['uuid'] == old_instance['uuid']:
						#Istanza migrata correttamente
		        			_instance_update(contexto, istanza['id'], vm_state=vm_states.ACTIVE)
						repeat = False
			check_last_vm(host,contexto)
コード例 #2
0
ファイル: green.py プロジェクト: fabio-ferretti/nova
    def _schedule_instance(self, context, instance_opts, *_args, **_kwargs):
        """Picks a host that is up and has the fewest running instances."""
        elevated = context.elevated()

        availability_zone = instance_opts.get('availability_zone')

        zone, host = FLAGS.default_schedule_zone, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')

        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, 'nova-compute')
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            return host

        #Metodo che restituisce tutti i compute node attivi
        #TODO creare una lista dei compute node ad-hoc in stand-by da riattivare su necessita
        #Get all compute services sorted by instance count.
        #returns: a list of (Service, instance_count) tuples.
        results = db.service_get_all_compute_sorted_desc(elevated)
	out = open("/home/fabioferretti/scheduler_output","w")
	out.write("Result 1)\n")
	#i = 0
	#while i < len(results):
	out.write("\n%s" % len(results))
	#	i = i + 1
	out.close()
        in_isolation = instance_opts['image_ref'] in FLAGS.isolated_images
        check_cores = not in_isolation or not FLAGS.skip_isolated_core_check
        if zone:
            results = [(service, cores) for (service, cores) in results
                       if service['availability_zone'] == zone]
	out = open("/home/fabioferretti/scheduler_output","a")
	out.write("Result 2)\n")
	#i = 0
	#while i < len(results):
	#out.write("\n%s" % results[i])
	out.write("\n%s" % len(results))
	#	i = i +1
	out.close()
        i = 0
        ordered_results = []
        for result in results:
            (service, instance_cores) = result
            if is_cluster_controller(service['host']):
                ordered_results.append(results[i])
                del results[i]
                ordered_results = ordered_results + results
                break
            i = i + 1  
        #Ciclo su tutti i compute node trovati
        for result in ordered_results:
            (service, instance_cores) = result
            if in_isolation and service['host'] not in FLAGS.isolated_hosts:
                # isolated images run on isolated hosts
                continue
            if service['host'] in FLAGS.isolated_hosts and not in_isolation:
                # images that aren't isolated only run on general hosts
                continue
            #Controllo se i core gia occupati piu quelli che verranno occupati con la VM
            #supero la capacita massima del nodo
            #TODO MODIFICARE LA CAPACITA MASSIMA al 70 per cento
            if not (check_cores and instance_cores + instance_opts['vcpus'] > FLAGS.max_cores):
                #controllo che il nodo non sia sospeso
                if is_node_suspended(service['host']):
                    mac = get_macaddress_node_suspended(service['host'])
                    wake_on_lan(mac)
                    #TODO modificare con uno scambio di messaggi
                    time.sleep(10)
                    #se il nodo non e' attivo cambio il suo stato in active
                    if is_node_active(service['host']) == False:
                        change_node_state(service['host'], "active")
                    return service['host']
                else:
                    if utils.service_is_up(service) and not service['disabled']:
                        #se il nodo nnon e' attivo cambio il suo stato in active
                        if is_node_active(service['host']) == False:
                            change_node_state(service['host'], "active")
                        return service['host']
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)