From: mirabal Date: Mon, 13 Feb 2017 11:41:49 +0000 (+0100) Subject: Add gateway_ip to nets DB table X-Git-Tag: v2.0.0~52 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=18f5de3f9de56ad4b608daf1e9107e65dc22a851;p=osm%2Fopenvim.git Add gateway_ip to nets DB table - Add gateway_ip column to net table at DB - Save and retrive gw ip during net creation and vm launching process Change-Id: I93c5339aa61ded3631d34a90018bd67525b49ab1 Signed-off-by: mirabal --- diff --git a/database_utils/migrate_vim_db.sh b/database_utils/migrate_vim_db.sh index 362edd3..b856db9 100755 --- a/database_utils/migrate_vim_db.sh +++ b/database_utils/migrate_vim_db.sh @@ -178,6 +178,7 @@ DATABASE_TARGET_VER_NUM=0 [ $OPENVIM_VER_NUM -ge 4010 ] && DATABASE_TARGET_VER_NUM=8 #0.4.10 => 8 [ $OPENVIM_VER_NUM -ge 5001 ] && DATABASE_TARGET_VER_NUM=9 #0.5.1 => 9 [ $OPENVIM_VER_NUM -ge 5002 ] && DATABASE_TARGET_VER_NUM=10 #0.5.2 => 10 +[ $OPENVIM_VER_NUM -ge 5004 ] && DATABASE_TARGET_VER_NUM=11 #0.5.4 => 11 #TODO ... put next versions here @@ -481,6 +482,19 @@ function downgrade_from_10(){ echo "ALTER TABLE ports CHANGE COLUMN type type ENUM('instance:bridge','instance:data','external') NOT NULL DEFAULT 'instance:bridge' AFTER status;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 echo "DELETE FROM schema_version WHERE version_int = '10';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 } + +function upgrade_to_11(){ + echo " upgrade database from version 0.10 to version 0.11" + echo " Add gateway_ip colum to 'nets'" + echo "ALTER TABLE nets ADD COLUMN gateway_ip VARCHAR(64) NULL DEFAULT NULL AFTER dhcp_last_ip;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "INSERT INTO schema_version (version_int, version, openvim_ver, comments, date) VALUES (11, '0.11', '0.5.4', 'Add gateway_ip colum to nets', '2017-02-13');"| $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} +function downgrade_from_11(){ + echo " downgrade database from version 0.11 to version 0.10" + echo " Delete gateway_ip colum from 'nets'" + echo "ALTER TABLE nets DROP COLUMN gateway_ip;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 + echo "DELETE FROM schema_version WHERE version_int = '11';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1 +} #TODO ... put funtions here diff --git a/host_thread.py b/host_thread.py index e971ff2..97c57ba 100644 --- a/host_thread.py +++ b/host_thread.py @@ -1027,7 +1027,7 @@ class host_thread(threading.Thread): else: return False - def launch_dhcp_server(self, vlan, ip_range, netmask, dhcp_path): + def launch_dhcp_server(self, vlan, ip_range, netmask, dhcp_path, gateway): """ Generate a linux bridge and attache the port to a OVS bridge :param self: @@ -1035,6 +1035,7 @@ class host_thread(threading.Thread): :param ip_range: IP dhcp range :param netmask: network netmask :param dhcp_path: dhcp conf file path that live in namespace side + :param gateway: Gateway address for dhcp net :return: True if success """ @@ -1069,7 +1070,8 @@ class host_thread(threading.Thread): if not content: command = 'sudo ip netns exec ' + net_namespace + ' /usr/sbin/dnsmasq --strict-order --except-interface=lo ' \ '--interface=' + interface + ' --bind-interfaces --dhcp-hostsdir=' + dhcp_path + \ - ' --dhcp-range ' + dhcp_range + ' --pid-file=' + pid_file + ' --dhcp-leasefile=' + leases_path + ' --listen-address ' + ip_range[0] + ' --dhcp-range ' + dhcp_range + ' --pid-file=' + pid_file + ' --dhcp-leasefile=' + leases_path + \ + ' --listen-address ' + gateway print self.name, ': command:', command (_, stdout, _) = self.ssh_conn.exec_command(command) diff --git a/httpserver.py b/httpserver.py index c8d093f..f991bc4 100644 --- a/httpserver.py +++ b/httpserver.py @@ -1626,12 +1626,13 @@ def http_post_server_id(tenant_id): dhcp_firt_ip = str(server_net['network']['dhcp_first_ip']) dhcp_last_ip = str(server_net['network']['dhcp_last_ip']) dhcp_cidr = str(server_net['network']['cidr']) + gateway = str(server_net['network']['gateway']) vm_dhcp_ip = c2[0]["ip_address"] config_dic['host_threads'][server['host_id']].insert_task("create-ovs-bridge-port", vlan) set_mac_dhcp(vm_dhcp_ip, vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, c2[0]['mac']) http_controller = config_dic['http_threads'][threading.current_thread().name] - http_controller.ovim.launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr) + http_controller.ovim.launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr, gateway) #Start server server['uuid'] = new_instance @@ -2070,6 +2071,8 @@ def check_dhcp_data_integrity(network): network["dhcp_first_ip"] = str(ips[2]) if "dhcp_last_ip" not in network: network["dhcp_last_ip"] = str(ips[-2]) + if "gateway_ip" not in network: + network["gateway_ip"] = str(ips[1]) return True else: diff --git a/openvimd.py b/openvimd.py index 3affa56..17a958f 100755 --- a/openvimd.py +++ b/openvimd.py @@ -30,9 +30,9 @@ and host controllers __author__="Alfonso Tierno" __date__ ="$10-jul-2014 12:07:15$" -__version__="0.5.3-r520" +__version__="0.5.4-r521" version_date="Jan 2017" -database_version="0.10" #expected database schema version +database_version="0.11" #expected database schema version import httpserver import auxiliary_functions as af diff --git a/ovim.py b/ovim.py index 0b252ee..286a4d0 100644 --- a/ovim.py +++ b/ovim.py @@ -396,7 +396,7 @@ class ovim(): dhcp_host.ssh_connect() return dhcp_host - def launch_dhcp_server(self, vlan, first_ip, last_ip, cidr): + def launch_dhcp_server(self, vlan, first_ip, last_ip, cidr, gateway): """ Launch a dhcpserver base on dnsmasq attached to the net base on vlan id across the the openvim computes :param vlan: vlan identifier @@ -414,6 +414,6 @@ class ovim(): controller_host = self.get_dhcp_controller() controller_host.create_linux_bridge(vlan) controller_host.create_dhcp_interfaces(vlan, first_ip, dhcp_netmask) - controller_host.launch_dhcp_server(vlan, ip_range, dhcp_netmask, dhcp_path) + controller_host.launch_dhcp_server(vlan, ip_range, dhcp_netmask, dhcp_path, gateway)