def enable_suspended_node(): path_nodes = ''.join([FLAGS.list_nodes_path, "nodes"]) suspended_nodes = open(path_nodes, 'r').readlines() if len(suspended_nodes) == 0: print "node_to_enable = None" return None node_to_enable = suspended_nodes[0] del suspended_nodes[0] open(path_nodes, 'w').writelines(suspended_nodes) #Risveglio il nodo selezionato macaddress = node_to_enable.split(' ')[0] wake_on_lan(macaddress) print macaddress return node_to_enable
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)