Пример #1
0
def determine_current_allocation():
    try:
        # Connect with all servers
        from virtual import util
        connections = util.connect_all()
        
        allocation = { host : [] for host in nodes.NODES }
            
        for host in nodes.NODES:
            connection = connections[host]
            
            vir_domains = connection.listDomainsID()
            for vir_id in vir_domains:
                vir_domain = connection.lookupByID(vir_id)
                name = vir_domain.name()
                if domains.has_domain(name):
                    # print 'adding mapping with %s' % name
                    allocation[host].append(name)
                else:
                    print 'ERROR: Domain %s is not in the domain list!' % name
    finally:
        print 'Closing connections...'
        util.close_all(connections)
    
    return allocation
Пример #2
0
def migrateAllocation(migrations):
    try:
        # Connect with all servers
        from virtual import util
        connections = util.connect_all()
        
        # trigger migrations
        for migration in migrations:
            domain_name = migration[0]
            target_node = nodes.get_node_name(migration[1])
            
            # Search the node which currently holds the domain
            domain, _ = __find_domain(connections, domain_name)
            if domain == None:
                print 'WARN: skipping - domain not found: %s' % (domain_name)
                continue
            
            # If not running start on source (necessary for migrations?)
            state = domain.state(0)[0]
            if state != 1:
                # Destroy 
                print 'Resetting the domain %s' % (domain_name)
                try:
                    domain.destroy()
                except: pass
                
                # Start
                try:
                    domain.create()
                    time.sleep(10)
                except: pass
            
            # Undefine target domain if it already exists
            try:
                dom_target = connections[target_node].lookupByName(domain_name)
                if dom_target != None:
                    dom_target.undefine()
                    print 'Undefined already exiting target domain'
            except:
                pass
            
            # Migrate to target
            try:
                print 'Migrating domain: %s to node: %s ...' % (domain_name, connections[target_node].getHostname())
                domain = domain.migrate(connections[target_node],
                                        VIR_MIGRATE_LIVE | VIR_MIGRATE_UNDEFINE_SOURCE | VIR_MIGRATE_PERSIST_DEST,
                                        domain_name, None, 0)
                print 'Migration successful'
            except:
                traceback.print_exc(file=sys.stdout)
                print 'Skipping - migration failed'
            
    except:
        traceback.print_exc(file=sys.stdout)
    finally:
        # Close connections
        util.close_all(connections)
Пример #3
0
def main():
    # Dump configuration
    print 'Cloning: %s ' % clone_names
    
    # Create drones
    drones.main()
    
    # Connect
    global connections
    connections = util.connect_all()
    
    try:
        # Shutdown all running VMs 
        shutdownall()
        
        reactor.callLater(0, next_vm)
        
        print 'Starting reactor'
        reactor.run()
        print 'Reactor returned'
        
    finally:
        util.close_all(connections)