class LinuxOVSRyuInterfaceDriver(linux_net.LinuxOVSInterfaceDriver): def __init__(self): super(LinuxOVSRyuInterfaceDriver, self).__init__() LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host) self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host) self.datapath_id = _get_datapath_id( FLAGS.linuxnet_ovs_integration_bridge) if linux_net.binary_name == 'nova-network': for tables in [linux_net.iptables_manager.ipv4, linux_net.iptables_manager.ipv6]: tables['filter'].add_rule( 'FORWARD', '--in-interface gw-+ --out-interface gw-+ -j DROP') linux_net.iptables_manager.apply() def plug(self, network, mac_address, gateway=True): LOG.debug("network %s mac_adress %s gateway %s", network, mac_address, gateway) ret = super(LinuxOVSRyuInterfaceDriver, self).plug( network, mac_address, gateway) port_no = _get_port_no(self.get_dev(network)) self.ryu_client.create_port(network['uuid'], self.datapath_id, port_no) return ret
class RyuInterfaceDriver(OVSInterfaceDriver): """Driver for creating a Ryu OVS interface.""" def __init__(self, conf): super(RyuInterfaceDriver, self).__init__(conf) from ryu.app.client import OFPClient LOG.debug('ryu rest host %s', self.conf.ryu_api_host) self.ryu_client = OFPClient(self.conf.ryu_api_host) def plug(self, network_id, port_id, device_name, mac_address, bridge=None, namespace=None, prefix=None): """Plug in the interface.""" super(RyuInterfaceDriver, self).plug(network_id, port_id, device_name, mac_address, bridge=bridge, namespace=namespace, prefix=prefix) if not bridge: bridge = self.conf.ovs_integration_bridge self.check_bridge_exists(bridge) ovs_br = ovs_lib.OVSBridge(bridge, self.conf.root_helper) datapath_id = ovs_br.get_datapath_id() port_no = ovs_br.get_port_ofport(device_name) self.ryu_client.create_port(network_id, datapath_id, port_no)
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtOpenVswitchDriver): def __init__(self, **kwargs): super(LibvirtOpenVswitchOFPRyuDriver, self).__init__() LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge) self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host) self.datapath_id = ovs_utils.get_datapath_id(FLAGS.libvirt_ovs_bridge) def _get_port_no(self, mapping): iface_id = mapping['vif_uuid'] dev = self.get_dev_name(iface_id) return ovs_utils.get_port_no(dev) def plug(self, instance, network, mapping): result = super(LibvirtOpenVswitchOFPRyuDriver, self).plug( instance, network, mapping) port_no = self._get_port_no(mapping) self.ryu_client.create_port(network['id'], self.datapath_id, port_no) return result def unplug(self, instance, network, mapping): port_no = self._get_port_no(mapping) try: self.ryu_client.delete_port(network['id'], self.datapath_id, port_no) except httplib.HTTPException as e: res = e.args[0] if res.status != httplib.NOT_FOUND: raise super(LibvirtOpenVswitchOFPRyuDriver, self).unplug(instance, network, mapping)
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtOpenVswitchDriver): def __init__(self, **kwargs): super(LibvirtOpenVswitchOFPRyuDriver, self).__init__() LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge) self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host) self.datapath_id = _get_datapath_id(FLAGS.libvirt_ovs_bridge) def _get_port_no(self, mapping): iface_id = mapping['vif_uuid'] dev = self.get_dev_name(iface_id) return _get_port_no(dev) def plug(self, instance, network, mapping): result = super(LibvirtOpenVswitchOFPRyuDriver, self).plug(instance, network, mapping) port_no = self._get_port_no(mapping) self.ryu_client.create_port(network['id'], self.datapath_id, port_no) return result def unplug(self, instance, network, mapping): port_no = self._get_port_no(mapping) try: self.ryu_client.delete_port(network['id'], self.datapath_id, port_no) except httplib.HTTPException as e: res = e.args[0] if res.status != httplib.NOT_FOUND: raise super(LibvirtOpenVswitchOFPRyuDriver, self).unplug(instance, network, mapping)
class LinuxOVSRyuInterfaceDriver(object): nova_linux_net = None def __init__(self): if self.nova_linux_net is None: self.nova_linux_net = utils.import_object('nova.network.linux_net') cls = utils.import_class( 'nova.network.linux_net.LinuxOVSInterfaceDriver') self.parent = cls() LOG.debug('ryu rest host %s', FLAGS.linuxnet_ovs_ryu_api_host) self.ryu_client = OFPClient(FLAGS.linuxnet_ovs_ryu_api_host) self.datapath_id = ovs_utils.get_datapath_id( FLAGS.linuxnet_ovs_integration_bridge) if self.nova_linux_net.binary_name == 'nova-network': for tables in [ self.nova_linux_net.iptables_manager.ipv4, self.nova_linux_net.iptables_manager.ipv6 ]: tables['filter'].add_rule( 'FORWARD', '--in-interface gw-+ --out-interface gw-+ -j DROP') self.nova_linux_net.iptables_manager.apply() def plug(self, network, mac_address, gateway=True): LOG.debug("network %s mac_adress %s gateway %s", network, mac_address, gateway) ret = self.parent.plug(network, mac_address, gateway) port_no = ovs_utils.get_port_no(self.get_dev(network)) self.ryu_client.create_port(network['uuid'], self.datapath_id, port_no) return ret def unplug(self, network): return self.parent.unplug(network) def get_dev(self, network): return self.parent.get_dev(network)
class LibvirtOpenVswitchOFPRyuDriver(libvirt_vif.LibvirtHybridOVSBridgeDriver): def __init__(self, **kwargs): super(LibvirtOpenVswitchOFPRyuDriver, self).__init__() LOG.debug('ryu rest host %s', FLAGS.libvirt_ovs_bridge) self.ryu_client = OFPClient(FLAGS.libvirt_ovs_ryu_api_host) self.datapath_id = _get_datapath_id(FLAGS.libvirt_ovs_bridge) def _get_port_no(self, mapping): iface_id = mapping['vif_uuid'] _v1_name, v2_name = self.get_veth_pair_names(iface_id) return _get_port_no(v2_name) def plug(self, instance, vif): result = super(LibvirtOpenVswitchOFPRyuDriver, self).plug( instance, vif) network, mapping = vif port_no = self._get_port_no(mapping) try: self.ryu_client.create_port(network['id'], self.datapath_id, port_no) except httplib.HTTPException as e: res = e.args[0] if res.status != httplib.CONFLICT: raise return result def unplug(self, instance, vif): network, mapping = vif port_no = self._get_port_no(mapping) try: self.ryu_client.delete_port(network['id'], self.datapath_id, port_no) except httplib.HTTPException as e: res = e.args[0] if res.status != httplib.NOT_FOUND: raise super(LibvirtOpenVswitchOFPRyuDriver, self).unplug(instance, vif)