def insert_lswitches(self, cursor): print("Inserting nvp driver lswitches...") m = 0 query = """ INSERT INTO quark_nvp_driver_lswitch ( `id`, `nvp_id`, `network_id`, `display_name`, `port_count`, `transport_zone`, `transport_connector`, `segment_id`) VALUES """ port_query = """ INSERT INTO quark_nvp_driver_lswitchport ( `id`, `port_id`, `switch_id`, `created_at`) VALUES """ switchids = [] for switch, ports in self.quark_nvp_stuff.iteritems(): switch = mysqlize(switch) query += "({0},{1},{2},{3},{4},{5},{6},{7}),\n".format( switch.id, switch.nvp_id, switch.network_id, switch.display_name, switch.port_count, switch.transport_zone, # TODO: isolated nets not NULL switch.transport_connector, switch.segment_connector, switch.segment_id) # TODO: created_at add for port in ports: if port.port_id != 'TODO': m += 1 port = mysqlize(port) port_query += "('{0}',{1},{2},{3}),\n".format( str(uuid4()), port.port_id, switch.id, port.created_at) query = query.rstrip(',\n') port_query = port_query.rstrip(',\n') with open("quark_nvp_lswitch.sql", "w") as f: f.write(query) with open("quark_nvp_ports.sql", "w") as f: f.write(port_query) try: cursor.execute(query) cursor.execute(port_query) except Exception as e: print("\tError inserting nvp ports: {}".format(e)) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_lswitches(self, cursor): print("Inserting nvp driver lswitches...") m = 0 query = """ INSERT INTO quark_nvp_driver_lswitch ( `id`, `nvp_id`, `network_id`, `display_name`, `port_count`, `transport_zone`, `transport_connector`, `segment_id`) VALUES """ port_query = """ INSERT INTO quark_nvp_driver_lswitchport ( `id`, `port_id`, `switch_id`, `created_at`) VALUES """ switchids = [] for switch, ports in self.quark_nvp_stuff.iteritems(): switch = mysqlize(switch) query += "({0},{1},{2},{3},{4},{5},{6},{7}),\n".format( switch.id, switch.nvp_id, switch.network_id, switch.display_name, switch.port_count, switch.transport_zone, # TODO: isolated nets not NULL switch.transport_connector, switch.segment_connector, switch.segment_id) # TODO: created_at add for port in ports: if port.port_id != 'TODO': m += 1 port = mysqlize(port) port_query += "('{0}',{1},{2},{3}),\n".format(str(uuid4()), port.port_id, switch.id, port.created_at) query = query.rstrip(',\n') port_query = port_query.rstrip(',\n') with open("quark_nvp_lswitch.sql", "w") as f: f.write(query) with open("quark_nvp_ports.sql", "w") as f: f.write(port_query) try: cursor.execute(query) cursor.execute(port_query) except Exception as e: print("\tError inserting nvp ports: {}".format(e)) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, m))
def insert_policies(self, cursor): print("Inserting policies...") m = 0 query = """ INSERT INTO quark_ip_policy ( `id`, `name`, `tenant_id`, `description`, `created_at`) VALUES """ for record in self.quark_ip_policies.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4}),\n".format( record.id, record.name, record.tenant_id, record.description, record.created_at) with open('quark_ip_policies.sql', 'w') as f: f.write(query.rstrip(',\n')) cursor.execute(query.rstrip(',\n')) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, m))
def insert_routes(self, cursor): print("Inserting routes...") query = """ INSERT INTO quark_routes ( `id`, `tenant_id`, `created_at`, `cidr`, `gateway`, `subnet_id`, `tag_association_uuid`) VALUES """ for route_id, route in self.quark_routes.iteritems(): record = mysqlize(route) query += "({0},{1},{2},{3},{4},{5},{6}),\n".format( record.id, record.tenant_id, record.created_at, record.cidr, record.gateway, record.subnet_id, record.tag_association_uuid) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, len(self.quark_routes)))
def insert_networks(self, cursor): print("Inserting networks...") m = 0 query = """ INSERT INTO quark_networks ( `id`, `tenant_id`, `created_at`, `name`, `ipam_strategy`, `network_plugin`) VALUES """ for record in self.quark_networks.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4},{5}),\n".format( record.id, record.tenant_id, record.created_at, record.name, record.ipam_strategy, #record.max_allocation, record.network_plugin) query = query.rstrip(',\n') with open('quark_networks.sql', 'w') as f: f.write(query) cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_networks(self, cursor): print("Inserting networks...") m = 0 query = """ INSERT INTO quark_networks ( `id`, `tenant_id`, `created_at`, `name`, `ipam_strategy`, `network_plugin`) VALUES """ for record in self.quark_networks.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4},{5}),\n".format(record.id, record.tenant_id, record.created_at, record.name, record.ipam_strategy, #record.max_allocation, record.network_plugin) query = query.rstrip(',\n') with open('quark_networks.sql', 'w') as f: f.write(query) cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_quark_dns_nameservers(self, cursor): print("Inserting dns nameservers...") query = """ INSERT INTO quark_dns_nameservers ( `id`, `tenant_id`, `created_at`, `ip`, `subnet_id`, `tag_association_uuid`) VALUES """ for ns_id, ns in self.quark_dns_nameservers.iteritems(): record = mysqlize(ns) query += "({0},{1},{2},{3},{4},{5}),\n".format( record.id, record.tenant_id, record.created_at, record.ip, record.subnet_id, record.tag_association_uuid) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, len(self.quark_dns_nameservers)))
def insert_mac_addresses(self, cursor): print("Inserting mac addressess...") m = 0 query = """ INSERT INTO quark_mac_addresses ( `tenant_id`, `created_at`, `address`, `mac_address_range_id`, `deallocated`, `deallocated_at`) VALUES """ for mac_range_id, macs in self.quark_mac_addresses.iteritems(): mac_range = mysqlize(self.mac_address_ranges[mac_range_id]) # There is only one mac range so this is fine: cursor.execute(""" INSERT INTO quark_mac_address_ranges ( `id`, `created_at`, `cidr`, `first_address`, `last_address`, `next_auto_assign_mac`) VALUES ({0},{1},{2},{3},{4},{5})""".format( mac_range.id, mac_range.created_at, mac_range.cidr, mac_range.first_address, mac_range.last_address, mac_range.next_auto_assign_mac)) for mac in macs: m += 1 mac = mysqlize(mac) query += "({0},{1},{2},{3},'0',{5}),\n".format( mac.tenant_id, mac.created_at, mac.address, mac.mac_address_range_id, mac.deallocated, mac.deallocated_at) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, m))
def insert_mac_addresses(self, cursor): print("Inserting mac addressess...") m = 0 query = """ INSERT INTO quark_mac_addresses ( `tenant_id`, `created_at`, `address`, `mac_address_range_id`, `deallocated`, `deallocated_at`) VALUES """ for mac_range_id, macs in self.quark_mac_addresses.iteritems(): mac_range = mysqlize(self.mac_address_ranges[mac_range_id]) # There is only one mac range so this is fine: cursor.execute(""" INSERT INTO quark_mac_address_ranges ( `id`, `created_at`, `cidr`, `first_address`, `last_address`, `next_auto_assign_mac`) VALUES ({0},{1},{2},{3},{4},{5})""".format( mac_range.id, mac_range.created_at, mac_range.cidr, mac_range.first_address, mac_range.last_address, mac_range.next_auto_assign_mac)) for mac in macs: m += 1 mac = mysqlize(mac) query += "({0},{1},{2},{3},'0',{5}),\n".format( mac.tenant_id, mac.created_at, mac.address, mac.mac_address_range_id, mac.deallocated, mac.deallocated_at) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_ip_addresses(self, cursor): print("Inserting ip addresses...") m = 0 # this giant query needs to be broken down into bite-sized chunks # make a list of the strings for insertion then send them off query = """ INSERT INTO quark_ip_addresses ( `id`, `address_readable`, `address`, `used_by_tenant_id`, `created_at`, `subnet_id`, `network_id`, `version`, `_deallocated`, `deallocated_at`, `allocated_at`) VALUES """ all_records = [] for record in self.quark_ip_addresses.values(): record = mysqlize(record) m += 1 all_records.append("({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}),\n".format( record.id, record.address_readable, record.address, record.used_by_tenant_id, record.created_at, record.subnet_id, record.network_id, record.version, record._deallocated, record.deallocated_at, record.allocated_at)) chunks = paginate_query(all_records) n = 0 for i, chunk in enumerate(chunks): chunk_query = query + chunk chunk_query = chunk_query.rstrip(',\n') with open('quark_ip_addresses_{}.sql'.format(i), 'w') as f: f.write(chunk_query) cursor.execute(chunk_query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_subnets(self, cursor): print("Inserting subnets...") m = 0 query = """ INSERT INTO quark_subnets ( `id`, `tenant_id`, `created_at`, `network_id`, `_cidr`, `first_ip`, `last_ip`, `ip_version`, `next_auto_assign_ip`, `tag_association_uuid`, `do_not_use`, `name`, `ip_policy_id`, `enable_dhcp`, `segment_id`) VALUES """ for record in self.quark_subnets.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}),\n".format( record.id, record.tenant_id, record.created_at, record.network_id, record._cidr, record.first_ip, record.last_ip, record.ip_version, record.next_auto_assign_ip, record.tag_association_uuid, record.do_not_use, record.name, record.ip_policy_id, record.enable_dhcp, record.segment_id) with open("quark_subnets.sql", 'w') as f: f.write(query) cursor.execute(query.rstrip(',\n')) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_ports(self, cursor): print("Inserting ports...") m = 0 query = """ INSERT INTO quark_ports ( `id`, `tenant_id`, `created_at`, `name`, `admin_state_up`, `network_id`, `backend_key`, `mac_address`, `device_id`, `device_owner`, `bridge`) VALUES """ all_records = [] for record in self.port_cache.values(): record = mysqlize(record) m += 1 all_records.append( "({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}),\n".format( record.id, record.tenant_id, record.created_at, record.name, record.admin_state_up, record.network_id, record.backend_key, # TODO shouldnt be TODO record.mac_address, record.device_id, record.device_owner, record.bridge)) # TODO come back to this chunks = paginate_query(all_records) for i, chunk in enumerate(chunks): chunk_query = query + chunk chunk_query = chunk_query.rstrip(',\n') with open('quark_ports_{}.sql'.format(i), 'w') as f: f.write(chunk_query) cursor.execute(chunk_query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_ports(self, cursor): print("Inserting ports...") m = 0 query = """ INSERT INTO quark_ports ( `id`, `tenant_id`, `created_at`, `name`, `admin_state_up`, `network_id`, `backend_key`, `mac_address`, `device_id`, `device_owner`, `bridge`) VALUES """ all_records = [] for record in self.port_cache.values(): record = mysqlize(record) m += 1 all_records.append("({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}),\n".format( record.id, record.tenant_id, record.created_at, record.name, record.admin_state_up, record.network_id, record.backend_key, # TODO shouldnt be TODO record.mac_address, record.device_id, record.device_owner, record.bridge)) # TODO come back to this chunks = paginate_query(all_records) for i, chunk in enumerate(chunks): chunk_query = query + chunk chunk_query = chunk_query.rstrip(',\n') with open('quark_ports_{}.sql'.format(i), 'w') as f: f.write(chunk_query) cursor.execute(chunk_query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_quotas(self, cursor): print("Inserting quotas...") query = """ INSERT INTO quark_quotas ( `id`, `tenant_id`, `limit`, `resource`) VALUES """ for tenant_id, quota in self.quark_quotas.iteritems(): record = mysqlize(quota) query += "({0},{1},{2},{3}),\n".format(record.id, record.tenant_id, record.limit, record.resource) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, len(self.quark_ip_policy_cidrs)))
def insert_ip_addresses(self, cursor): print("Inserting ip addresses...") m = 0 # this giant query needs to be broken down into bite-sized chunks # make a list of the strings for insertion then send them off query = """ INSERT INTO quark_ip_addresses ( `id`, `address_readable`, `address`, `used_by_tenant_id`, `created_at`, `subnet_id`, `network_id`, `version`, `_deallocated`, `deallocated_at`, `allocated_at`) VALUES """ all_records = [] for record in self.quark_ip_addresses.values(): record = mysqlize(record) m += 1 all_records.append( "({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}),\n".format( record.id, record.address_readable, record.address, record.used_by_tenant_id, record.created_at, record.subnet_id, record.network_id, record.version, record._deallocated, record.deallocated_at, record.allocated_at)) chunks = paginate_query(all_records) n = 0 for i, chunk in enumerate(chunks): chunk_query = query + chunk chunk_query = chunk_query.rstrip(',\n') with open('quark_ip_addresses_{}.sql'.format(i), 'w') as f: f.write(chunk_query) cursor.execute(chunk_query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_ip_policy_rules(self, cursor): print("Inserting ip policy rules...") query = """ INSERT INTO quark_ip_policy_cidrs ( `id`, `ip_policy_id`, `created_at`, `cidr`) VALUES """ for rule_id, rule in self.quark_ip_policy_cidrs.iteritems(): record = mysqlize(rule) query += "({0},{1},{2},{3}),\n".format(record.id, record.ip_policy_id, record.created_at, record.cidr) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, len(self.quark_ip_policy_cidrs)))
def insert_quotas(self, cursor): print("Inserting quotas...") query = """ INSERT INTO quark_quotas ( `id`, `tenant_id`, `limit`, `resource`) VALUES """ for tenant_id, quota in self.quark_quotas.iteritems(): record = mysqlize(quota) query += "({0},{1},{2},{3}),\n".format( record.id, record.tenant_id, record.limit, record.resource) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, len(self.quark_ip_policy_cidrs)))
def insert_quark_dns_nameservers(self, cursor): print("Inserting dns nameservers...") query = """ INSERT INTO quark_dns_nameservers ( `id`, `tenant_id`, `created_at`, `ip`, `subnet_id`, `tag_association_uuid`) VALUES """ for ns_id, ns in self.quark_dns_nameservers.iteritems(): record = mysqlize(ns) query += "({0},{1},{2},{3},{4},{5}),\n".format( record.id, record.tenant_id, record.created_at, record.ip, record.subnet_id, record.tag_association_uuid) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, len(self.quark_dns_nameservers)))
def insert_ip_policy_rules(self, cursor): print("Inserting ip policy rules...") query = """ INSERT INTO quark_ip_policy_cidrs ( `id`, `ip_policy_id`, `created_at`, `cidr`) VALUES """ for rule_id, rule in self.quark_ip_policy_cidrs.iteritems(): record = mysqlize(rule) query += "({0},{1},{2},{3}),\n".format( record.id, record.ip_policy_id, record.created_at, record.cidr) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format(time.time() - self.start_time, len(self.quark_ip_policy_cidrs)))
def insert_routes(self, cursor): print("Inserting routes...") query = """ INSERT INTO quark_routes ( `id`, `tenant_id`, `created_at`, `cidr`, `gateway`, `subnet_id`, `tag_association_uuid`) VALUES """ for route_id, route in self.quark_routes.iteritems(): record = mysqlize(route) query += "({0},{1},{2},{3},{4},{5},{6}),\n".format( record.id, record.tenant_id, record.created_at, record.cidr, record.gateway, record.subnet_id, record.tag_association_uuid) query = query.rstrip(',\n') cursor.execute(query) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, len(self.quark_routes)))
def insert_policies(self, cursor): print("Inserting policies...") m = 0 query = """ INSERT INTO quark_ip_policy ( `id`, `name`, `tenant_id`, `description`, `created_at`) VALUES """ for record in self.quark_ip_policies.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4}),\n".format(record.id, record.name, record.tenant_id, record.description, record.created_at) with open('quark_ip_policies.sql', 'w') as f: f.write(query.rstrip(',\n')) cursor.execute(query.rstrip(',\n')) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))
def insert_subnets(self, cursor): print("Inserting subnets...") m = 0 query = """ INSERT INTO quark_subnets ( `id`, `tenant_id`, `created_at`, `network_id`, `_cidr`, `first_ip`, `last_ip`, `ip_version`, `next_auto_assign_ip`, `tag_association_uuid`, `do_not_use`, `name`, `ip_policy_id`, `enable_dhcp`, `segment_id`) VALUES """ for record in self.quark_subnets.values(): m += 1 record = mysqlize(record) query += "({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}),\n".format( record.id, record.tenant_id, record.created_at, record.network_id, record._cidr, record.first_ip, record.last_ip, record.ip_version, record.next_auto_assign_ip, record.tag_association_uuid, record.do_not_use, record.name, record.ip_policy_id, record.enable_dhcp, record.segment_id) with open("quark_subnets.sql", 'w') as f: f.write(query) cursor.execute(query.rstrip(',\n')) print("\tDone, {:.2f} sec, {} migrated.".format( time.time() - self.start_time, m))