return
-def get_dhcp_controller():
- """
- Create an host_thread object for manage openvim controller and not create a thread for itself
- :return: dhcp_host openvim controller object
- """
-
- if 'openvim_controller' in config_dic['host_threads']:
- return config_dic['host_threads']['openvim_controller']
-
- bridge_ifaces = []
- controller_ip = config_dic['ovs_controller_ip']
- ovs_controller_user = config_dic['ovs_controller_user']
-
- host_test_mode = True if config_dic['mode'] == 'test' or config_dic['mode'] == "OF only" else False
- host_develop_mode = True if config_dic['mode'] == 'development' else False
-
- dhcp_host = ht.host_thread(name='openvim_controller', user=ovs_controller_user, host=controller_ip, db=config_dic['db'],
- db_lock=config_dic['db_lock'], test=host_test_mode,
- image_path=config_dic['image_path'], version=config_dic['version'],
- host_id='openvim_controller', develop_mode=host_develop_mode,
- develop_bridge_iface=bridge_ifaces)
-
- config_dic['host_threads']['openvim_controller'] = dhcp_host
- if not host_test_mode:
- dhcp_host.ssh_connect()
- return dhcp_host
-
-
def delete_dhcp_ovs_bridge(vlan, net_uuid):
"""
Delete bridges and port created during dhcp launching at openvim controller
"""
dhcp_path = config_dic['ovs_controller_file_path']
- controller_host = get_dhcp_controller()
- controller_host.delete_dhcp_port(vlan, net_uuid)
- controller_host.delete_dhcp_server(vlan, net_uuid, dhcp_path)
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_controller = http_controller.ovim.get_dhcp_controller()
+
+ dhcp_controller.delete_dhcp_port(vlan, net_uuid)
+ dhcp_controller.delete_dhcp_server(vlan, net_uuid, dhcp_path)
def create_dhcp_ovs_bridge():
Initialize bridge to allocate the dhcp server at openvim controller
:return:
"""
- controller_host = get_dhcp_controller()
- controller_host.create_ovs_bridge()
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_controller = http_controller.ovim.get_dhcp_controller()
+
+ dhcp_controller.create_ovs_bridge()
def set_mac_dhcp(vm_ip, vlan, first_ip, last_ip, cidr, mac):
if not len(all_matching_cidrs(vm_ip, new_cidr)):
vm_ip = None
- controller_host = get_dhcp_controller()
- controller_host.set_mac_dhcp_server(vm_ip, mac, vlan, dhcp_netmask, dhcp_path)
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_controller = http_controller.ovim.get_dhcp_controller()
+
+ dhcp_controller.set_mac_dhcp_server(vm_ip, mac, vlan, dhcp_netmask, dhcp_path)
def delete_mac_dhcp(vm_ip, vlan, mac):
dhcp_path = config_dic['ovs_controller_file_path']
- controller_host = get_dhcp_controller()
- controller_host.delete_mac_dhcp_server(vm_ip, mac, vlan, dhcp_path)
-
-
-def launch_dhcp_server(vlan, first_ip, last_ip, cidr):
- """
- Launch a dhcpserver base on dnsmasq attached to the net base on vlan id across the the openvim computes
- :param vlan: vlan identifier
- :param first_ip: First dhcp range ip
- :param last_ip: Last dhcp range ip
- :param cidr: net cidr
- :return:
- """
- ip_tools = IPNetwork(cidr)
- dhcp_netmask = str(ip_tools.netmask)
- ip_range = [first_ip, last_ip]
- dhcp_path = config_dic['ovs_controller_file_path']
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_controller = http_controller.ovim.get_dhcp_controller()
- controller_host = 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)
+ dhcp_controller.delete_mac_dhcp_server(vm_ip, mac, vlan, dhcp_path)
def create_vxlan_mesh(host_id):
if len(existing_hosts['hosts']) > 0:
# vlxan mesh creation between openvim controller and computes
computes_available = existing_hosts['hosts']
- controller_host = get_dhcp_controller()
+
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_controller = http_controller.ovim.get_dhcp_controller()
+
for compute in computes_available:
vxlan_interface_name = get_vxlan_interface(compute['id'][:8])
- config_dic['host_threads'][compute['id']].insert_task("new-vxlan", dhcp_compute_name, controller_host.host)
- controller_host.create_ovs_vxlan_tunnel(vxlan_interface_name, compute['ip_name'])
+ config_dic['host_threads'][compute['id']].insert_task("new-vxlan", dhcp_compute_name, dhcp_controller.host)
+ dhcp_controller.create_ovs_vxlan_tunnel(vxlan_interface_name, compute['ip_name'])
# vlxan mesh creation between openvim computes
for count, compute_owner in enumerate(computes_available):
pass
else:
vxlan_interface_name = get_vxlan_interface(compute_owner['id'][:8])
- controller_host.create_ovs_vxlan_tunnel(vxlan_interface_name, compute_owner['ip_name'])
+ dhcp_controller.create_ovs_vxlan_tunnel(vxlan_interface_name, compute_owner['ip_name'])
config_dic['host_threads'][compute['id']].insert_task("new-vxlan",
vxlan_interface_name,
compute_owner['ip_name'])
computes_available = existing_hosts['hosts']
#
vxlan_interface_name = get_vxlan_interface(host_id[:8])
- controller_host = get_dhcp_controller()
- controller_host.delete_ovs_vxlan_tunnel(vxlan_interface_name)
+
+ http_controller = config_dic['http_threads'][threading.current_thread().name]
+ dhcp_host = http_controller.ovim.get_dhcp_controller()
+
+ dhcp_host.delete_ovs_vxlan_tunnel(vxlan_interface_name)
# remove bridge from openvim controller if no more computes exist
if len(existing_hosts):
- controller_host.delete_ovs_bridge()
+ dhcp_host.delete_ovs_bridge()
# Remove vxlan mesh
for compute in computes_available:
if host_id == compute['id']:
pass
else:
- controller_host.delete_ovs_vxlan_tunnel(vxlan_interface_name)
+ dhcp_host.delete_ovs_vxlan_tunnel(vxlan_interface_name)
config_dic['host_threads'][compute['id']].insert_task("del-vxlan", vxlan_interface_name)
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'])
- launch_dhcp_server(vlan, dhcp_firt_ip, dhcp_last_ip, dhcp_cidr)
+ 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)
#Start server
server['uuid'] = new_instance
network['provider'] = net_provider
network['type'] = net_type
network['vlan'] = net_vlan
-
+ dhcp_integrity = True
if 'enable_dhcp' in network and network['enable_dhcp']:
- check_dhcp_data_integrity(network)
+ dhcp_integrity = check_dhcp_data_integrity(network)
result, content = my.db.new_row('nets', network, True, True)
- if result >= 0:
+ if result >= 0 and dhcp_integrity:
if bridge_net!=None:
bridge_net[3] = content
if config_dic.get("dhcp_server") and config_dic['network_type'] == 'bridge':
if "cidr" in network:
cidr = network["cidr"]
+ ip_tools = IPNetwork(cidr)
+ cidr_len = ip_tools.prefixlen
+ if cidr_len > 29:
+ return False
ips = IPNetwork(cidr)
if "dhcp_first_ip" not in network:
if "dhcp_last_ip" not in network:
network["dhcp_last_ip"] = str(ips[-2])
+ return True
+ else:
+ return False
+
@bottle.route(url_base + '/networks/<network_id>', method='PUT')
def http_put_network_id(network_id):
import host_thread as ht
import dhcp_thread as dt
import openflow_thread as oft
+from netaddr import IPNetwork, IPAddress, all_matching_cidrs
HTTP_Bad_Request = 400
HTTP_Unauthorized = 401
self.db = None
self.db = self._create_database_connection()
+
def _create_database_connection(self):
db = vim_db.vim_db((self.config["network_vlan_range_start"], self.config["network_vlan_range_end"]),
self.config['log_level_db']);
thread.start()
self.config['host_threads'][host['uuid']] = thread
+ # create ovs dhcp thread
+ result, content = self.db.get_table(FROM='nets')
+ if result < 0:
+ self.logger.error("http_get_ports Error %d %s", result, content)
+ raise ovimException(str(content), -result)
+
+ for net in content:
+ net_type = net['type']
+ if net_type == 'bridge_data' or net_type == 'bridge_man' and net["provider"][:4]=="OVS:" and net["enable_dhcp"] == "true":
+ if net['enable_dhcp'] == 'true':
+ self.launch_dhcp_server(net['vlan'], net['dhcp_first_ip'], net['dhcp_last_ip'], net['cidr'])
+
def stop_service(self):
threads = self.config.get('host_threads', {})
if 'of_thread' in self.config:
return port_id
else:
raise ovimException("Error {}".format(content), http_code=-result)
+
+ def get_dhcp_controller(self):
+ """
+ Create an host_thread object for manage openvim controller and not create a thread for itself
+ :return: dhcp_host openvim controller object
+ """
+
+ if 'openvim_controller' in self.config['host_threads']:
+ return self.config['host_threads']['openvim_controller']
+
+ bridge_ifaces = []
+ controller_ip = self.config['ovs_controller_ip']
+ ovs_controller_user = self.config['ovs_controller_user']
+
+ host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False
+ host_develop_mode = True if self.config['mode'] == 'development' else False
+
+ dhcp_host = ht.host_thread(name='openvim_controller', user=ovs_controller_user, host=controller_ip,
+ db=self.config['db'],
+ db_lock=self.config['db_lock'], test=host_test_mode,
+ image_path=self.config['image_path'], version=self.config['version'],
+ host_id='openvim_controller', develop_mode=host_develop_mode,
+ develop_bridge_iface=bridge_ifaces)
+
+ self.config['host_threads']['openvim_controller'] = dhcp_host
+ if not host_test_mode:
+ dhcp_host.ssh_connect()
+ return dhcp_host
+
+ def launch_dhcp_server(self, vlan, first_ip, last_ip, cidr):
+ """
+ Launch a dhcpserver base on dnsmasq attached to the net base on vlan id across the the openvim computes
+ :param vlan: vlan identifier
+ :param first_ip: First dhcp range ip
+ :param last_ip: Last dhcp range ip
+ :param cidr: net cidr
+ :return:
+ """
+ ip_tools = IPNetwork(cidr)
+ dhcp_netmask = str(ip_tools.netmask)
+ ip_range = [first_ip, last_ip]
+
+ dhcp_path = self.config['ovs_controller_file_path']
+
+ 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)
+
+