def main():
    args = collect_args()
    common.load_config(CONF, args.config)

    novac = common.get_nova_client()
    print "Getting all instances"
    instances = common.all_servers(novac)
    print "Got all instances"
    conn = MySQLdb.connect(
        host=CONF.get('db', 'host'),
        user=CONF.get('db', 'user'),
        passwd=CONF.get('db', 'password'),
        db=CONF.get('db', 'name'))
    cursor = conn.cursor()
    try:
        print "Dropping table if exists"
        cursor.execute('DROP TABLE network_migration_info')
    except:
        pass
    print "Creating migration table"
    cursor.execute(CREATE_TABLE_SQL)
    conn.commit()
    count = 0
    for i in instances:
        add_instance(cursor, i)
        if count > 50:
            conn.commit()
            count = 0
        else:
            count += 1
    conn.commit()
    cursor.close()
    conn.close()
Example #2
0
def main():
    args = collect_args()
    common.load_config(CONF, args.config)

    novac = common.get_nova_client()
    print "Getting all instances"
    instances = common.all_servers(novac)
    print "Got all instances"
    conn = MySQLdb.connect(host=CONF.get('db', 'host'),
                           user=CONF.get('db', 'user'),
                           passwd=CONF.get('db', 'password'),
                           db=CONF.get('db', 'name'))
    cursor = conn.cursor()
    try:
        print "Dropping table if exists"
        cursor.execute('DROP TABLE network_migration_info')
    except:
        pass
    print "Creating migration table"
    cursor.execute(CREATE_TABLE_SQL)
    conn.commit()
    count = 0
    for i in instances:
        add_instance(cursor, i)
        if count > 50:
            conn.commit()
            count = 0
        else:
            count += 1
    conn.commit()
    cursor.close()
    conn.close()
Example #3
0
def main():
    args = collect_args()
    common.load_config(CONF, args.config)
    noop = True
    if args.for_realsies:
        noop = False
    else:
        print "Running migration in noop mode, use -f to actually migrate things"
    direction = args.direction
    conn = MySQLdb.connect(host=CONF.get('db', 'host'),
                           user=CONF.get('db', 'user'),
                           passwd=CONF.get('db', 'password'),
                           db=CONF.get('db', 'name'))

    cursor = MySQLdb.cursors.DictCursor(conn)

    url = CONF.get('creds', 'auth_url')
    username = CONF.get('creds', 'username')
    password = CONF.get('creds', 'password')
    tenant = CONF.get('creds', 'tenant_name')

    host = socket.gethostname()
    novac = common.get_nova_client(username=username,
                                   password=password,
                                   tenant=tenant,
                                   url=url)

    neutronc = common.get_neutron_client(username=username,
                                         password=password,
                                         tenant=tenant,
                                         url=url)

    networks = []
    for section in CONF.sections():
        if section.startswith('network_'):
            network_id = CONF.get(section, 'neutron_net_id')
            network = get_network(neutronc, network_id)
            for option in ('device', 'bridge', 'nova_name'):
                network[option] = CONF.get(section, option)
            networks.append(network)

    instances = common.all_servers(novac, host=host)
    if direction == 'neutron':
        manager = NeutronMigration
    elif direction == 'nova':
        manager = NovaMigration
    else:
        print "unknown direction"
    print "Running checks"
    errors = migrate_interfaces(True, manager, neutronc, cursor, networks,
                                instances)
    if not noop and not errors:
        print "running for real"
        migrate_interfaces(False, manager, neutronc, cursor, networks,
                           instances)
    if errors:
        print "ERROR: Cannot run due to errors"
    cursor.close()
    conn.close()
    print "SUCCESS!"
Example #4
0
def main():
    args = collect_args()
    common.load_config(CONF, args.config)
    target_zone = args.zone
    conn = MySQLdb.connect(host=CONF.get('db', 'host'),
                           user=CONF.get('db', 'user'),
                           passwd=CONF.get('db', 'password'),
                           db=CONF.get('db', 'name'))

    cursor = MySQLdb.cursors.DictCursor(conn)
    novac = common.get_nova_client()
    check_hypervisors(novac)
    neutronc = common.get_neutron_client()
    print "creating networks"
    mappings = create_networks(neutronc, cursor)
    print "getting instances"
    instances = common.all_servers(novac)
    print "adding ports"

    for i in instances:
        add_ports(neutronc, cursor, mappings, i, target_zone)
    cursor.close()
    conn.close()
def main():
    args = collect_args()
    common.load_config(CONF, args.config)
    target_zone = args.zone
    conn = MySQLdb.connect(
        host=CONF.get('db', 'host'),
        user=CONF.get('db', 'user'),
        passwd=CONF.get('db', 'password'),
        db=CONF.get('db', 'name'))

    cursor = MySQLdb.cursors.DictCursor(conn)
    novac = common.get_nova_client()
    check_hypervisors(novac)
    neutronc = common.get_neutron_client()
    print "creating networks"
    mappings = create_networks(neutronc)
    print "getting instances"
    instances = common.all_servers(novac)
    print "adding ports"

    for i in instances:
        add_ports(neutronc, cursor, mappings, i, target_zone)
    cursor.close()
    conn.close()
def main():
    args = collect_args()
    common.load_config(CONF, args.config)
    noop = True
    if args.for_realsies:
        noop = False
    else:
        print "Running migration in noop mode, use -f to actually migrate things"
    direction = args.direction
    conn = MySQLdb.connect(
        host=CONF.get('db', 'host'),
        user=CONF.get('db', 'user'),
        passwd=CONF.get('db', 'password'),
        db=CONF.get('db', 'name'))

    cursor = MySQLdb.cursors.DictCursor(conn)

    url = CONF.get('creds', 'auth_url')
    username = CONF.get('creds', 'username')
    password = CONF.get('creds', 'password')
    tenant = CONF.get('creds', 'tenant_name')

    host = socket.gethostname()
    novac = common.get_nova_client(username=username,
                                   password=password,
                                   tenant=tenant,
                                   url=url)

    neutronc = common.get_neutron_client(username=username,
                                         password=password,
                                         tenant=tenant,
                                         url=url)

    networks = []
    for section in CONF.sections():
        if section.startswith('network_'):
            network_id = CONF.get(section, 'neutron_net_id')
            network = get_network(neutronc, network_id)
            for option in ('device', 'bridge', 'nova_name'):
                network[option] = CONF.get(section, option)
            networks.append(network)

    instances = common.all_servers(novac, host=host)
    if direction == 'neutron':
        manager = NeutronMigration
    elif direction == 'nova':
        manager = NovaMigration
    else:
        print "unknown direction"
    print "Running checks"
    errors = migrate_interfaces(True, manager, neutronc, cursor,
                                networks, instances)
    if not noop and not errors:
        print "running for real"
        migrate_interfaces(False, manager, neutronc,
                           cursor, networks, instances)
    if errors:
        print "ERROR: Cannot run due to errors"
    cursor.close()
    conn.close()
    print "SUCCESS!"
Example #7
0
def main():
    args = collect_args()
    common.load_config(CONF, args.config)
    noop = True
    if args.for_realsies:
        noop = False
    else:
        print "Running migration in noop mode, use -f to actually migrate things"
    direction = args.direction
    conn = MySQLdb.connect(
        host=CONF.get('db', 'host'),
        user=CONF.get('db', 'user'),
        passwd=CONF.get('db', 'password'),
        db=CONF.get('db', 'name'))

    cursor = MySQLdb.cursors.DictCursor(conn)

    url = CONF.get('creds', 'auth_url')
    username = CONF.get('creds', 'username')
    password = CONF.get('creds', 'password')
    tenant = CONF.get('creds', 'tenant_name')
    region = CONF.get('creds', 'region')

    host = socket.gethostname()
    novac = common.get_nova_client(username=username,
                                   password=password,
                                   tenant=tenant,
                                   region=region,
                                   url=url)

    neutronc = common.get_neutron_client(username=username,
                                         password=password,
                                         tenant=tenant,
                                         region=region,
                                         url=url)

    networks = []
    device = 'bond0'
    # Gather neutron network id, nova network name, device/physnet, and nova bridge
    # Could generate a list? Or do we need to generate this data in generate-network-data.py?
    # Example in prod:
    # device = bond0
    # bridge = brXXX

    for section in CONF.sections():
	if section.startswith('network_default'):
	    device = CONF.get(section, 'device')

    # O hai - why aren't you defined?
    cursor.execute("SELECT * from networks WHERE project_id is not null order by id")
    nova_networks = cursor.fetchall()
    for novanet in nova_networks:
	network = get_network(neutronc, novanet['label'])
        print network
	network['device'] = device
	network['bridge'] = novanet['bridge']
	network['nova_name'] = novanet['label']
	network['neutron_net_id'] = network['id']
	networks.append(network)

    #for section in CONF.sections():
    #    if section.startswith('network_'):
    #        network_id = CONF.get(section, 'neutron_net_id')
    #        network = get_network(neutronc, network_id)
    #        for option in ('device', 'bridge', 'nova_name'):
    #            network[option] = CONF.get(section, option)
    #        networks.append(network)

    instances = common.all_servers(novac, host=host)
    if direction == 'neutron':
        manager = NeutronMigration
    elif direction == 'nova':
        manager = NovaMigration
    else:
        print "unknown direction"
    print "Running checks"
    errors = migrate_interfaces(True, manager, neutronc, cursor,
                                networks, instances)
    if not noop and not errors:
        print "running for real"
        migrate_interfaces(False, manager, neutronc,
                           cursor, networks, instances)
    if errors:
        print "ERROR: Cannot run due to errors"
    cursor.close()
    conn.close()
    print "SUCCESS!"