Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- import MySQLdb
- import sys
- import os
- import subprocess
- import csv
- import ipaddress
- from collections import OrderedDict
- from subprocess import Popen, PIPE
- from os import environ, path
- from optparse import OptionParser
- from configparser import ConfigParser
- class MysqlPython(object):
- __instance = None
- __host = None
- __user = None
- __password = None
- __database = None
- __session = None
- __connection = None
- def __new__(cls, *args, **kwargs):
- if not cls.__instance or not cls.__database:
- cls.__instance = super(MysqlPython, cls).__new__(cls, *args, **kwargs)
- return cls.__instance
- # End def __new__
- def __init__(self, host='localhost', user='root', password='', database=''):
- self.__host = host
- self.__user = user
- self.__password = password
- self.__database = database
- # End def __init__
- def __open(self):
- try:
- cnx = MySQLdb.connect(self.__host, self.__user, self.__password, self.__database)
- self.__connection = cnx
- self.__session = cnx.cursor(MySQLdb.cursors.DictCursor)
- except MySQLdb.Error as e:
- print "Error %d: %s" % (e.args[0], e.args[1])
- # End def __open
- def __close(self):
- self.__session.close()
- self.__connection.close()
- # End def __close
- def select(self, query):
- results = None
- self.__open()
- self.__session.execute(query)
- number_rows = self.__session.rowcount
- number_columns = len(self.__session.description)
- if number_rows >= 1 and number_columns > 1:
- results = [item for item in self.__session.fetchall()]
- elif number_rows > 1 and number_columns == 1:
- results = self.__session.fetchall()
- else:
- results = [item[0] for item in self.__session.fetchall()]
- self.__close()
- return results
- # End def select
- def select_one(self, query):
- self.__open()
- self.__session.execute(query)
- number_rows = self.__session.rowcount
- number_columns = len(self.__session.description)
- if number_rows > 1 or number_columns > 1:
- print "Error too mach results returned! \n"
- result = None
- else:
- result = self.__session.fetchone()
- self.__close()
- return result
- # End def select_one
- def update(self, query):
- self.__open()
- self.__session.execute(query)
- self.__connection.commit()
- # Obtain rows affected
- update_rows = self.__session.rowcount
- self.__close()
- return update_rows
- # End function update
- def insert(self, query):
- self.__open()
- self.__session.execute(query)
- self.__connection.commit()
- # Obtain last row id
- insert_rowid = self.__session.lastrowid
- self.__close()
- return insert_rowid
- ## End def insert
- def delete(self, query, values):
- self.__open()
- self.__session.execute(query, values)
- self.__connection.commit()
- # Obtain rows affected
- delete_rows = self.__session.rowcount
- self.__close()
- return delete_rows
- ## End def delete
- def create(self, create_query):
- self.__open()
- # Create table
- self.__session.execute(create_query)
- self.__close()
- return
- ## End def create
- def drop(self, table):
- self.__open()
- # Drop table if exists"
- drop_query = "DROP TABLE IF EXISTS %s " % (table)
- self.__session.execute(drop_query)
- self.__close()
- return
- ## End def drop
- # End class MysqlPython
- def source(script, update=True, clean=True):
- global environ
- if clean:
- environ_back = dict(environ)
- environ.clear()
- pipe = Popen(". %s; env" % script, stdout=PIPE, shell=True)
- data = pipe.communicate()[0]
- env = dict((line.split("=", 1) for line in data.splitlines()))
- if clean:
- # remove unwanted minimal vars
- env.pop('LINES', None)
- env.pop('COLUMNS', None)
- environ = dict(environ_back)
- if update:
- environ.update(env)
- return env
- # End def source
- def read_db_config(filename='my.cnf', section='mysql'):
- # create parser and read database ini configuration file
- parser = ConfigParser()
- parser.read(filename)
- # get section, default to mysql
- db = {}
- if parser.has_section(section):
- items = parser.items(section)
- for item in items:
- db[item[0]] = item[1]
- else:
- raise Exception(
- '{0} not found in the {1} file'.format(section, filename))
- return db
- # End def read_db_config
- def get_projectid(name, db_connect):
- sql_query = """
- SELECT id, name
- FROM keystone.project
- WHERE name='%s'
- AND enabled=1
- """ % (name)
- projectid = db_connect.select(sql_query)[0]["id"]
- return projectid
- # End def get_projectid
- def check_router(r_name, tenant_id, db_connect):
- # Check router on service tenant..
- sql_query = """
- SELECT id, name
- FROM neutron.routers
- WHERE tenant_id= '%s'
- AND status='ACTIVE'
- AND name='%s'
- """ % (tenant_id, r_name)
- if db_connect.select(sql_query):
- router_name = db_connect.select(sql_query)[0]["name"]
- else:
- router_name = None
- return router_name
- # End def check_router
- def create_neutron_router(r_name, tenant_id, db_connect, env):
- print
- # Check router on service tenant and create one if it doesn't exist..
- router = check_router(r_name, tenant_id, db_connect)
- if router:
- print "Found router '%s' on service tenant..\n" % router
- else:
- print "Neutron router not found, creating one..\n"
- router_create = ("%s --tenant-id %s --distributed True" % (r_name, tenant_id))
- subprocess.call(["neutron router-create %s" % (router_create)], env=env, shell=True)
- # End def create_neutron_router
- def check_neutron(r_name, tenant_id, db_connect, env):
- # Check basic neutron configuration..
- # Check router on service tenant..
- router = check_router(r_name, tenant_id, db_connect)
- if router:
- print "Found router '%s' on service tenant..\n" % (router)
- else:
- print "Neutron router '%s' not found!\n" % (r_name)
- # Check networks..
- sql_query = """
- SELECT n.name AS n_name, p.name AS p_name
- FROM neutron.networks n
- JOIN keystone.project p
- ON n.tenant_id=p.id
- WHERE n.status='ACTIVE'
- """
- if db_connect.select(sql_query):
- print "Found neutron networks..\n"
- subprocess.call(["neutron", "net-list"], env=env)
- else:
- print "No neutron networks found!\n"
- # Check subnets..
- sql_query = """
- SELECT p.name AS project, n.name AS network, s.name AS subnet, s.cidr, s.gateway_ip
- FROM neutron.subnets s
- JOIN keystone.project p
- ON s.tenant_id=p.id
- JOIN neutron.networks n
- ON s.network_id=n.id
- WHERE n.status='ACTIVE'
- AND p.enabled='1'
- """
- if db_connect.select(sql_query):
- print "Found neutron subnets..\n"
- subprocess.call(["neutron", "subnet-list"], env=env)
- else:
- print "No neutron subnets found!\n"
- # End def check_neutron
- def create_external_networks(router, ext_nets, t_service, env):
- # From "ext_nets" configuration file, create one external network named "floating".
- # Update these options if creating more than one external network.
- with open(ext_nets) as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- net_create = ("--tenant-id %s --provider:physical_network external --provider:network_type vlan --provider:segmentation_id %s --router:external floating"
- % (t_service, row['vlan_id']))
- print
- print "Creating external floating network vlan %s..\n" % (row['vlan_id'])
- subprocess.call(["neutron net-create %s" % (net_create)], env=env, shell=True)
- subnet_create = ("--tenant-id %s --name floating-subnet --disable-dhcp --allocation-pool start=%s,end=%s --dns-nameserver %s --dns-nameserver %s --gateway %s floating %s"
- % (t_service, row['pool_start'], row['pool_end'], row['dns1'], row['dns2'], row['gateway'], row['network']))
- print
- print "Creating external subnet floating-subnet..\n"
- subprocess.call(["neutron subnet-create %s" % (subnet_create)], env=env, shell=True)
- print
- print "Creating gateway for floating network..\n"
- router_gateway = ("--fixed-ip ip_address=%s %s floating" % (row['v_gateway'], router))
- subprocess.call(["neutron router-gateway-set %s" % (router_gateway)], env=env, shell=True)
- # End def create_external_networks
- def get_network_id(filename='network.out'):
- uuid = None
- with open(filename) as f:
- for line in f:
- line = line.replace(' ', '')
- if "|id|" in line:
- uuid = line.split("|")[2]
- break
- return uuid
- # End def get_network_id
- def create_internal_networks(db_connect, env):
- print
- sql_query = """
- SELECT uuid, project_id, label, vlan, cidr, netmask, dhcp_start, gateway
- FROM nova.networks
- WHERE deleted_at IS NULL
- """
- for row in db_connect.select(sql_query):
- print "Creating internal network '%s' vlan '%s'..\n" % (row['label'], row['vlan'])
- net_create = ("--tenant-id %s --provider:physical_network internal --provider:network_type vlan --provider:segmentation_id %s %s"
- % (row["project_id"], row['vlan'], row['label']))
- with open('network.out', 'w') as f:
- subprocess.call(["neutron net-create %s" % (net_create)], env=env, shell=True, stdout=f)
- # getting the new neutron network 'id'
- network_id = get_network_id()
- if not network_id:
- print "There was a problem getting the new network id..\n"
- return 1
- print "Updating uuid '%s' of the internal network '%s' vlan '%s' using existing uuid '%s'..\n" % (network_id, row['label'], row['vlan'], row["uuid"])
- sql_update = ("UPDATE neutron.networks SET id = '%s' WHERE id = '%s'" % (row["uuid"], network_id))
- db_connect.update(sql_update)
- print "Finished creating neutron networks.."
- subprocess.call(["neutron", "net-list"], env=env)
- # End def create_internal_networks
- def create_temporary_data(int_nets, int_pools, pools_update, db_connect, env):
- # Create network temporary table
- sql_create = """
- CREATE TABLE `nova`.`network_tmp` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `vlan_id` int(11) NOT NULL,
- `dns1` varchar(39) NOT NULL,
- `dns2` varchar(39) NOT NULL,
- `gateway` varchar(39) DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
- """
- db_connect.create(sql_create)
- with open(int_nets) as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- sql_insert = """INSERT INTO `nova`.`network_tmp`
- SET vlan_id = %d, dns1 = '%s', dns2 = '%s', gateway = '%s'
- """ % (int(row['vlan_id']), row['dns1'], row['dns2'], row['gateway'])
- db_connect.insert(sql_insert)
- # Create network pools temporary table
- sql_create = """
- CREATE TABLE `nova`.`network_pools_tmp` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `vlan_id` int(11) NOT NULL,
- `pool_start` varchar(39) NOT NULL,
- `pool_end` varchar(39) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
- """
- # CONSTRAINT `network_pools_tmp_fk` FOREIGN KEY (`vlan_id`) REFERENCES `nova`.`network_tmp` (`vlan_id`) ON DELETE CASCADE
- db_connect.create(sql_create)
- with open(int_pools) as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- sql_insert = """INSERT INTO `nova`.`network_pools_tmp`
- SET vlan_id = %d, pool_start = '%s', pool_end = '%s'
- """ % (int(row['vlan_id']), row['pool_start'], row['pool_end'])
- db_connect.insert(sql_insert)
- # Create network pools update temporary table
- sql_create = """
- CREATE TABLE `nova`.`network_pools_update_tmp` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `vlan_id` int(11) NOT NULL,
- `pool_start` varchar(39) NOT NULL,
- `pool_end` varchar(39) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
- """
- db_connect.create(sql_create)
- with open(pools_update) as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- sql_insert = """INSERT INTO `nova`.`network_pools_update_tmp`
- SET vlan_id = %d, pool_start = '%s', pool_end = '%s'
- """ % (int(row['vlan_id']), row['pool_start'], row['pool_end'])
- db_connect.insert(sql_insert)
- # End def create_temporary_data
- def create_internal_subnets(router, db_connect, env):
- sql_query = """
- SELECT nn.uuid, nn.project_id, nn.label, nn.vlan, nn.cidr, nn.gateway as v_gateway, nt.dns1, nt.dns2, nt.gateway as p_gateway
- FROM nova.networks nn
- JOIN nova.network_tmp nt
- WHERE nn.vlan=nt.vlan_id
- AND nn.deleted_at IS NULL
- """
- for row in db_connect.select(sql_query):
- sql_query_pools = """
- SELECT pool_start, pool_end
- FROM nova.network_pools_tmp
- WHERE vlan_id = %d
- """ % int(row['vlan'])
- allocation_pool = ""
- for pool in db_connect.select(sql_query_pools):
- allocation_pool += ("--allocation-pool start=%s,end=%s " % (pool["pool_start"], pool['pool_end']))
- intf = ipaddress.ip_interface(u"%s" % (row['cidr']))
- if intf.network.is_private:
- if row['p_gateway']:
- print
- print "Creating internal subnet 'subnet%s' for private routed network '%s'..\n" % (row['vlan'], row['cidr'])
- if row['dns1']:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --dns-nameserver %s --dns-nameserver %s --gateway %s --host-route destination=134.158.0.0/16,nexthop=%s --host-route destination=193.48.96.0/20,nexthop=%s --host-route destination=193.48.80.0/20,nexthop=%s --host-route destination=193.48.112.0/23,nexthop=%s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['dns1'], row['dns2'], row['v_gateway'], row['p_gateway'], row['p_gateway'], row['p_gateway'], row['p_gateway'], row['label'], row['cidr']))
- else:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --gateway %s --host-route destination=134.158.0.0/16,nexthop=%s --host-route destination=193.48.96.0/20,nexthop=%s --host-route destination=193.48.80.0/20,nexthop=%s --host-route destination=193.48.112.0/23,nexthop=%s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['v_gateway'], row['p_gateway'], row['p_gateway'], row['p_gateway'], row['p_gateway'], row['label'], row['cidr']))
- subprocess.call(["neutron subnet-create %s" % (subnet_create)], env=env, shell=True)
- else:
- print
- print "Creating internal subnet 'subnet%s' for private not routed network '%s'..\n" % (row['vlan'], row['cidr'])
- if row['dns1']:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --dns-nameserver %s --dns-nameserver %s --gateway %s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['dns1'], row['dns2'], row['v_gateway'], row['label'], row['cidr']))
- else:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --gateway %s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['v_gateway'], row['label'], row['cidr']))
- subprocess.call(["neutron subnet-create %s" % (subnet_create)], env=env, shell=True)
- print
- print "Creating gateway for subnet%s..\n" % (row['vlan'])
- router_gateway = ("%s subnet%s" % (router, row['vlan']))
- subprocess.call(["neutron router-interface-add %s" % (router_gateway)], env=env, shell=True)
- else:
- print
- print "Creating internal subnet 'subnet%s' for public network '%s'..\n" % (row['vlan'], row['cidr'])
- if row['dns1']:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --dns-nameserver %s --dns-nameserver %s --no-gateway --host-route destination=0.0.0.0/0,nexthop=%s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['dns1'], row['dns2'], row['p_gateway'], row['label'], row['cidr']))
- else:
- subnet_create = ("--tenant-id %s --name subnet%s --enable-dhcp %s --no-gateway --host-route destination=0.0.0.0/0,nexthop=%s %s %s" % (row['project_id'], row['vlan'], allocation_pool, row['p_gateway'], row['label'], row['cidr']))
- subprocess.call(["neutron subnet-create %s" % (subnet_create)], env=env, shell=True)
- print
- print "Updating ports quota for project '%s' (subnet 'subnet%s', network '%s')..\n" % (row['project_id'], row['vlan'], row['cidr'])
- quota_udate = ("--port %s --tenant-id %s " % (intf.network.num_addresses, row['project_id']))
- subprocess.call(["neutron quota-update %s" % (quota_udate)], env=env, shell=True)
- quota_udate = ("--security-group %d --security-group-rule %d --tenant-id %s " % ((1), (4), row['project_id']))
- subprocess.call(["neutron quota-update %s" % (quota_udate)], env=env, shell=True)
- # End def create_internal_subnets
- def update_subnets(db_connect, env):
- sql_query = """
- SELECT distinct(vlan_id)
- FROM nova.network_pools_update_tmp
- """
- for row in db_connect.select(sql_query):
- sql_query_pools_update = """
- SELECT pool_start, pool_end
- FROM nova.network_pools_update_tmp
- WHERE vlan_id = %d
- """ % int(row['vlan_id'])
- allocation_pool = ""
- for pool in db_connect.select(sql_query_pools_update):
- allocation_pool += ("--allocation-pool start=%s,end=%s " % (pool["pool_start"], pool['pool_end']))
- subnet_pool_update = ("%s subnet%s" % (allocation_pool, row['vlan_id']))
- print
- print "Update allocation pool for subnet%s..\n" % (row['vlan_id'])
- subprocess.call(["neutron subnet-update %s" % (subnet_pool_update)], env=env, shell=True)
- # End def update_subnets
- def get_port_id(filename='port.out'):
- uuid = None
- with open(filename) as f:
- for line in f:
- line = line.replace(' ', '')
- if "|id|" in line:
- uuid = line.split("|")[2]
- break
- return uuid
- # End def get_port_id
- def create_ports(db_connect, env):
- sql_query = """
- SELECT n.vlan, n.uuid as network_uuid, i.project_id, v.instance_uuid, i.hostname as instance_name, v.address as mac_address, f.address as ip_address, i.availability_zone, i.host
- FROM nova.virtual_interfaces as v
- JOIN (nova.networks as n, nova.instances as i, nova.fixed_ips as f)
- WHERE v.network_id = n.id
- AND v.instance_uuid = i.uuid
- AND v.id = f.virtual_interface_id
- AND v.deleted_at IS NULL
- AND f.deleted_at IS NULL
- ORDER BY i.host, n.vlan ASC
- """
- compute_name = None
- for row in db_connect.select(sql_query):
- port_create = ("--tenant-id %s --mac-address %s --fixed-ip subnet_id=subnet%s,ip_address=%s --device-owner compute:%s %s" % (row['project_id'], row['mac_address'], row['vlan'], row['ip_address'], row['availability_zone'], row['network_uuid']))
- print
- print "Creating neutron port for instance '%s' (mac=%s, ip=%s).. \n" % (row['instance_name'], row['mac_address'], row['ip_address'])
- with open('port.out', 'w') as f:
- subprocess.call(["neutron port-create %s" % (port_create)], env=env, shell=True, stdout=f)
- # getting the neutron port 'id'
- port_id = get_port_id()
- if not port_id:
- print "There was a problem getting the port id..\n"
- return 1
- print "Attach neutron port (id=%s, mac=%s, ip=%s) to instance '%s' .. \n" % (port_id, row['mac_address'], row['ip_address'],row['instance_name'])
- #print "Instance '%s' must be in a normal state.. \n" % (row['instance_name'])
- port_attach = ("--port-id %s %s" % (port_id, row['instance_uuid']))
- print "Saving data to file attach_ports for later use.. \n"
- with open('attach_ports', 'a') as p:
- if row['host'] != compute_name:
- p.write("######################################\n")
- p.write("# Compute: %s \n" % (row['host']))
- p.write("######################################\n")
- p.write("#neutron port-create %s \n" % (port_create))
- p.write("nova interface-attach %s \n" % (port_attach))
- compute_name = row['host']
- #print "Port attachment disabled during migration process.. \n"
- #subprocess.call(["nova interface-attach %s" % (port_attach)], env=env, shell=True)
- # End def create_ports
- def enable_dhcp(db_connect, env):
- sql_query = """
- SELECT id, name
- FROM neutron.subnets
- WHERE gateway_ip IS NULL
- AND enable_dhcp=0
- """
- for row in db_connect.select(sql_query):
- print
- print "Adding dhcp support for subnet '%s'.. \n" % (row['name'])
- subprocess.call(["neutron subnet-update --enable-dhcp %s" % (row['id'])], env=env, shell=True)
- # End def enable_dhcp
- def get_ext_netid(ip_address, db_connect, env):
- ext_netid = None
- sql_query = """SELECT name, network_id, cidr
- FROM neutron.subnets
- """
- #WHERE name like 'ext-%'
- for row in db_connect.select(sql_query):
- if ipaddress.ip_address(u"%s" % (ip_address)) in ipaddress.ip_network(u"%s" % (row['cidr'])):
- print
- print "Found network '%s' (%s) for floating ip '%s' \n" % (row['cidr'], row['name'], ip_address)
- ext_netid = row['network_id']
- break
- # else:
- # print "Floating ip '%s' is not part of network '%s' (%s) \n" % (ip_address, row['cidr'], row['name'])
- return ext_netid
- # End def get_ext_netid
- def create_floating_ips(db_connect, env):
- sql_query = """
- SELECT fl.project_id, fl.address AS floating_ip, fx.address AS fixed_ip, v.address AS fixed_mac, fx.instance_uuid
- FROM nova.fixed_ips AS fx
- JOIN (nova.floating_ips AS fl, nova.virtual_interfaces AS v)
- WHERE fx.id = fl.fixed_ip_id
- AND fx.virtual_interface_id = v.id
- AND fx.deleted_at IS NULL
- AND fl.deleted_at IS NULL
- AND v.deleted_at IS NULL
- """
- for row in db_connect.select(sql_query):
- sql_getport = """SELECT id
- FROM neutron.ports
- WHERE mac_address='%s'
- AND tenant_id='%s'
- """ % (row['fixed_mac'], row['project_id'])
- port_id = db_connect.select_one(sql_getport)['id']
- network_id = get_ext_netid(row['floating_ip'], db_connect, env)
- sql_getinstance = """SELECT hostname
- FROM nova.instances
- WHERE uuid = '%s'
- """ % (row['instance_uuid'])
- instance_name = db_connect.select_one(sql_getinstance)['hostname']
- print "creating floating ip '%s' for instance '%s' (uuid='%s', ip='%s').. \n" % (row['floating_ip'], instance_name, row['instance_uuid'], row['fixed_ip'])
- floatingip_create = ("--tenant-id %s --port-id %s --floating-ip-address %s %s" % (row['project_id'], port_id, row['floating_ip'], network_id))
- subprocess.call(["neutron floatingip-create %s" % (floatingip_create)], env=env, shell=True)
- # End def create_floating_ips
- noop = False
- def main():
- global noop
- nova_creds, mysql_conf, ext_nets, int_nets, int_pools, pools_update, r_name, exec_type = parse_options()
- # openstack creds and environment variables
- if os.path.isfile(nova_creds) and os.access(nova_creds, os.R_OK):
- env = {}
- # env.update(os.environ)
- env.update(source(nova_creds))
- else:
- print "Either creds file is missing or is not readable!\n"
- return 1
- # database connection
- if os.path.isfile(mysql_conf) and os.access(mysql_conf, os.R_OK):
- dsn = read_db_config(mysql_conf)
- db_connect = MysqlPython(dsn['host'], dsn['user'], dsn['password'], dsn['database'])
- else:
- print "Either mysql configuration file is missing or is not readable!\n"
- return 1
- # service tenant_id
- t_service = get_projectid('service', db_connect)
- # Run exec types
- if exec_type == 'test':
- # work in progress
- print "Checking Neutron configuration..\n"
- check_neutron(r_name, t_service, db_connect, env)
- elif exec_type == 'migration':
- # delete temporary data
- print "Removing temporary data before creation..\n"
- db_connect.drop('`nova`.`network_tmp`')
- db_connect.drop('`nova`.`network_pools_tmp`')
- db_connect.drop('`nova`.`network_pools_update_tmp`')
- # work in progress
- print "Processig network migration..\n"
- # create neutron router if it doesn't exist
- create_neutron_router(r_name, t_service, db_connect, env)
- # external networks configuration
- if os.path.isfile(ext_nets) and os.access(ext_nets, os.R_OK):
- print
- print "Creating external networks..\n"
- create_external_networks(r_name, ext_nets, t_service, env)
- else:
- print
- print "Either external networks configuration file is missing or is not readable!\n"
- return 1
- # internal networks configuration
- create_internal_networks(db_connect, env)
- # create temporary data for internal subnets
- if os.path.isfile(int_nets) and os.access(int_nets, os.R_OK):
- if os.path.isfile(int_pools) and os.access(int_pools, os.R_OK):
- print
- print "Creating temporary data for internal subnets..\n"
- create_temporary_data(int_nets, int_pools, pools_update, db_connect, env)
- else:
- print
- print "Either internal network pools configuration file is missing or is not readable!\n"
- return 1
- else:
- print
- print "Either internal networks configuration file is missing or is not readable!\n"
- return 1
- # create internal subnets
- print "Creating internal subnets..\n"
- create_internal_subnets(r_name, db_connect, env)
- # create ports
- print "Creating ports..\n"
- create_ports(db_connect, env)
- # enable dhcp for routed public networks
- enable_dhcp(db_connect, env)
- # create floating ips
- #print
- #print "Creating floating ips..\n"
- #create_floating_ips(db_connect, env)
- # update subnet pools
- if os.path.isfile(pools_update) and os.access(pools_update, os.R_OK):
- print
- print "Updating subnet pools..\n"
- update_subnets(db_connect, env)
- else:
- print
- print "Either pools_update configuration file is missing or is not readable!\n"
- return 1
- print "Removing temporary data after creation..\n"
- db_connect.drop('`nova`.`network_tmp`')
- db_connect.drop('`nova`.`network_pools_tmp`')
- db_connect.drop('`nova`.`network_pools_update_tmp`')
- # End main
- def parse_options():
- global noop
- parser = OptionParser(__doc__)
- parser.add_option("-c", "--creds",
- dest="nova_creds",
- #default = os.path.expanduser('./creds'),
- default="./creds",
- help="path to nova_creds file (default to 'creds')")
- parser.add_option("-m", "--mycnf",
- dest="mysql_conf",
- default="./mysql.ini",
- help="path to mysql configuration file (default to 'mysql.ini')")
- parser.add_option("-x", "--extnets",
- dest="ext_nets",
- default="./ext_nets",
- help="""path to external networks configuration file (default to 'ext_nets')""")
- parser.add_option("-i", "--intnets",
- dest="int_nets",
- default="./int_nets",
- help="""path to internal networks configuration file (default to 'int_nets')""")
- parser.add_option("-p", "--pools",
- dest="int_pools",
- default="./int_pools",
- help="""path to internal network pools configuration file (default to 'int_pools')""")
- parser.add_option("-u", "--update",
- dest="pools_update",
- default="./pools_update",
- help="""path to network pools update configuration file (default to 'pools_update')""")
- parser.add_option("-r", "--router",
- dest="r_name",
- default="router01",
- help="Neutron router name (default to 'router01')")
- parser.add_option("-e", "--exec",
- type="choice",
- action="store",
- dest="exec_type",
- choices=["migration", "test", ],
- default="test",
- help="""[migration]: Execute migration to Neutron,
- [test]: Check Neutron configuration (default)""")
- parser.add_option("-n", "--noop",
- dest="noop",
- action="store_true",
- help="Take no actions (dry-run)")
- (options, _) = parser.parse_args()
- nova_creds, mysql_conf, ext_nets, int_nets, int_pools, pools_update, r_name, exec_type = options.nova_creds, options.mysql_conf, options.ext_nets, options.int_nets, options.int_pools, options.pools_update, options.r_name, options.exec_type
- noop = options.noop
- return nova_creds, mysql_conf, ext_nets, int_nets, int_pools, pools_update, r_name, exec_type
- # End def parse_options
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement