X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fovim.py;h=852196499d1e6177f2a891343bd4e315549af889;hb=50557c2e90ad65d8d9459063bd83d5e0b2e02f37;hp=2fca38fe83a193f475418afa1cb27991226f8373;hpb=6878e3f50618cf9a6dfe8d365951cb8bc9a98a6a;p=osm%2Fopenvim.git diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index 2fca38f..8521964 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -43,9 +43,9 @@ import openflow_conn __author__ = "Alfonso Tierno, Leonardo Mirabal" __date__ = "$06-Feb-2017 12:07:15$" -__version__ = "0.5.18-r534" -version_date = "Jun 2017" -database_version = 21 #needed database schema version +__version__ = "0.5.24-r542" +version_date = "Mar 2018" +database_version = 23 #needed database schema version HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -199,8 +199,8 @@ class ovim(): host_develop_bridge_iface = self.config.get('development_bridge', None) # get host list from data base before starting threads - r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid', 'password', 'keyfile'), - FROM='hosts', WHERE={'status': 'ok'}) + r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid', 'hypervisors', 'password', 'keyfile'), + FROM='hosts', WHERE={'status': 'ok'}) #Unikernels extension if r < 0: raise ovimException("Cannot get hosts from database {}".format(hosts)) @@ -215,6 +215,7 @@ class ovim(): version=self.config['version'], host_id=host['uuid'], develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface, + hypervisors=host['hypervisors'], #Unikernels extension logger_name=self.logger_name + ".host." + host['name'], debug=self.config.get('log_level_host')) @@ -283,25 +284,42 @@ class ovim(): for net in content: net_type = net['type'] - if (net_type == 'bridge_data' or net_type == 'bridge_man') and \ + if net['status'] != "INACTIVE" and (net_type == 'bridge_data' or net_type == 'bridge_man') and \ net["provider"][:4] == 'OVS:' and net["enable_dhcp"] == "true": try: - routes = yaml.safe_load(net.get('routes')) - dns = yaml.safe_load(net.get('dns')) - self.launch_dhcp_server(net.get('vlan'), - net.get('dhcp_first_ip'), - net.get('dhcp_last_ip'), - net.get('cidr'), - net.get('gateway_ip'), - dns, - routes) - self.launch_link_bridge_to_ovs(net['vlan'], net.get('links'), net.get('routes')) + config_routes = net.get('routes') + if config_routes: + routes = yaml.safe_load(config_routes) + else: + routes = None + + config_dns = net.get('dns') + if config_dns: + dns = yaml.safe_load(config_dns) + else: + dns = None + + links = net.get('links') + if links: + links = yaml.safe_load(net.get('links')) + if net.get('enable_dhcp'): + self.launch_dhcp_server(net.get('vlan'), + net.get('dhcp_first_ip'), + net.get('dhcp_last_ip'), + net.get('cidr'), + net.get('gateway_ip'), + dns, + routes) + self.launch_link_bridge_to_ovs(net['vlan'], net.get('gateway_ip'), net.get('cidr'), links, routes) + if net["status"] == "ERROR": + self.db.update_rows("nets", UPDATE={"status": "ACTIVE", "last_error": None}, + WHERE={"uuid": net["uuid"]}) except Exception as e: self.logger.error("Fail at launching dhcp server for net_id='%s' net_name='%s': %s", net["uuid"], net["name"], str(e)) - self.db.update_rows("nets", {"status": "ERROR", + self.db.update_rows("nets", UPDATE={"status": "ERROR", "last_error": "Fail at launching dhcp server: " + str(e)}, - {"uuid": net["uuid"]}) + WHERE={"uuid": net["uuid"]}) def _start_of_db_tasks(self): """ @@ -644,7 +662,7 @@ class ovim(): network['vlan'] = net_vlan network['region'] = net_region dhcp_integrity = True - if 'enable_dhcp' in network and network['enable_dhcp']: + if network.get('enable_dhcp'): dhcp_integrity = self._check_dhcp_data_integrity(network) if network.get('links'): @@ -655,8 +673,7 @@ class ovim(): network['routes'] = yaml.safe_dump(network['routes'], default_flow_style=True, width=256) result, content = self.db.new_row('nets', network, True, True) - - if result >= 0 and dhcp_integrity: + if result >= 0: # and dhcp_integrity: if bridge_net: bridge_net[3] = content if self.config.get("dhcp_server") and self.config['network_type'] == 'bridge': @@ -668,7 +685,8 @@ class ovim(): self.logger.debug("dhcp_server: add new net", content, content) return content else: - raise ovimException("Error posting network", HTTP_Internal_Server_Error) + raise ovimException("Error creating network: {}".format(content), -result) + # TODO kei change update->edit def edit_network(self, network_id, network): @@ -768,6 +786,7 @@ class ovim(): :param network_id: network id :return: """ + net_data = self.show_network(network_id) # delete from the data base result, content = self.db.delete_row('nets', network_id) @@ -781,7 +800,18 @@ class ovim(): break if self.config.get("dhcp_server") and network_id in self.config["dhcp_nets"]: self.config["dhcp_nets"].remove(network_id) - return content + + if net_data.get('enable_dhcp'): + dhcp_path = self.config['ovs_controller_file_path'] + dhcp_controller = self.get_dhcp_controller() + dhcp_controller.delete_dhcp_server(net_data['vlan'], network_id, dhcp_path) + dhcp_controller.delete_dhcp_port(net_data['vlan'], network_id, dhcp_path) + links = yaml.load(net_data.get('links')) + if links: + links = yaml.load(net_data.get('links')) + self.delete_link_bridge_to_ovs(net_data['vlan'], links) + + return content else: raise ovimException("Error deleting network '{}': {}".format(network_id, content), -result) @@ -1333,6 +1363,8 @@ class ovim(): map['switch_dpid'] = switch_dpid if region: map['region'] = region + if map.get("pci"): + map["pci"] = map["pci"].lower() for of_map in of_maps: result, uuid = self.db.new_row('of_port_mappings', of_map, True) @@ -1422,7 +1454,7 @@ class ovim(): dhcp_path = self.config['ovs_controller_file_path'] controller_host = self.get_dhcp_controller() - # TODO leo check if is need ti to create an ovim-vlan bridge, looks like not + # controller_host.create_linux_bridge(vlan) controller_host.create_dhcp_interfaces(vlan, first_ip, dhcp_netmask) dhcp_path = self.config['ovs_controller_file_path']