X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fovim.py;h=fe2748ff5b4c903032c0dbecc59376ef20dd17fb;hb=55195779db090c1e753a4fa4357b5152d455e9fe;hp=6317421d9d865d3872c0ae91b02a53bb1b429224;hpb=e16a636320bb40ae49227b4145fa10835aa878f1;p=osm%2Fopenvim.git diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index 6317421..fe2748f 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -283,7 +283,7 @@ 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: config_routes = net.get('routes') @@ -301,20 +301,24 @@ class ovim(): links = net.get('links') if links: links = yaml.safe_load(net.get('links')) - 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) + 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): """ @@ -668,11 +672,10 @@ 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 bridge_net: bridge_net[3] = content - if self.config.get("dhcp_server") and self.config['network_type'] == 'bridge': + if self.config.get("dhcp_server") and self.config['network_type'] == 'bridge': # \ if network["name"] in self.config["dhcp_server"].get("nets", ()): self.config["dhcp_nets"].append(content) self.logger.debug("dhcp_server: add new net", content) @@ -781,6 +784,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) @@ -794,7 +798,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)