예제 #1
0
def _top_dev(network, attrs):
    if utils.tobool(attrs.get('bridged')):
        return network
    # bridgeless
    nics, vlan, _, bonding = netinfo.cache.NetInfo(
        netswitch.netinfo()).getNicsVlanAndBondingForNetwork(network)
    return vlan or bonding or nics[0]
예제 #2
0
def _top_dev(network, attrs):
    if utils.tobool(attrs.get('bridged')):
        return network
    # bridgeless
    nics, vlan, _, bonding = netinfo.cache.NetInfo(
        netswitch.netinfo()).getNicsVlanAndBondingForNetwork(network)
    return vlan or bonding or nics[0]
예제 #3
0
def _handle_setup(nets, bonds, running_config, nets_by_nic):
    commands = []
    netinfo = NetInfo(netswitch.netinfo())
    for bond, attrs in six.iteritems(bonds):
        if 'remove' not in attrs:
            _validate_bond_configuration(attrs, netinfo)
            if bond in running_config.bonds:
                commands.extend(_edit_ovs_bond(bond, attrs, running_config))
            else:
                commands.extend(_setup_ovs_bond(bond, attrs, running_config))
    for net, attrs in six.iteritems(nets):
        if 'remove' not in attrs:
            _validate_net_configuration(net, attrs, running_config, netinfo)
            if net in running_config.networks:
                commands.extend(_edit_ovs_net(net, attrs, running_config,
                                              nets_by_nic))
            else:
                commands.extend(_setup_ovs_net(net, attrs, running_config,
                                               nets_by_nic))
    return commands
예제 #4
0
def _getNetInfo():
    def _processNetworks(netinfo):
        networks = {}
        defaultGateway = routes.getDefaultGateway()

        for network, netParams in netinfo.networks.iteritems():
            networks[network] = {}

            # Translate key/value pairs from netinfo to unified if key matches
            for key, value in netParams.iteritems():
                if key in NET_ATTR_WHITELIST and value != "":
                    networks[network][key] = NET_ATTR_WHITELIST[key](value)

            networks[network]['bridged'] = netParams['bridged']

            # Determine devices: nic/bond -> vlan -> bridge
            topLevelDevice = netParams['iface']
            if netParams['bridged']:
                devices = (netinfo.nics.keys() + netinfo.vlans.keys() +
                           netinfo.bondings.keys())
                nonVnicPorts = [dev for dev in netParams['ports'] if
                                dev in devices]
                # A network should only ever have (at most) an underlying
                # device hierarchy
                if nonVnicPorts:
                    physicalDevice, = nonVnicPorts
                else:
                    physicalDevice = None  # vdsm allows nicless VM nets
            else:
                physicalDevice = topLevelDevice

            # Copy ip addressing information
            bootproto = str(misc.getIfaceCfg(topLevelDevice).get('BOOTPROTO'))
            if bootproto == 'dhcp':
                networks[network]['bootproto'] = bootproto
            else:
                if netParams['addr'] != '':
                    networks[network]['ipaddr'] = netParams['addr']
                if netParams['netmask'] != '':
                    networks[network]['netmask'] = netParams['netmask']
                if netParams['gateway'] != '':
                    networks[network]['gateway'] = netParams['gateway']

            if defaultGateway is not None:
                networks[network]['defaultRoute'] = (defaultGateway.device ==
                                                     topLevelDevice)

            # What if the 'physical device' is actually a VLAN?
            if physicalDevice in netinfo.vlans:
                vlanDevice = physicalDevice
                networks[network]['vlan'] = \
                    str(netinfo.vlans[vlanDevice]['vlanid'])
                # The 'new' physical device is the VLAN's device
                physicalDevice = netinfo.vlans[vlanDevice]['iface']

            # Is the physical device a bond or a nic?
            if physicalDevice in netinfo.bondings:
                networks[network]['bonding'] = physicalDevice
            elif physicalDevice in netinfo.nics:
                networks[network]['nic'] = physicalDevice
            else:  # Nic-less networks
                pass

        return networks

    def _processBondings(netinfo):
        bondings = {}
        for bonding, bondingParams in netinfo.bondings.iteritems():
            # If the bond is unused, skip it
            if not bondingParams['slaves']:
                continue

            bondings[bonding] = {'nics': bondingParams['slaves']}
            bondingOptions = misc.getIfaceCfg(bonding). \
                get('BONDING_OPTS')
            if bondingOptions:
                bondings[bonding]['options'] = bondingOptions

        return bondings

    netinfo = NetInfo(netswitch.netinfo())
    networks = _processNetworks(netinfo)
    bonds = _processBondings(netinfo)

    used_bonds = frozenset(
        attr['bonding'] for attr in networks.values()
        if 'bonding' in attr)

    # we do not want to touch bonds that are unrelated to us
    for bonding in bonds.keys():
        if not _owned(bonding) and bonding not in used_bonds:
            del bonds[bonding]

    # assert that all bonds that we depend on are persisted
    for network, attributes in networks.iteritems():
        bond = attributes.get('bonding')
        if bond is None:
            continue

        if bond not in bonds:
            raise Exception(
                'Network %s depends on missing bond %s' %
                (network, bond))

    return networks, bonds
예제 #5
0
def _getNetInfo():
    def _processNetworks(netinfo):
        networks = {}
        defaultGateway = routes.getDefaultGateway()

        for network, netParams in netinfo.networks.iteritems():
            networks[network] = {}

            # Translate key/value pairs from netinfo to unified if key matches
            for key, value in netParams.iteritems():
                if key in NET_ATTR_WHITELIST and value != "":
                    networks[network][key] = NET_ATTR_WHITELIST[key](value)

            networks[network]['bridged'] = netParams['bridged']

            # Determine devices: nic/bond -> vlan -> bridge
            topLevelDevice = netParams['iface']
            if netParams['bridged']:
                devices = (netinfo.nics.keys() + netinfo.vlans.keys() +
                           netinfo.bondings.keys())
                nonVnicPorts = [
                    dev for dev in netParams['ports'] if dev in devices
                ]
                # A network should only ever have (at most) an underlying
                # device hierarchy
                if nonVnicPorts:
                    physicalDevice, = nonVnicPorts
                else:
                    physicalDevice = None  # vdsm allows nicless VM nets
            else:
                physicalDevice = topLevelDevice

            # Copy ip addressing information
            bootproto = str(misc.getIfaceCfg(topLevelDevice).get('BOOTPROTO'))
            if bootproto == 'dhcp':
                networks[network]['bootproto'] = bootproto
            else:
                if netParams['addr'] != '':
                    networks[network]['ipaddr'] = netParams['addr']
                if netParams['netmask'] != '':
                    networks[network]['netmask'] = netParams['netmask']
                if netParams['gateway'] != '':
                    networks[network]['gateway'] = netParams['gateway']

            if defaultGateway is not None:
                networks[network]['defaultRoute'] = (
                    defaultGateway.device == topLevelDevice)

            # What if the 'physical device' is actually a VLAN?
            if physicalDevice in netinfo.vlans:
                vlanDevice = physicalDevice
                networks[network]['vlan'] = \
                    str(netinfo.vlans[vlanDevice]['vlanid'])
                # The 'new' physical device is the VLAN's device
                physicalDevice = netinfo.vlans[vlanDevice]['iface']

            # Is the physical device a bond or a nic?
            if physicalDevice in netinfo.bondings:
                networks[network]['bonding'] = physicalDevice
            elif physicalDevice in netinfo.nics:
                networks[network]['nic'] = physicalDevice
            else:  # Nic-less networks
                pass

        return networks

    def _processBondings(netinfo):
        bondings = {}
        for bonding, bondingParams in netinfo.bondings.iteritems():
            # If the bond is unused, skip it
            if not bondingParams['slaves']:
                continue

            bondings[bonding] = {'nics': bondingParams['slaves']}
            bondingOptions = misc.getIfaceCfg(bonding). \
                get('BONDING_OPTS')
            if bondingOptions:
                bondings[bonding]['options'] = bondingOptions

        return bondings

    netinfo = NetInfo(netswitch.netinfo())
    networks = _processNetworks(netinfo)
    bonds = _processBondings(netinfo)

    used_bonds = frozenset(attr['bonding'] for attr in networks.values()
                           if 'bonding' in attr)

    # we do not want to touch bonds that are unrelated to us
    for bonding in bonds.keys():
        if not _owned(bonding) and bonding not in used_bonds:
            del bonds[bonding]

    # assert that all bonds that we depend on are persisted
    for network, attributes in networks.iteritems():
        bond = attributes.get('bonding')
        if bond is None:
            continue

        if bond not in bonds:
            raise Exception('Network %s depends on missing bond %s' %
                            (network, bond))

    return networks, bonds