X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fovim.py;h=0ad5258cfd83ce0d0bb103bb226e9ca336b9f5a1;hb=refs%2Ftags%2Fv6.0.3;hp=213676a11e676106be7f398550f962b7496d9b5e;hpb=bd7d70e31f58e207c4228ebac47d659e487632cf;p=osm%2Fopenvim.git diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index 213676a..0ad5258 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- ## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. # This file is part of openvim # All Rights Reserved. # @@ -43,8 +43,8 @@ import openflow_conn __author__ = "Alfonso Tierno, Leonardo Mirabal" __date__ = "$06-Feb-2017 12:07:15$" -__version__ = "0.5.27-r547" -version_date = "Jul 2018" +__version__ = "0.5.29-r549" +version_date = "Sep 2018" database_version = 23 #needed database schema version HTTP_Bad_Request = 400 @@ -189,7 +189,6 @@ class ovim(): self.get_version(), self.get_version_date(), self.get_database_version())) # create database connection for openflow threads self.config["db"] = self._create_database_connection() - self.config["db_lock"] = threading.Lock() self.of_test_mode = False if self.config['mode'] == 'normal' or self.config['mode'] == "OF only" else True @@ -210,7 +209,7 @@ class ovim(): thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], password=host['password'], keyfile=host.get('keyfile', self.config["host_ssh_keyfile"]), - db_lock=self.config["db_lock"], test=host_test_mode, + test=host_test_mode, image_path=self.config['host_image_path'], version=self.config['version'], host_id=host['uuid'], develop_mode=host_develop_mode, @@ -268,7 +267,7 @@ class ovim(): dhcp_params = self.config.get("dhcp_server") if dhcp_params: thread = dt.dhcp_thread(dhcp_params=dhcp_params, test=host_test_mode, dhcp_nets=self.config["dhcp_nets"], - db=self.config["db"], db_lock=self.config["db_lock"], + db=self.config["db"], logger_name=self.logger_name + ".dhcp", debug=self.config.get('log_level_of')) thread.start() @@ -325,7 +324,6 @@ class ovim(): """ Start ofc task for existing ofcs in database :param db_of: - :param db_lock: :return: """ ofcs = self.get_of_controllers() @@ -453,7 +451,6 @@ class ovim(): ofc_net_same_vlan = False thread = oft.openflow_thread(ofc_uuid, of_conn, of_test=self.of_test_mode, db=self.config["db"], - db_lock=self.config["db_lock"], pmp_with_same_vlan=ofc_net_same_vlan, logger_name=self.logger_name + ".ofc." + ofc_uuid, debug=self.config.get('log_level_of')) @@ -501,7 +498,7 @@ class ovim(): return content - def show_network(self, network_id, db_filter={}): + def show_network(self, network_id, db_filter={}, skip_on_not_found=False): """ Get network from DB by id :param network_id: net Id @@ -518,7 +515,9 @@ class ovim(): if result < 0: raise ovimException(str(content), -result) elif result == 0: - raise ovimException("show_network network '%s' not found" % network_id, -result) + if skip_on_not_found: + return + raise ovimException("show_network network '%s' not found" % network_id, HTTP_Not_Found) else: convert_boolean(content, ('shared', 'admin_state_up', 'enable_dhcp')) # get ports from DB @@ -544,7 +543,7 @@ class ovim(): if tenant_id: result, _ = self.db.get_table(FROM='tenants', SELECT=('uuid',), WHERE={'uuid': tenant_id, "enabled": True}) if result <= 0: - raise ovimException("set_network error, no tenant founded", -result) + raise ovimException("set_network error, no tenant found", -result) bridge_net = None # check valid params @@ -784,13 +783,15 @@ class ovim(): else: raise ovimException(content, -result) - def delete_network(self, network_id): + def delete_network(self, network_id, idempotent=True): """ Delete network by network id :param network_id: network id :return: """ - net_data = self.show_network(network_id) + net_data = self.show_network(network_id, skip_on_not_found=idempotent) + if not net_data: # network does not exist + return # delete from the data base result, content = self.db.delete_row('nets', network_id) @@ -983,7 +984,7 @@ class ovim(): port_mapping_data = self.get_of_port_mappings(columns, db_filter) if not len(port_mapping_data): - raise ovimException("No port mapping founded for '{}'".format(str(db_filter)), + raise ovimException("No port mapping found for '{}'".format(str(db_filter)), HTTP_Not_Found) elif len(port_mapping_data) > 1: raise ovimException("Wrong port data was given, please check pci, region & compute id data", @@ -1061,7 +1062,7 @@ class ovim(): self.logger.error(message) raise ovimException(message, HTTP_Internal_Server_Error) - def delete_port(self, port_id): + def delete_port(self, port_id, idempotent=False): # Look for the previous port data result, ports = self.db.get_table(WHERE={'uuid': port_id, "type": "external"}, FROM='ports') if result < 0: @@ -1069,6 +1070,8 @@ class ovim(): # delete from the data base result, content = self.db.delete_row('ports', port_id) if result == 0: + if idempotent: + return raise ovimException("External port '{}' not found".format(port_id), http_code=HTTP_Not_Found) elif result < 0: raise ovimException("Cannot delete port from database: {}".format(content), http_code=-result) @@ -1430,7 +1433,7 @@ class ovim(): dhcp_host = ht.host_thread(name='openvim_controller', user=ovs_controller_user, host=controller_ip, password=self.config.get('ovs_controller_password'), keyfile=self.config.get('ovs_controller_keyfile'), - db=self.config["db"], db_lock=self.config["db_lock"], test=host_test_mode, + db=self.config["db"], test=host_test_mode, image_path=self.config['host_image_path'], version=self.config['version'], host_id='openvim_controller', develop_mode=host_develop_mode, develop_bridge_iface=bridge_ifaces,