def create_network_postcommit(self, mech_context): """Create VLAN on the switch. :param:mech_context: Details about the network to be created :raise: Exception """ LOG.debug("create_network_postcommit: called") network = mech_context.current network_id = network['id'] tenant_id = network['tenant_id'] segments = mech_context.network_segments network_type = segments[0]['network_type'] vlan_id = segments[0]['segmentation_id'] physical_network = segments[0]['physical_network'] if physical_network not in self._physical_networks: LOG.info(_LI("BrocadeFiNiMechanism: Ignoring request to create " "network. Network cannot be created in the " "configured physical network %(physnet)s"), {'physnet': physical_network}) return if network_type != 'vlan': LOG.info(_LI("BrocadeFiNiMechanism: Ignoring request to create " "network for network type %(nw_type)s. Only type " "vlan is supported"), {'nw_type': network_type}) return try: devices = self._physical_networks.get(physical_network) for device in devices: device_info = self._devices.get(device) address = device_info.get('address') driver = None try: driver = self._get_driver(device) except Exception as e: LOG.exception(_LE("BrocadeFiNiMechanism: create_network" "_postcommit failed while configuring " "device %(host)s exception=%(error)s"), {'host': address, 'error': e.args}) raise ml2_exc.MechanismDriverError(method='create_network_' 'postcommit') # Proceed only if the driver is not None if driver is not None: driver.create_network( vlan_id, device_info.get("ports").split(",")) except Exception as e: LOG.exception( _LE("Brocade FI/NI driver: create_network_postcommit failed" "Error = %(error)s"), {'error': e.args}) raise ml2_exc.MechanismDriverError(method='create_network_postcomm' 'it') LOG.info(_LI("BrocadeFiNiMechanism:created_network_postcommit: " "%(network_id)s of network type = %(network_type)s with " "vlan = %(vlan_id)s for tenant %(tenant_id)s"), {'network_id': network_id, 'network_type': network_type, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def _delete_nos_port(self, context, port, segment): hostname, vlan_id, physical_network =\ self._get_port_info(port, segment) if not hostname or not vlan_id: LOG.info(_LI("hostname or vlan id is empty")) return for (speed, name) in self._device_dict[(hostname, physical_network)]: try: if brocade_db.is_last_vm_on_host(context, hostname, physical_network, vlan_id)\ and not self._is_dhcp_port(port): address, user, password = self._get_switch_address(hostname) self._driver.deconfigure_trunk_vlan_on_interface( address, user, password, vlan_id, name, speed) else: LOG.info(_LI("more vm exist for network on host hence vlan" " is not removed from port")) except Exception: LOG.exception( _LE("Brocade NOS driver: failed to remove vlan from port")) raise Exception( _("Brocade switch exception: delete_port_postcommit" "failed"))
def _update_ips_for_port(self, context, port): LOG.info(_LI("_update_ips_for_port called()")) port['fixed_ips'] is not attributes.ATTR_NOT_SPECIFIED filter = {'network_id': [port['network_id']]} subnets = self._core_plugin.get_subnets(context, filters=filter) result = self._core_plugin.ipam._generate_ip(context, subnets) LOG.info(_LI("_update_ips_for_port generated ip %s"), result) allocated = models_v2.IPAllocation(network_id=port['network_id'], port_id=port['id'], ip_address=result['ip_address'], subnet_id=result['subnet_id']) context.session.add(allocated) return result
def bind_port(self, context): port = context.current vnic_type = port['binding:vnic_type'] LOG.debug("Brcd:Attempting to bind port %(port)s with vnic_type " "%(vnic_type)s on network %(network)s", {'port': port['id'], 'vnic_type': vnic_type, 'network': context.network.current['id']}) if baremetal_util.is_baremetal_deploy(port): segments = context.segments_to_bind LOG.info(_LI("Segments:%s"), segments) params = baremetal_util.validate_physical_net_params(context) try: # TODO(rmadapur): Handle local_link_info portgroups for i in params["local_link_information"]: speed, name = i['port_id'] vlan_id = segments[0][api.SEGMENTATION_ID] self._driver.configure_native_vlan_on_interface( speed, name, vlan_id) except Exception: LOG.exception(_LE("Brocade NOS driver:failed to trunk" " bare metal vlan")) raise Exception(_("Brocade switch exception:" " bind_port failed for baremetal")) context.set_binding(segments[0][api.ID], portbindings.VIF_TYPE_OTHER, {}, status=n_const.PORT_STATUS_ACTIVE)
def _create_nos_port(self, context, port, segment): hostname, vlan_id, physical_network = self._get_port_info( port, segment) if not hostname or not vlan_id: LOG.info(_LI("hostname or vlan id is empty")) return for (speed, name) in self._device_dict[(hostname, physical_network)]: LOG.debug("_create_nos_port:port %s %s vlan %s", speed, name, str(vlan_id)) try: if not brocade_db.is_vm_exists_on_host(context, hostname, physical_network, vlan_id): address, user, password = self._get_switch_address(hostname) self._driver.configure_trunk_vlan_on_interface( address, user, password, vlan_id, name, speed) else: LOG.debug("_create_nos_port:port is already trunked") except Exception: self._delete_brocade_port(context, port) LOG.exception(_LE("Brocade NOS driver:failed to trunk vlan")) raise Exception(_("Brocade switch exception:" " create_port_postcommit failed"))
def get_brocade_l3_config(): register_brocade_l3_config() svi = {'rbridge_ids': cfg.CONF.svi.rbridge_ids, 'redundancy': True if ((cfg.CONF.svi.redundancy == 'enabled') and (len(cfg.CONF.svi.rbridge_ids) > 1)) else False, 'vrrp_version': cfg.CONF.svi.vrrp_version, 'vrrp_group_id': cfg.CONF.svi.vrrp_group_id, 'vrrp_advertisement_interval': cfg.CONF.svi.vrrp_advertisement_interval, 'is_vrf_required': cfg.CONF.svi.is_vrf_required } if not svi['redundancy'] and len(svi['rbridge_ids']) > 1: # redundancy disabled consider only first rbride configured del svi['rbridge_ids'][1:] LOG.info(_LI("rbridge_ids %(rbridge_ids)s" " redundancy %(redundancy)s" " vrrp_version %(vrrp_version)s" " vrrp_group_id %(vrrp_group_id)s") % {'rbridge_ids': svi['rbridge_ids'], 'redundancy': svi['redundancy'], 'vrrp_version': svi['vrrp_version'], 'vrrp_group_id': svi['vrrp_group_id']}) return svi
def delete_network_precommit(self, mech_context): """Delete Network from the plugin specific database table.""" LOG.debug("delete_network_precommit: called") network = mech_context.current network_id = network['id'] vlan_id = network['provider:segmentation_id'] tenant_id = network['tenant_id'] context = mech_context._plugin_context try: brocade_db.delete_network(context, network_id) except Exception: LOG.exception( _LE("Brocade Mechanism: failed to delete network in db")) raise Exception( _("Brocade Mechanism: delete_network_precommit failed")) LOG.info( _LI("delete network (precommit): %(network_id)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), { 'network_id': network_id, 'vlan_id': vlan_id, 'tenant_id': tenant_id })
def delete_network_postcommit(self, mech_context): """Delete network. This translates to removng portprofile from the switch. """ LOG.debug("delete_network_postcommit: called") network = mech_context.current network_id = network['id'] vlan_id = network['provider:segmentation_id'] tenant_id = network['tenant_id'] try: self._driver.delete_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id) except Exception: LOG.exception(_LE("Brocade NOS driver: failed to delete network")) raise Exception( _("Brocade switch exception, " "delete_network_postcommit failed")) LOG.info( _LI("delete network (postcommit): %(network_id)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), { 'network_id': network_id, 'vlan_id': vlan_id, 'tenant_id': tenant_id })
def delete_network_postcommit(self, mech_context): """Delete network. This translates to removng portprofile from the switch. """ LOG.debug("delete_network_postcommit: called") network = mech_context.current network_id = network['id'] vlan_id = network['provider:segmentation_id'] tenant_id = network['tenant_id'] try: self._driver.delete_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id) except Exception: LOG.exception(_LE("Brocade NOS driver: failed to delete network")) raise Exception( _("Brocade switch exception, " "delete_network_postcommit failed")) LOG.info(_LI("delete network (postcommit): %(network_id)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), {'network_id': network_id, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def delete_network_precommit(self, mech_context): """Delete Network from the plugin specific database table.""" LOG.debug("delete_network_precommit: called") network = mech_context.current network_id = network['id'] vlan_id = network['provider:segmentation_id'] tenant_id = network['tenant_id'] context = mech_context._plugin_context try: brocade_db.delete_network(context, network_id) except Exception: LOG.exception( _LE("Brocade Mechanism: failed to delete network in db")) raise Exception( _("Brocade Mechanism: delete_network_precommit failed")) LOG.info(_LI("delete network (precommit): %(network_id)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), {'network_id': network_id, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def get_driver(self, device): """ Returns the driver based on the firmware. :param:device: A dictionary which has the device details :returns: Appropriate driver for the device based on the firmware version, None otherwise :raises: Exception """ driver = None address = device.get('address') os_type = device.get('ostype') if os_type == FI: driver = importutils.import_object(FI_DRIVER, device) elif os_type == NI: driver = importutils.import_object(NI_DRIVER, device) else: connector = importutils.import_object( CONNECTION_FACTORY).get_connector(device) connector.connect() version = connector.get_version() connector.close_session() if NETIRON in version: LOG.info(_LI("OS Type of the device %(host)s is as NetIron"), {'host': address}) driver = importutils.import_object(NI_DRIVER, device) device.update({'ostype': NI}) elif FASTIRON in version: LOG.info(_LI("OS Type of the device %(host)s is as FastIron"), {'host': device.get('address')}) driver = importutils.import_object(FI_DRIVER, device) device.update({'ostype': FI}) else: LOG.exception( _LE("Brocade Driver Factory: failed to " "identify device type for device=" "%(device)s"), {'device': address}) raise Exception( "Unsupported firmware %(firmware)s for device " "%(host)s", { 'firmware': version, 'host': address }) return driver
def brocade_init(self): """Brocade specific initialization.""" LOG.debug("brocade init brocadeSVIPlugin") self._switch = utils.get_brocade_credentials() self._svi = utils.get_brocade_l3_config() LOG.info(_LI("rbridge id %(rbridge id)s redundancy %(redundancy)s") % {'rbridge id': self._svi['rbridge_ids'], 'redundancy': self._svi['redundancy']}) self._driver = driver.NOSdriver(self._switch['address'], self._switch['username'], self._switch['password']) if self._svi['redundancy']: for rbridge_id in self._svi['rbridge_ids']: LOG.info(_LI("rbridge id %s protocol vrrp enabled"), rbridge_id) self._driver.configure_protocol_vrrp(rbridge_id) self._driver.close_session()
def get_driver(self, device): """ Returns the driver based on the firmware. :param:device: A dictionary which has the device details :returns: Appropriate driver for the device based on the firmware version, None otherwise :raises: Exception """ driver = None address = device.get('address') os_type = device.get('ostype') if os_type == FI: driver = importutils.import_object(FI_DRIVER, device) elif os_type == NI: driver = importutils.import_object(NI_DRIVER, device) else: connector = importutils.import_object(CONNECTION_FACTORY ).get_connector(device) connector.connect() version = connector.get_version() connector.close_session() if NETIRON in version: LOG.info( _LI("OS Type of the device %(host)s is as NetIron"), {'host': address}) driver = importutils.import_object(NI_DRIVER, device) device.update({'ostype': NI}) elif FASTIRON in version: LOG.info( _LI("OS Type of the device %(host)s is as FastIron"), {'host': device.get('address')}) driver = importutils.import_object(FI_DRIVER, device) device.update({'ostype': FI}) else: LOG.exception(_LE("Brocade Driver Factory: failed to " "identify device type for device=" "%(device)s"), {'device': address}) raise Exception("Unsupported firmware %(firmware)s for device " "%(host)s", {'firmware': version, 'host': address}) return driver
def delete_network_postcommit(self, mech_context): """Delete network which translates to removing vlan from the switch. :param:mech_context: Details about the network to be created :raise: MechanismDriverError """ LOG.debug("delete_network_postcommit: called") network = mech_context.current network_id = network['id'] vlan_id = network['provider:segmentation_id'] tenant_id = network['tenant_id'] segments = mech_context.network_segments segment = segments[0] network_type = segment['network_type'] physical_network = segment['physical_network'] if physical_network not in self._physical_networks: LOG.info(_LI("BrocadeFiNiMechanism: Ignoring request to delete " "network. Network cannot be deleted in the " "configured physical network %(physnet)s"), {'physnet': physical_network}) return if network_type != 'vlan': LOG.info(_LI("BrocadeFiNiMechanism: Ignoring request to delete " "network for type %(nw_type)s. Only network type " "vlan is supported"), {'nw_type': network_type}) return try: devices = self._physical_networks.get(physical_network) for device in devices: driver = self._get_driver(device) driver.delete_network(vlan_id) except Exception: LOG.exception( _LE("BrocadeFiNiMechanism: failed to delete network")) raise ml2_exc.MechanismDriverError(method='delete_network_postcomm' 'it') LOG.info(_LI("BrocadeFiNiMechanism: delete network (postcommit): " "%(network_id)s with vlan = %(vlan_id)s for tenant " "%(tenant_id)s"), {'network_id': network_id, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def create_port_postcommit(self, mech_context): """Associate the assigned MAC address to the portprofile.""" LOG.debug("create_port_postcommit: called") if self.is_flat_network(mech_context.network.network_segments[0]): return port = mech_context.current port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] context = mech_context._plugin_context network = brocade_db.get_network(context, network_id) if not network: LOG.info(_LI("network not populated nothing to be done")) return vlan_id = network['vlan'] interface_mac = port['mac_address'] # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx mac = self.mac_reformat_62to34(interface_mac) try: self._driver.associate_mac_to_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id, mac) except Exception: LOG.exception( _LE("Brocade NOS driver: failed to associate mac %s"), interface_mac) raise Exception( _("Brocade switch exception: create_port_postcommit failed")) LOG.info( _LI("created port (postcommit): port_id=%(port_id)s" " network_id=%(network_id)s tenant_id=%(tenant_id)s"), { 'port_id': port_id, 'network_id': network_id, 'tenant_id': tenant_id })
def mocked_brocade_init(self): LOG.debug("brocadeSVIPlugin::mocked_brocade_init()") self._switch = {'address': cfg.CONF.ml2_brocade.address, 'username': cfg.CONF.ml2_brocade.username, 'password': cfg.CONF.ml2_brocade.password, 'rbridge_id': cfg.CONF.ml2_brocade.rbridge_id } LOG.info(_LI("rbridge id %s"), self._switch['rbridge_id']) self._driver = mock.MagicMock()
def _is_l3_agent_running(self, context): l3plugin = manager.NeutronManager.get_service_plugins()[ plugin_constants.L3_ROUTER_NAT] if not l3plugin: LOG.error(_LE('No plugin for L3 routing registered! Will reply ' 'no l3 agents!! ')) return False l3_agents = l3plugin.get_l3_agents(context, True) LOG.info(_LI("List of L3 agents _is_l3_agent_running %s"), l3_agents) return ((l3_agents) and (len(l3_agents) > 0))
def delete_port_postcommit(self, mech_context): """Dissociate MAC address from the portprofile.""" LOG.debug("delete_port_postcommit: called") if self.is_flat_network(mech_context.network.network_segments[0]): return port = mech_context.current port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] context = mech_context._plugin_context network = brocade_db.get_network(context, network_id) if not network: LOG.info(_LI("network not populated nothing to be done")) return vlan_id = network['vlan'] interface_mac = port['mac_address'] # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx mac = self.mac_reformat_62to34(interface_mac) try: self._driver.dissociate_mac_from_network( self._switch['address'], self._switch['username'], self._switch['password'], vlan_id, mac) except Exception: LOG.exception( _LE("Brocade NOS driver: failed to dissociate MAC %s"), interface_mac) raise Exception( _("Brocade switch exception, delete_port_postcommit failed")) LOG.info( _LI("delete port (postcommit): port_id=%(port_id)s" " network_id=%(network_id)s tenant_id=%(tenant_id)s"), {'port_id': port_id, 'network_id': network_id, 'tenant_id': tenant_id})
def _is_l3_agent_running(self, context): l3plugin = manager.NeutronManager.get_service_plugins()[ plugin_constants.L3_ROUTER_NAT] if not l3plugin: LOG.error( _LE('No plugin for L3 routing registered! Will reply ' 'no l3 agents!! ')) return False l3_agents = l3plugin.get_l3_agents(context, True) LOG.info(_LI("List of L3 agents _is_l3_agent_running %s"), l3_agents) return ((l3_agents) and (len(l3_agents) > 0))
def brocade_init(self): """Brocade specific initialization.""" LOG.debug("brocadeSVIPlugin::brocade_init()") self._switch = {'address': cfg.CONF.ml2_brocade.address, 'username': cfg.CONF.ml2_brocade.username, 'password': cfg.CONF.ml2_brocade.password, 'rbridge_id': cfg.CONF.ml2_brocade.rbridge_id } self._driver = driver.NOSdriver() LOG.info(_LI("rbridge id %s"), self._switch['rbridge_id'])
def brocade_init(self): """Brocade specific initialization.""" LOG.debug("brocade init brocadeSVIPlugin") self._switch = utils.get_brocade_credentials() self._svi = utils.get_brocade_l3_config() LOG.info( _LI("rbridge id %(rbridge id)s redundancy %(redundancy)s") % { 'rbridge id': self._svi['rbridge_ids'], 'redundancy': self._svi['redundancy'] }) self._driver = driver.NOSdriver(self._switch['address'], self._switch['username'], self._switch['password']) if self._svi['redundancy']: for rbridge_id in self._svi['rbridge_ids']: LOG.info(_LI("rbridge id %s protocol vrrp enabled"), rbridge_id) self._driver.configure_protocol_vrrp(rbridge_id) self._driver.close_session()
def brocade_init(self): """Brocade specific initialization.""" LOG.debug("brocadeSVIPlugin::brocade_init()") self._switch = { 'address': cfg.CONF.ml2_brocade.address, 'username': cfg.CONF.ml2_brocade.username, 'password': cfg.CONF.ml2_brocade.password, 'rbridge_id': cfg.CONF.ml2_brocade.rbridge_id } self._driver = driver.NOSdriver() LOG.info(_LI("rbridge id %s"), self._switch['rbridge_id'])
def _get_router_info_list_for_tenant(self, routers, tenant_id): """Returns the list of router info objects on which to apply the fw.""" router_info_list = [] for router in routers: # for routers without an interface - _get_routers returns # the router - but this is not yet populated in router_info if router['tenant_id'] != tenant_id: continue LOG.info(_LI("_get_router_info_list_for_tenant router %s"), router) # This is done to Keep fwaas driver code unchanged ri = RouterInfo(router) router_info_list.append(ri) return router_info_list
def _update_firewall(self, context, svi, tenant_id): """update newly added interface with firewall rules""" fw_plugin = manager.NeutronManager.get_service_plugins().get( plugin_constants.FIREWALL, None) if not fw_plugin: LOG.info(_LI('No Firewall plugin registered!!')) return context.tenant_id = tenant_id if hasattr(fw_plugin, 'handle_router_interface_add'): fw_plugin.handle_router_interface_add(context, svi, tenant_id) else: LOG.warning(_LW("Brocade SVI Plugin is used but brocade firewall" " plugin you may want to configure" " brocade firewall plugin"))
def update_router(self, rbridge_id, router_id, added, removed): """update router""" LOG.info(_LI("Inside update_router before sending to switch")) if added is None: LOG.info(_LI("Added is None")) if removed is None: LOG.info(_LI("Removed is None")) if not utils.is_vrf_required(): """ Configure the static route at the rbridge mode""" try: if added is not None: LOG.info(_LI("Adding new route")) for route in added: self.configure_static_route(rbridge_id, route['destination'], route['nexthop']) if removed is not None: LOG.info(_LI("Deleting new route")) for route in removed: self.delete_static_route(rbridge_id, route['destination'], route['nexthop']) except Exception as e: with excutils.save_and_reraise_exception(): LOG.exception( _LE("Failed to create static route %s"), str(e)) else: """ config the static route in for the VRF""" vrf_name = template.OS_VRF_NAME.format(id=router_id) vrf_name = vrf_name[:32] try: if added is not None: LOG.info(_LI("Adding new route with VRF %s"), vrf_name) for route in added: self.configure_vrf_static_route(rbridge_id, vrf_name, route['destination'], route['nexthop']) if removed is not None: LOG.info(_LI("Deleting new route from vrf %s"), vrf_name) for route in removed: self.delete_vrf_static_route(rbridge_id, vrf_name, route['destination'], route['nexthop']) except Exception as e: with excutils.save_and_reraise_exception(): LOG.exception( _LE("Failed to create static route %s"), str(e))
def create_network_precommit(self, mech_context): """Create Network in the mechanism specific database table.""" if self.is_flat_network(mech_context.network_segments[0]): return network = mech_context.current context = mech_context._plugin_context tenant_id = network['tenant_id'] network_id = network['id'] segments = mech_context.network_segments # currently supports only one segment per network segment = segments[0] network_type = segment['network_type'] vlan_id = segment['segmentation_id'] segment_id = segment['id'] if segment['physical_network'] not in self._physical_networks: raise Exception( _("Brocade Mechanism: failed to create network, " "network cannot be created in the configured " "physical network")) if network_type not in [p_const.TYPE_VLAN]: raise Exception( _("Brocade Mechanism: failed to create network, " "only network type vlan is supported")) try: brocade_db.create_network(context, network_id, vlan_id, segment_id, network_type, tenant_id) except Exception: LOG.exception( _LE("Brocade Mechanism: failed to create network in db")) raise Exception( _("Brocade Mechanism: create_network_precommit failed")) LOG.info( _LI("create network (precommit): %(network_id)s " "of network type = %(network_type)s " "with vlan = %(vlan_id)s " "for tenant %(tenant_id)s"), { 'network_id': network_id, 'network_type': network_type, 'vlan_id': vlan_id, 'tenant_id': tenant_id })
def _update_firewall(self, context, svi, tenant_id): """update newly added interface with firewall rules""" fw_plugin = manager.NeutronManager.get_service_plugins().get( plugin_constants.FIREWALL, None) if not fw_plugin: LOG.info(_LI('No Firewall plugin registered!!')) return context.tenant_id = tenant_id if hasattr(fw_plugin, 'handle_router_interface_add'): fw_plugin.handle_router_interface_add(context, svi, tenant_id) else: LOG.warning( _LW("Brocade SVI Plugin is used but brocade firewall" " plugin you may want to configure" " brocade firewall plugin"))
def update_router(self, rbridge_id, router_id, added, removed): """update router""" LOG.info(_LI("Inside update_router before sending to switch")) if added is None: LOG.info(_LI("Added is None")) if removed is None: LOG.info(_LI("Removed is None")) if not utils.is_vrf_required(): """ Configure the static route at the rbridge mode""" try: if added is not None: LOG.info(_LI("Adding new route")) for route in added: self.configure_static_route(rbridge_id, route['destination'], route['nexthop']) if removed is not None: LOG.info(_LI("Deleting new route")) for route in removed: self.delete_static_route(rbridge_id, route['destination'], route['nexthop']) except Exception as e: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Failed to create static route %s"), str(e)) else: """ config the static route in for the VRF""" vrf_name = template.OS_VRF_NAME.format(id=router_id) vrf_name = vrf_name[:32] try: if added is not None: LOG.info(_LI("Adding new route with VRF %s"), vrf_name) for route in added: self.configure_vrf_static_route( rbridge_id, vrf_name, route['destination'], route['nexthop']) if removed is not None: LOG.info(_LI("Deleting new route from vrf %s"), vrf_name) for route in removed: self.delete_vrf_static_route(rbridge_id, vrf_name, route['destination'], route['nexthop']) except Exception as e: with excutils.save_and_reraise_exception(): LOG.exception(_LE("Failed to create static route %s"), str(e))
def create_network_precommit(self, mech_context): """Create Network in the mechanism specific database table.""" if self.is_flat_network(mech_context.network_segments[0]): return network = mech_context.current context = mech_context._plugin_context tenant_id = network['tenant_id'] network_id = network['id'] segments = mech_context.network_segments # currently supports only one segment per network segment = segments[0] network_type = segment['network_type'] vlan_id = segment['segmentation_id'] segment_id = segment['id'] if segment['physical_network'] not in self._physical_networks: raise Exception( _("Brocade Mechanism: failed to create network, " "network cannot be created in the configured " "physical network")) if network_type not in [p_const.TYPE_VLAN]: raise Exception( _("Brocade Mechanism: failed to create network, " "only network type vlan is supported")) try: brocade_db.create_network(context, network_id, vlan_id, segment_id, network_type, tenant_id) except Exception: LOG.exception( _LE("Brocade Mechanism: failed to create network in db")) raise Exception( _("Brocade Mechanism: create_network_precommit failed")) LOG.info(_LI("create network (precommit): %(network_id)s " "of network type = %(network_type)s " "with vlan = %(vlan_id)s " "for tenant %(tenant_id)s"), {'network_id': network_id, 'network_type': network_type, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def create_network_postcommit(self, mech_context): """Create Network as a portprofile on the switch.""" LOG.debug("create_network_postcommit: called") if self.is_flat_network(mech_context.network_segments[0]): return network = mech_context.current # use network_id to get the network attributes # ONLY depend on our db for getting back network attributes # this is so we can replay postcommit from db context = mech_context._plugin_context network_id = network['id'] network = brocade_db.get_network(context, network_id) network_type = network.network_type tenant_id = network['tenant_id'] vlan_id = network['vlan'] try: self._driver.create_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id) except Exception: LOG.exception(_LE("Brocade NOS driver: failed in create network")) brocade_db.delete_network(context, network_id) raise Exception( _("Brocade Mechanism: create_network_postcommmit failed")) LOG.info( _LI("created network (postcommit): %(network_id)s" " of network type = %(network_type)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), { 'network_id': network_id, 'network_type': network_type, 'vlan_id': vlan_id, 'tenant_id': tenant_id })
def create_network_postcommit(self, mech_context): """Create Network as a portprofile on the switch.""" LOG.debug("create_network_postcommit: called") if self.is_flat_network(mech_context.network_segments[0]): return network = mech_context.current # use network_id to get the network attributes # ONLY depend on our db for getting back network attributes # this is so we can replay postcommit from db context = mech_context._plugin_context network_id = network['id'] network = brocade_db.get_network(context, network_id) network_type = network.network_type tenant_id = network['tenant_id'] vlan_id = network['vlan'] try: self._driver.create_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id) except Exception: LOG.exception(_LE("Brocade NOS driver: failed in create network")) brocade_db.delete_network(context, network_id) raise Exception( _("Brocade Mechanism: create_network_postcommmit failed")) LOG.info(_LI("created network (postcommit): %(network_id)s" " of network type = %(network_type)s" " with vlan = %(vlan_id)s" " for tenant %(tenant_id)s"), {'network_id': network_id, 'network_type': network_type, 'vlan_id': vlan_id, 'tenant_id': tenant_id})
def delete_port_postcommit(self, mech_context): """Dissociate MAC address from the portprofile.""" LOG.debug("delete_port_postcommit: called") port = mech_context.current port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] context = mech_context._plugin_context network = brocade_db.get_network(context, network_id) vlan_id = network['vlan'] interface_mac = port['mac_address'] # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx mac = self.mac_reformat_62to34(interface_mac) try: self._driver.dissociate_mac_from_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id, mac) except Exception: LOG.exception( _LE("Brocade NOS driver: failed to dissociate MAC %s"), interface_mac) raise Exception( _("Brocade switch exception, delete_port_postcommit failed")) LOG.info( _LI("delete port (postcommit): port_id=%(port_id)s" " network_id=%(network_id)s tenant_id=%(tenant_id)s"), { 'port_id': port_id, 'network_id': network_id, 'tenant_id': tenant_id })
def create_port_postcommit(self, mech_context): """Associate the assigned MAC address to the portprofile.""" LOG.debug("create_port_postcommit: called") port = mech_context.current port_id = port['id'] network_id = port['network_id'] tenant_id = port['tenant_id'] context = mech_context._plugin_context network = brocade_db.get_network(context, network_id) vlan_id = network['vlan'] interface_mac = port['mac_address'] # convert mac format: xx:xx:xx:xx:xx:xx -> xxxx.xxxx.xxxx mac = self.mac_reformat_62to34(interface_mac) try: self._driver.associate_mac_to_network(self._switch['address'], self._switch['username'], self._switch['password'], vlan_id, mac) except Exception: LOG.exception( _LE("Brocade NOS driver: failed to associate mac %s"), interface_mac) raise Exception( _("Brocade switch exception: create_port_postcommit failed")) LOG.info( _LI("created port (postcommit): port_id=%(port_id)s" " network_id=%(network_id)s tenant_id=%(tenant_id)s"), {'port_id': port_id, 'network_id': network_id, 'tenant_id': tenant_id})
def add_router_interface(self, context, router_id, interface_info): """creates svi on NOS device and assigns ip addres to SVI.""" LOG.debug( "BrocadeSVIPlugin.add_router_interface on VDX: " "router_id=%(router_id)s " "interface_info=%(interface_info)r", { 'router_id': router_id, 'interface_info': interface_info }) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).add_router_interface(context, router_id, interface_info) port = db.get_port(context.session, info["port_id"]) # shutting down neutron port to allow NOS to do Arp/Routing port['admin_state_up'] = False port['port'] = port self._core_plugin.update_port(context, info["port_id"], port) interface_info = info subnet = self._core_plugin._get_subnet(context, interface_info["subnet_id"]) cidr = subnet["cidr"] net_addr, net_len = self.net_addr(cidr) gateway_ip = subnet["gateway_ip"] network_id = subnet['network_id'] bnet = brocade_db.get_network(context, network_id) vlan_id = bnet['vlan'] gateway_ip_cidr = gateway_ip + '/' + str(net_len) LOG.debug( "Allocated cidr %(cidr)s from the pool, " "network_id %(net_id)s " "bnet %(bnet)s " "vlan %(vlan_id)d ", { 'cidr': gateway_ip_cidr, 'net_id': network_id, 'bnet': bnet, 'vlan_id': int(vlan_id) }) port_filters = { 'network_id': [network_id], 'device_owner': [DEVICE_OWNER_ROUTER_INTF] } port_count = self._core_plugin.get_ports_count( context, port_filters) LOG.info( _LI("BrocadeSVIPlugin.add_router_interface ports_count " "%d"), port_count) # port count is checked against 2 since the current port is already # added to db if port_count == 2: # This subnet is already part of some router # (this is not supported in this version of brocade svi plugin) msg = _("BrocadeSVIPlugin: adding redundant router interface " "is not supported") LOG.error(msg) raise Exception(msg) try: switch = self._switch self._driver.create_svi(switch['address'], switch['username'], switch['password'], switch['rbridge_id'], vlan_id, gateway_ip_cidr, str(router_id)) except Exception: LOG.error( _LE("Failed to create Brocade resources to add router " "interface. info=%(info)s, router_id=%(router_id)s"), { "info": info, "router_id": router_id }) with excutils.save_and_reraise_exception(): with context.session.begin(subtransactions=True): self.remove_router_interface(context, router_id, interface_info) return info
def add_remove_router_interface(self, context, router_id, interface_info, is_add): """ Add/Remove router interface on NI device :param:context: Contains the network details :param:router_id: The router ID :param:interface_info: Contains interface details :param:is_add: True for add operation, False for remove operation. :raises: Exception """ operation = None method = None if is_add is True: method = "add_router_interface" operation = "Add" else: method = "remove_router_interface" operation = "Remove" info = getattr(super(BrocadeRouterPlugin, self), method)(context, router_id, interface_info) interface_info = info subnet = self._core_plugin._get_subnet(context.elevated(), interface_info["subnet_id"]) vlan_id, gateway_ip_cidr = self._get_network_info(context, subnet) for device in self._devices: device_info = self._devices.get(device) address = device_info.get('address') driver = self._get_driver(device) LOG.info(_LI("BrocadeRouterPlugin:Before %(op)s l3 " "router to vlan %(vlan_id)s with ip %(gatewayip)s" "on device " "%(host)s"), {'op': operation, 'vlan_id': vlan_id, 'gatewayip': gateway_ip_cidr, 'host': address}) try: if is_add is True: getattr(driver, method)(vlan_id, gateway_ip_cidr) else: getattr(driver, method)(vlan_id) except Exception as e: if is_add: method = "remove_router_interface" info = getattr(super(BrocadeRouterPlugin, self), method)(context, router_id, interface_info) LOG.exception(_LE("BrocadeRouterPlugin: failed to" " %(op)s l3 router interface for " "device= %(device)s exception : " "%(error)s"), {'op': operation, 'device': address, 'error': e.args}) raise Exception( _("BrocadeRouterPlugin: %(op)s router " "interface failed"), {'op': operation}) LOG.info(_LI("BrocadeRouterPlugin:%(op)sed router " "interface in vlan = %(vlan_id)s with ip address" " %(gatewayip)s on device %(host)s " "successful"), {'op': operation, 'vlan_id': vlan_id, 'gatewayip': gateway_ip_cidr, 'host': address}) return info
def _invoke_nos_driver_api(self, func_name, router_id, vlan_id=None, gateway_ip_cidr=None, context=None, port=None, added=None, removed=None): LOG.info(_LI("_invoke_nos_driver_api called()")) self._switch priority = 1 if self._svi['redundancy'] and\ (func_name == 'delete_svi' or func_name == 'create_svi'): vip, net_len = self.net_addr(gateway_ip_cidr) LOG.info(_LI("_invoke_nos_driver_api vip %(vip)s" " net_len %(net_len)s") % {'vip': vip, 'net_len': net_len}) for rbridge_id in self._svi['rbridge_ids']: if func_name == 'create_router' or\ func_name == 'delete_router': self._driver.__getattribute__(func_name)(rbridge_id, str(router_id)) elif func_name == 'create_svi': if self._svi['redundancy']: LOG.info(_LI("calling update_ips_for_port")) res = self._update_ips_for_port(context, port) gateway_ip_cidr = res['ip_address'] + '/' + str(net_len) LOG.info(_LI("after _update_ips_for_port generated" " gate_ip_cidr %s"), gateway_ip_cidr) LOG.info(_LI("invoke create svi")) self._driver.__getattribute__(func_name)(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) if self._svi['redundancy']: vrrp_version = self._svi['vrrp_version'] vrrp_group_id = self._svi['vrrp_group_id'] vrrp_advt_interval =\ self._svi['vrrp_advertisement_interval'] try: self._driver.configure_vrrp_on_svi(rbridge_id, vlan_id, vrrp_group_id, vrrp_version, vip, vrrp_advt_interval, priority) priority += 1 except Exception: self._driver.delete_svi(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) raise "vrrp configuration failed on NOS" elif func_name == 'delete_svi': self._driver.__getattribute__(func_name)(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) elif func_name == 'update_router': self._driver.__getattribute__(func_name)(rbridge_id, str(router_id), added, removed)
def is_flat_network(self, segment): if not segment or segment['network_type'] == p_const.TYPE_FLAT: LOG.info(_LI("Flat network nothing to be done")) return True return False
def add_remove_router_interface(self, context, router_id, interface_info, is_add): """ Add/Remove router interface on NI device :param:context: Contains the network details :param:router_id: The router ID :param:interface_info: Contains interface details :param:is_add: True for add operation, False for remove operation. :raises: Exception """ operation = None method = None if is_add is True: method = "add_router_interface" operation = "Add" else: method = "remove_router_interface" operation = "Remove" info = getattr(super(BrocadeRouterPlugin, self), method)(context, router_id, interface_info) interface_info = info subnet = self._core_plugin._get_subnet(context.elevated(), interface_info["subnet_id"]) vlan_id, gateway_ip_cidr = self._get_network_info(context, subnet) for device in self._devices: device_info = self._devices.get(device) address = device_info.get('address') driver = self._get_driver(device) LOG.info( _LI("BrocadeRouterPlugin:Before %(op)s l3 " "router to vlan %(vlan_id)s with ip %(gatewayip)s" "on device " "%(host)s"), { 'op': operation, 'vlan_id': vlan_id, 'gatewayip': gateway_ip_cidr, 'host': address }) try: if is_add is True: getattr(driver, method)(vlan_id, gateway_ip_cidr) else: getattr(driver, method)(vlan_id) except Exception as e: if is_add: method = "remove_router_interface" info = getattr(super(BrocadeRouterPlugin, self), method)(context, router_id, interface_info) LOG.exception( _LE("BrocadeRouterPlugin: failed to" " %(op)s l3 router interface for " "device= %(device)s exception : " "%(error)s"), { 'op': operation, 'device': address, 'error': e.args }) raise Exception( _("BrocadeRouterPlugin: %(op)s router " "interface failed"), {'op': operation}) LOG.info( _LI("BrocadeRouterPlugin:%(op)sed router " "interface in vlan = %(vlan_id)s with ip address" " %(gatewayip)s on device %(host)s " "successful"), { 'op': operation, 'vlan_id': vlan_id, 'gatewayip': gateway_ip_cidr, 'host': address }) return info
def _invoke_nos_driver_api(self, func_name, router_id, vlan_id=None, gateway_ip_cidr=None, context=None, port=None, added=None, removed=None): LOG.info(_LI("_invoke_nos_driver_api called()")) self._switch priority = 1 if self._svi['redundancy'] and\ (func_name == 'delete_svi' or func_name == 'create_svi'): vip, net_len = self.net_addr(gateway_ip_cidr) LOG.info( _LI("_invoke_nos_driver_api vip %(vip)s" " net_len %(net_len)s") % { 'vip': vip, 'net_len': net_len }) for rbridge_id in self._svi['rbridge_ids']: if func_name == 'create_router' or\ func_name == 'delete_router': self._driver.__getattribute__(func_name)(rbridge_id, str(router_id)) elif func_name == 'create_svi': if self._svi['redundancy']: LOG.info(_LI("calling update_ips_for_port")) res = self._update_ips_for_port(context, port) gateway_ip_cidr = res['ip_address'] + '/' + str(net_len) LOG.info( _LI("after _update_ips_for_port generated" " gate_ip_cidr %s"), gateway_ip_cidr) LOG.info(_LI("invoke create svi")) self._driver.__getattribute__(func_name)(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) if self._svi['redundancy']: vrrp_version = self._svi['vrrp_version'] vrrp_group_id = self._svi['vrrp_group_id'] vrrp_advt_interval =\ self._svi['vrrp_advertisement_interval'] try: self._driver.configure_vrrp_on_svi( rbridge_id, vlan_id, vrrp_group_id, vrrp_version, vip, vrrp_advt_interval, priority) priority += 1 except Exception: self._driver.delete_svi(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) raise "vrrp configuration failed on NOS" elif func_name == 'delete_svi': self._driver.__getattribute__(func_name)(rbridge_id, vlan_id, gateway_ip_cidr, str(router_id)) elif func_name == 'update_router': self._driver.__getattribute__(func_name)(rbridge_id, str(router_id), added, removed)
def add_router_interface(self, context, router_id, interface_info): """creates svi on NOS device and assigns ip addres to SVI""" LOG.debug("BrocadeSVIPlugin.add_router_interface called: " "router_id=%(router_id)s " "interface_info=%(interface_info)r", {'router_id': router_id, 'interface_info': interface_info}) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).add_router_interface( context, router_id, interface_info) try: port = self._core_plugin._get_port(context, info["port_id"]) # shutting down neutron port to allow NOS to do Arp/Routing # Propose to community to allow this to do more gracefully port.update({"admin_state_up": False}) interface_info = info subnet = self._core_plugin._get_subnet(context, interface_info["subnet_id"]) cidr = subnet["cidr"] net_addr, net_len = self.net_addr(cidr) gateway_ip = subnet["gateway_ip"] network_id = subnet['network_id'] tenant_id = subnet['tenant_id'] bnet = brocade_db.get_network(context, network_id) vlan_id = bnet['vlan'] gateway_ip_cidr = gateway_ip + '/' + str(net_len) LOG.debug("Allocated cidr (%s) from the pool, network_id(%s)" "bnet (%s) vlan (%d) ", gateway_ip_cidr, network_id, bnet, int(vlan_id)) port_filters = {'network_id': [network_id], 'device_owner': [DEVICE_OWNER_ROUTER_INTF]} port_count = self._core_plugin.get_ports_count(context, port_filters) LOG.info(_LI("BrocadeSVIPlugin.add_router_interface" " ports_count %d"), port_count) # port count is checked against 2 since the # current port is already added to db if port_count == 2: # This subnet is already part of some router is not # supported # in this version of brocadesvi plugin LOG.error(_LE("BrocadeSVIPlugin:adding redundent router" "interface is not supported")) raise Exception(_("BrocadeSVIPlugin:adding redundent" "router interface is not supported")) # res = self._update_ips_for_port(context, port) # gateway_ip = res['ip_address'] # gateway_ip_cidr = gateway_ip +'/'+str(net_len) brocade_db.create_svi(context, router_id, tenant_id, str(vlan_id), True, gateway_ip, str(net_len)) self._invoke_nos_driver_api("create_svi", router_id, vlan_id, gateway_ip_cidr, context, port) self._update_firewall(context, vlan_id, tenant_id) except Exception: LOG.error(_LE("Failed to create Brocade resources to add router " "interface. info=%(info)s, router_id=%(router_id)s"), {"info": info, "router_id": router_id}) with excutils.save_and_reraise_exception(): self._invoke_nos_driver_api("delete_svi", router_id, vlan_id, gateway_ip_cidr) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).\ remove_router_interface(context, router_id, interface_info) return info
def add_router_interface(self, context, router_id, interface_info): """creates svi on NOS device and assigns ip addres to SVI""" LOG.debug( "BrocadeSVIPlugin.add_router_interface called: " "router_id=%(router_id)s " "interface_info=%(interface_info)r", { 'router_id': router_id, 'interface_info': interface_info }) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).add_router_interface(context, router_id, interface_info) try: port = self._core_plugin._get_port(context, info["port_id"]) # shutting down neutron port to allow NOS to do Arp/Routing # Propose to community to allow this to do more gracefully port.update({"admin_state_up": False}) interface_info = info subnet = self._core_plugin._get_subnet(context, interface_info["subnet_id"]) cidr = subnet["cidr"] net_addr, net_len = self.net_addr(cidr) gateway_ip = subnet["gateway_ip"] network_id = subnet['network_id'] tenant_id = subnet['tenant_id'] bnet = brocade_db.get_network(context, network_id) vlan_id = bnet['vlan'] gateway_ip_cidr = gateway_ip + '/' + str(net_len) LOG.debug( "Allocated cidr (%s) from the pool, network_id(%s)" "bnet (%s) vlan (%d) ", gateway_ip_cidr, network_id, bnet, int(vlan_id)) port_filters = { 'network_id': [network_id], 'device_owner': [DEVICE_OWNER_ROUTER_INTF] } port_count = self._core_plugin.get_ports_count( context, port_filters) LOG.info( _LI("BrocadeSVIPlugin.add_router_interface" " ports_count %d"), port_count) # port count is checked against 2 since the # current port is already added to db if port_count == 2: # This subnet is already part of some router is not # supported # in this version of brocadesvi plugin LOG.error( _LE("BrocadeSVIPlugin:adding redundent router" "interface is not supported")) raise Exception( _("BrocadeSVIPlugin:adding redundent" "router interface is not supported")) # res = self._update_ips_for_port(context, port) # gateway_ip = res['ip_address'] # gateway_ip_cidr = gateway_ip +'/'+str(net_len) brocade_db.create_svi(context, router_id, tenant_id, str(vlan_id), True, gateway_ip, str(net_len)) self._invoke_nos_driver_api("create_svi", router_id, vlan_id, gateway_ip_cidr, context, port) self._update_firewall(context, vlan_id, tenant_id) except Exception: LOG.error( _LE("Failed to create Brocade resources to add router " "interface. info=%(info)s, router_id=%(router_id)s"), { "info": info, "router_id": router_id }) with excutils.save_and_reraise_exception(): self._invoke_nos_driver_api("delete_svi", router_id, vlan_id, gateway_ip_cidr) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).\ remove_router_interface(context, router_id, interface_info) return info
def add_router_interface(self, context, router_id, interface_info): """creates svi on NOS device and assigns ip addres to SVI.""" LOG.debug("BrocadeSVIPlugin.add_router_interface on VDX: " "router_id=%(router_id)s " "interface_info=%(interface_info)r", {'router_id': router_id, 'interface_info': interface_info}) with context.session.begin(subtransactions=True): info = super(BrocadeSVIPlugin, self).add_router_interface( context, router_id, interface_info) port = db.get_port(context.session, info["port_id"]) # shutting down neutron port to allow NOS to do Arp/Routing port['admin_state_up'] = False port['port'] = port self._core_plugin.update_port(context, info["port_id"], port) interface_info = info subnet = self._core_plugin._get_subnet(context, interface_info["subnet_id"]) cidr = subnet["cidr"] net_addr, net_len = self.net_addr(cidr) gateway_ip = subnet["gateway_ip"] network_id = subnet['network_id'] bnet = brocade_db.get_network(context, network_id) vlan_id = bnet['vlan'] gateway_ip_cidr = gateway_ip + '/' + str(net_len) LOG.debug("Allocated cidr %(cidr)s from the pool, " "network_id %(net_id)s " "bnet %(bnet)s " "vlan %(vlan_id)d ", {'cidr': gateway_ip_cidr, 'net_id': network_id, 'bnet': bnet, 'vlan_id': int(vlan_id)}) port_filters = {'network_id': [network_id], 'device_owner': [DEVICE_OWNER_ROUTER_INTF]} port_count = self._core_plugin.get_ports_count(context, port_filters) LOG.info(_LI("BrocadeSVIPlugin.add_router_interface ports_count " "%d"), port_count) # port count is checked against 2 since the current port is already # added to db if port_count == 2: # This subnet is already part of some router # (this is not supported in this version of brocade svi plugin) msg = _("BrocadeSVIPlugin: adding redundant router interface " "is not supported") LOG.error(msg) raise Exception(msg) try: switch = self._switch self._driver.create_svi(switch['address'], switch['username'], switch['password'], switch['rbridge_id'], vlan_id, gateway_ip_cidr, str(router_id)) except Exception: LOG.error(_LE("Failed to create Brocade resources to add router " "interface. info=%(info)s, router_id=%(router_id)s"), {"info": info, "router_id": router_id}) with excutils.save_and_reraise_exception(): with context.session.begin(subtransactions=True): self.remove_router_interface(context, router_id, interface_info) return info