def _get_interface_config(self, networktype):
        config = {}

        network_interface = interface.find_interface_by_type(
            self.context, networktype)

        if network_interface:
            interface_name = interface.get_interface_os_ifname(
                self.context, network_interface)
            interface_devices = interface.get_interface_devices(
                self.context, network_interface)
            network_id = interface.find_network_id_by_networktype(
                self.context, networktype)
            # Convert the dash to underscore because puppet parameters cannot
            # have dashes
            networktype = networktype.replace('-', '_')
            config.update({
                'platform::network::%s::params::interface_name' % networktype:
                interface_name,
                'platform::network::%s::params::interface_devices' % networktype:
                interface_devices,
                'platform::network::%s::params::mtu' % networktype:
                network_interface.imtu
            })

            interface_address = interface.get_interface_primary_address(
                self.context, network_interface, network_id)
            if interface_address:
                config.update({
                    'platform::network::%s::params::interface_address' % networktype:
                    interface_address['address']
                })

        return config
Beispiel #2
0
    def _get_ptp_interface_config(self):
        config = {}
        ptp_devices = {
            constants.INTERFACE_PTP_ROLE_MASTER: [],
            constants.INTERFACE_PTP_ROLE_SLAVE: []
        }
        ptp_interfaces = interface.get_ptp_interfaces(self.context)
        ptp = self.dbapi.ptp_get_one()
        is_udp = (ptp.transport == constants.PTP_TRANSPORT_UDP)
        for network_interface in ptp_interfaces:
            interface_devices = interface.get_interface_devices(self.context, network_interface)

            address_family = None
            if is_udp:
                address = interface.get_interface_primary_address(self.context, network_interface)
                if address:
                    address_family = netaddr.IPAddress(address['address']).version

            for device in interface_devices:
                ptp_devices[network_interface['ptp_role']].append({'device': device, 'family': address_family})

        config.update({
            'platform::ptp::master_devices': ptp_devices[constants.INTERFACE_PTP_ROLE_MASTER],
            'platform::ptp::slave_devices': ptp_devices[constants.INTERFACE_PTP_ROLE_SLAVE]
        })

        return config
Beispiel #3
0
    def _get_port_config(self, host):
        ovs_devices = {}
        ovs_bridges = {}
        ovs_ports = {}
        ovs_addresses = {}
        ovs_flows = {}

        index = 0
        for iface in sorted(self.context['interfaces'].values(),
                            key=interface.interface_sort_key):
            if interface.is_data_network_type(iface):
                # create a separate bridge for every configured data interface
                brname = 'br-phy%d' % index
                ovs_bridges[brname] = {}

                # save the associated bridge for provider network mapping
                iface['_ovs_bridge'] = brname

                if iface['iftype'] == constants.INTERFACE_TYPE_ETHERNET:
                    port, devices = self._get_ethernet_port(
                        host, iface, brname, index)
                elif iface['iftype'] == constants.INTERFACE_TYPE_AE:
                    port, devices = self._get_bond_port(
                        host, iface, brname, index)
                elif iface['iftype'] == constants.INTERFACE_TYPE_VLAN:
                    port, devices = self._get_vlan_port(
                        host, iface, brname, index)
                else:
                    raise Exception("unsupported interface type: %s" %
                                    iface['iftype'])

                ovs_ports.update({port['name']: port})
                ovs_devices.update({d['pci_addr']: d for d in devices})

                if iface['iftype'] == constants.INTERFACE_TYPE_ETHERNET:
                    ovs_ifname = port['interfaces'][0]['name']
                    lldp_port = self._get_lldp_port(iface,
                                                    brname,
                                                    ovs_ifname=ovs_ifname)
                    ovs_ports.update({lldp_port['name']: lldp_port})
                    flow = self._get_lldp_flow(brname, ovs_ifname,
                                               lldp_port['name'])
                    ovs_flows.update({port['name']: flow})

                if iface['iftype'] == constants.INTERFACE_TYPE_AE:
                    slaves = interface.get_interface_slaves(
                        self.context, iface)
                    for member, slave in enumerate(slaves):
                        ovs_ifname = port['interfaces'][member]['name']

                        lldp_port = self._get_lldp_port(slave,
                                                        brname,
                                                        ovs_ifname=ovs_ifname)
                        ovs_ports.update({lldp_port['name']: lldp_port})
                        flow = self._get_lldp_flow(brname, ovs_ifname,
                                                   lldp_port['name'])
                        ovs_flows.update({flow['name']: flow})
                        flow = self._get_lldp_flow(brname, lldp_port['name'],
                                                   ovs_ifname)
                        ovs_flows.update({flow['name']: flow})

                index += 1

                datanets = interface.get_interface_datanets(
                    self.context, iface)

                # setup tunnel address if assigned provider network is vxlan
                if datanets and self._is_vxlan_datanet(datanets[0]):
                    address = interface.get_interface_primary_address(
                        self.context, iface)
                    if address:
                        ovs_addresses[brname] = {
                            'ifname': brname,
                            'address': address['address'],
                            'prefixlen': address['prefix'],
                        }

        ovs_dict = {
            'platform::vswitch::ovs::devices': ovs_devices,
            'platform::vswitch::ovs::bridges': ovs_bridges,
            'platform::vswitch::ovs::ports': ovs_ports,
            'platform::vswitch::ovs::addresses': ovs_addresses,
            'platform::vswitch::ovs::flows': ovs_flows,
        }

        LOG.debug("_get_port_config=%s" % ovs_dict)

        return ovs_dict