标签:驱动 ensure fail dash comm begin 理念 实现 服务启动
@utils.transaction_guard @db_api.retry_if_session_inactive() def create_network(self, context, network): result, mech_context = self._create_network_db(context, network) kwargs = {‘context‘: context, ‘network‘: result} registry.notify(resources.NETWORK, events.AFTER_CREATE, self, **kwargs) try: self.mechanism_manager.create_network_postcommit(mech_context) except ml2_exc.MechanismDriverError: with excutils.save_and_reraise_exception(): LOG.error(_LE("mechanism_manager.create_network_postcommit " "failed, deleting network ‘%s‘"), result[‘id‘]) self.delete_network(context, result[‘id‘]) return result
def _create_network_db(self, context, network): net_data = network[attributes.NETWORK] tenant_id = net_data[‘tenant_id‘] session = context.session with session.begin(subtransactions=True): self._ensure_default_security_group(context, tenant_id) net_db = self.create_network_db(context, network) result = self._make_network_dict(net_db, process_extensions=False, context=context) self.extension_manager.process_create_network(context, net_data, result) self._process_l3_create(context, result, net_data) net_data[‘id‘] = result[‘id‘] self.type_manager.create_network_segments(context, net_data, tenant_id) self.type_manager.extend_network_dict_provider(context, result) # Update the transparent vlan if configured if utils.is_extension_supported(self, ‘vlan-transparent‘): vlt = vlantransparent.get_vlan_transparent(net_data) net_db[‘vlan_transparent‘] = vlt result[‘vlan_transparent‘] = vlt mech_context = driver_context.NetworkContext(self, context, result) self.mechanism_manager.create_network_precommit(mech_context) result[api.MTU] = self._get_network_mtu(result) ... self._apply_dict_extend_functions(‘networks‘, result, net_db) return result, mech_context
在服务启动的时候会从配置文件读取出来,并存到数据库中,查看一下ml2_vlan_allocations表,得到如下结果。
def _allocate_segment(self, session, network_type): driver = self.drivers.get(network_type) return driver.obj.allocate_tenant_segment(session)
def _call_on_drivers(self, method_name, context, continue_on_failure=False, raise_db_retriable=False): """Helper method for calling a method across all mechanism drivers. """ errors = [] for driver in self.ordered_mech_drivers: try: getattr(driver.obj, method_name)(context) except Exception as e: if raise_db_retriable and db_api.is_retriable(e): with excutils.save_and_reraise_exception(): LOG.debug("DB exception raised by Mechanism driver " "‘%(name)s‘ in %(method)s", {‘name‘: driver.name, ‘method‘: method_name}, exc_info=e) LOG.exception( _LE("Mechanism driver ‘%(name)s‘ failed in %(method)s"), {‘name‘: driver.name, ‘method‘: method_name} ) errors.append(e) if not continue_on_failure: break if errors: raise ml2_exc.MechanismDriverError( method=method_name, errors=errors )
标签:驱动 ensure fail dash comm begin 理念 实现 服务启动
原文地址:https://www.cnblogs.com/zhouqi0505/p/10526340.html