Ejemplo n.º 1
0
def _handleBondings(bondings, configurator):
    """ Add/Edit/Remove bond interface """
    logger = logging.getLogger("_handleBondings")

    _netinfo = netinfo.NetInfo()

    edition = []
    addition = []
    for name, attrs in bondings.items():
        if 'remove' in attrs:
            bond = Bond.objectivize(name, configurator, attrs.get('options'),
                                    attrs.get('nics'), mtu=None,
                                    _netinfo=_netinfo,
                                    destroyOnMasterRemoval='remove' in attrs)
            bond.remove()
            del _netinfo.bondings[name]
        elif name in _netinfo.bondings:
            edition.append((name, attrs))
        else:
            addition.append((name, attrs))

    for name, attrs in edition:
        bond = Bond.objectivize(name, configurator, attrs.get('options'),
                                attrs.get('nics'), mtu=None, _netinfo=_netinfo,
                                destroyOnMasterRemoval='remove' in attrs)
        logger.debug("Editing bond %r with options %s", bond, bond.options)
        configurator.editBonding(bond, _netinfo)
    for name, attrs in addition:
        bond = Bond.objectivize(name, configurator, attrs.get('options'),
                                attrs.get('nics'), mtu=None, _netinfo=_netinfo,
                                destroyOnMasterRemoval='remove' in attrs)
        logger.debug("Creating bond %r with options %s", bond, bond.options)
        configurator.configureBond(bond)
Ejemplo n.º 2
0
def _handleBondings(bondings, configurator):
    """ Add/Edit/Remove bond interface """
    logger = logging.getLogger("_handleBondings")

    _netinfo = netinfo.NetInfo()

    for bondName, bondAttrs in bondings.items():
        bond = Bond.objectivize(bondName,
                                configurator,
                                bondAttrs.get('options'),
                                bondAttrs.get('nics'),
                                mtu=None,
                                _netinfo=_netinfo,
                                destroyOnMasterRemoval='remove' in bondAttrs)
        if 'remove' in bondAttrs:
            logger.debug("Removing bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.removeBond(bond)
            del bondings[bondName]
            del _netinfo.bondings[bondName]
        elif bondName in _netinfo.bondings:
            logger.debug("Editing bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.editBonding(bond, _netinfo)
        else:
            logger.debug("Creating bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.configureBond(bond)
Ejemplo n.º 3
0
def _handleBondings(bondings, configurator):
    """ Add/Edit/Remove bond interface """
    logger = logging.getLogger("_handleBondings")

    _netinfo = netinfo.NetInfo()

    for bondName, bondAttrs in bondings.items():
        bond = Bond.objectivize(bondName, configurator,
                                bondAttrs.get('options'),
                                bondAttrs.get('nics'), mtu=None,
                                _netinfo=_netinfo,
                                destroyOnMasterRemoval='remove' in bondAttrs)
        if 'remove' in bondAttrs:
            logger.debug("Removing bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.removeBond(bond)
            del bondings[bondName]
            del _netinfo.bondings[bondName]
        elif bondName in _netinfo.bondings:
            logger.debug("Editing bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.editBonding(bond, _netinfo)
        else:
            logger.debug("Creating bond %s with attributes %s", bondName,
                         bondAttrs)
            configurator.configureBond(bond)
Ejemplo n.º 4
0
def objectivizeNetwork(bridge=None, vlan=None, bonding=None,
                       bondingOptions=None, nics=None, mtu=None, ipaddr=None,
                       netmask=None, gateway=None, bootproto=None,
                       ipv6addr=None, ipv6gateway=None, ipv6autoconf=None,
                       dhcpv6=None, defaultRoute=None, _netinfo=None,
                       configurator=None, blockingdhcp=None,
                       implicitBonding=None, **opts):
    """
    Constructs an object hierarchy that describes the network configuration
    that is passed in the parameters.

    :param bridge: name of the bridge.
    :param vlan: vlan tag id.
    :param bonding: name of the bond.
    :param bondingOptions: bonding options separated by spaces.
    :param nics: list of nic names.
    :param mtu: the desired network maximum transmission unit.
    :param ipaddr: IPv4 address in dotted decimal format.
    :param netmask: IPv4 mask in dotted decimal format.
    :param gateway: IPv4 address in dotted decimal format.
    :param bootproto: protocol for getting IP config for the net, e.g., 'dhcp'
    :param ipv6addr: IPv6 address in format address[/prefixlen].
    :param ipv6gateway: IPv6 address in format address[/prefixlen].
    :param ipv6autoconf: whether to use IPv6's stateless autoconfiguration.
    :param dhcpv6: whether to use DHCPv6.
    :param _netinfo: network information snapshot.
    :param configurator: instance to use to apply the network configuration.
    :param blockingdhcp: whether to acquire dhcp IP config in a synced manner.
    :param implicitBonding: whether the bond's existance is tied to it's
                            master's.
    :param defaultRoute: Should this network's gateway be set in the main
                         routing table?

    :returns: the top object of the hierarchy.
    """
    if configurator is None:
        configurator = ConfiguratorClass()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    if bondingOptions and not bonding:
        raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Bonding options '
                                 'specified without bonding')
    topNetDev = None
    if bonding:
        topNetDev = Bond.objectivize(bonding, configurator, bondingOptions,
                                     nics, mtu, _netinfo, implicitBonding)
    elif nics:
        try:
            nic, = nics
        except ValueError:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Multiple nics '
                                     'require a bonding device')
        else:
            bond = _netinfo.getBondingForNic(nic)
            if bond:
                raise ConfigNetworkError(ne.ERR_USED_NIC, 'nic %s already '
                                         'enslaved to %s' % (nic, bond))
            topNetDev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
    if vlan is not None:
        topNetDev = Vlan(topNetDev, vlan, configurator, mtu=mtu)
    if bridge:
        topNetDev = Bridge(bridge, configurator, port=topNetDev, mtu=mtu,
                           stp=opts.get('stp'))
    if topNetDev is None:
        raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without '
                                 'devices.')
    ipv6 = IPv6(ipv6addr, ipv6gateway, defaultRoute)
    ipv4 = IPv4(ipaddr, netmask, gateway, defaultRoute)
    topNetDev.ip = IpConfig(inet4=ipv4, inet6=ipv6, bootproto=bootproto,
                            blocking=utils.tobool(blockingdhcp),
                            ipv6autoconf=ipv6autoconf, dhcpv6=dhcpv6)
    return topNetDev
Ejemplo n.º 5
0
def objectivizeNetwork(bridge=None,
                       vlan=None,
                       bonding=None,
                       bondingOptions=None,
                       nics=None,
                       mtu=None,
                       ipaddr=None,
                       netmask=None,
                       gateway=None,
                       bootproto=None,
                       _netinfo=None,
                       configurator=None,
                       blockingdhcp=None,
                       implicitBonding=None,
                       defaultRoute=None,
                       **opts):
    """
    Constructs an object hierarchy that describes the network configuration
    that is passed in the parameters.

    :param bridge: name of the bridge.
    :param vlan: vlan tag id.
    :param bonding: name of the bond.
    :param bondingOptions: bonding options separated by spaces.
    :param nics: list of nic names.
    :param mtu: the desired network maximum transmission unit.
    :param ipaddr: IPv4 address in dotted decimal format.
    :param netmask: IPv4 mask in dotted decimal format.
    :param gateway: IPv4 address in dotted decimal format.
    :param bootproto: protocol for getting IP config for the net, e.g., 'dhcp'
    :param _netinfo: network information snapshot.
    :param configurator: instance to use to apply the network configuration.
    :param blockingdhcp: whether to acquire dhcp IP config in a synced manner.
    :param implicitBonding: whether the bond's existance is tied to it's
                            master's.
    :param defaultRoute: Should this network's gateway be set in the main
                         routing table?

    :returns: the top object of the hierarchy.
    """
    if configurator is None:
        configurator = Ifcfg()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    if bondingOptions and not bonding:
        raise ConfigNetworkError(
            ne.ERR_BAD_BONDING, 'Bonding options '
            'specified without bonding')
    topNetDev = None
    if bonding:
        topNetDev = Bond.objectivize(bonding, configurator, bondingOptions,
                                     nics, mtu, _netinfo, implicitBonding)
    elif nics:
        try:
            nic, = nics
        except ValueError:
            raise ConfigNetworkError(
                ne.ERR_BAD_BONDING, 'Multiple nics '
                'require a bonding device')
        else:
            bond = _netinfo.getBondingForNic(nic)
            if bond:
                raise ConfigNetworkError(
                    ne.ERR_USED_NIC, 'nic %s already '
                    'enslaved to %s' % (nic, bond))
            topNetDev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
    if vlan:
        topNetDev = Vlan(topNetDev, vlan, configurator, mtu=mtu)
    if bridge:
        topNetDev = Bridge(bridge,
                           configurator,
                           port=topNetDev,
                           mtu=mtu,
                           stp=opts.get('stp'),
                           forwardDelay=int(opts.get('forward_delay', 0)))
    if topNetDev is None:
        raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without'
                                 'devices.')
    topNetDev.ip = IpConfig(inet=IPv4(ipaddr, netmask, gateway, defaultRoute),
                            bootproto=bootproto,
                            blocking=utils.tobool(blockingdhcp))
    return topNetDev
Ejemplo n.º 6
0
def objectivizeNetwork(bridge=None, vlan=None, bonding=None,
                       bondingOptions=None, nics=None, mtu=None, ipaddr=None,
                       netmask=None, gateway=None, bootproto=None,
                       _netinfo=None, configurator=None, blockingdhcp=None,
                       **opts):
    """
    Constructs an object hierarchy that describes the network configuration
    that is passed in the parameters.

    :param bridge: name of the bridge.
    :param vlan: vlan tag id.
    :param bonding: name of the bond.
    :param bondingOptions: bonding options separated by spaces.
    :param nics: list of nic names.
    :param mtu: the desired network maximum transmission unit.
    :param ipaddr: IPv4 address in dotted decimal format.
    :param netmask: IPv4 mask in dotted decimal format.
    :param gateway: IPv4 address in dotted decimal format.
    :param bootproto: protocol for getting IP config for the net, e.g., 'dchp'
    :param _netinfo: network information snapshot.
    :param configurator: instance to use to apply the network configuration.
    :param blockingdhcp: whether to acquire dhcp IP config in a synced manner.

    :returns: the top object of the hierarchy.
    """
    if configurator is None:
        configurator = Ifcfg()
    if _netinfo is None:
        _netinfo = netinfo.NetInfo()
    if bondingOptions and not bonding:
        raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Bonding options '
                                 'specified without bonding')
    topNetDev = None
    if bonding:
        topNetDev = Bond.objectivize(bonding, configurator, bondingOptions,
                                     nics, mtu, _netinfo)
    elif nics:
        try:
            nic, = nics
        except ValueError:
            raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Multiple nics '
                                     'require a bonding device')
        else:
            bond = _netinfo.getBondingForNic(nic)
            if bond:
                raise ConfigNetworkError(ne.ERR_USED_NIC, 'nic %s already '
                                         'enslaved to %s' % (nic, bond))
            topNetDev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
    if vlan:
        topNetDev = Vlan(topNetDev, vlan, configurator, mtu=mtu)
    if bridge:
        topNetDev = Bridge(bridge, configurator, port=topNetDev, mtu=mtu,
                           stp=opts.get('stp'),
                           forwardDelay=opts.get('forward_delay', 0))
    if topNetDev is None:
        raise ConfigNetworkError(ne.ERR_BAD_PARAMS, 'Network defined without'
                                 'devices.')
    topNetDev.ip = IpConfig(inet=IPv4(ipaddr, netmask, gateway),
                            bootproto=bootproto,
                            blocking=utils.tobool(blockingdhcp))
    return topNetDev