예제 #1
0
def _get_ipv4_model(attrs):
    address = attrs.get('ipaddr')
    netmask = attrs.get('netmask')
    gateway = attrs.get('gateway')
    default_route = attrs.get('defaultRoute')
    bootproto = attrs.get('bootproto')
    return IPv4(address, netmask, gateway, default_route, bootproto)
예제 #2
0
 def __init__(self, name, configurator, ipv4=None, ipv6=None,
              blockingdhcp=False, mtu=None):
     self.name = name
     self.ipv4 = ipv4 if ipv4 is not None else IPv4()
     self.ipv6 = ipv6 if ipv6 is not None else IPv6()
     self.blockingdhcp = blockingdhcp
     self.mtu = mtu
     self.configurator = configurator
     self.master = None
     self.duid_source = None
     self.nameservers = None
예제 #3
0
 def removeBond(self, bonding):
     to_be_removed = self._ifaceDownAndCleanup(bonding)
     if to_be_removed:
         self.configApplier.removeBonding(bonding.name)
         if bonding.on_removal_just_detach_from_network:
             # Recreate the bond with ip and master info cleared
             bonding.ipv4 = IPv4()
             bonding.ipv6 = IPv6()
             bonding.master = None
             bonding.configure()
         else:
             for slave in bonding.slaves:
                 slave.remove()
             if self.unifiedPersistence:
                 self.runningConfig.removeBonding(bonding.name)
     else:
         set_mtu = self._setNewMtu(bonding,
                                   vlans.vlan_devs_for_iface(bonding.name))
         # Since we are not taking the device up again, ifcfg will not be
         # read at this point and we need to set the live mtu value.
         # Note that ip link set dev bondX mtu Y sets Y on all its links
         if set_mtu is not None:
             ipwrapper.linkSet(bonding.name, ['mtu', str(set_mtu)])
예제 #4
0
파일: legacy_switch.py 프로젝트: minqf/vdsm
def _objectivize_network(
    bridge=None,
    vlan=None,
    vlan_id=None,
    bonding=None,
    bondattr=None,
    nic=None,
    mtu=None,
    ipaddr=None,
    netmask=None,
    gateway=None,
    bootproto=None,
    ipv6addr=None,
    ipv6gateway=None,
    ipv6autoconf=None,
    dhcpv6=None,
    defaultRoute=None,
    nameservers=None,
    _netinfo=None,
    configurator=None,
    blockingdhcp=None,
    opts=None,
):
    """
    Constructs an object hierarchy that describes the network configuration
    that is passed in the parameters.

    :param bridge: name of the bridge.
    :param vlan: vlan device name.
    :param vlan_id: vlan tag id.
    :param bonding: name of the bond.
    :param bondattr: bond attributes if defined.
    :param nic: name of the nic.
    :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 nameservers: a list of DNS servers.
    :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 defaultRoute: Should this network's gateway be set in the main
                         routing table?
    :param opts: misc options received by the callee, e.g., {'stp': True}. this
                 function can modify the dictionary.

    :returns: the top object of the hierarchy.
    """
    if _netinfo is None:
        _netinfo = CachingNetInfo()
    if configurator is None:
        configurator = Ifcfg(_netinfo)
    if opts is None:
        opts = {}
    if bootproto == 'none':
        bootproto = None

    top_net_dev = None
    if bonding:
        if bondattr is None:
            bondattr = {}
        top_net_dev = Bond.objectivize(
            bonding,
            configurator,
            options=bondattr.get('options'),
            nics=bondattr.get('nics'),
            hwaddr=bondattr.get('hwaddr'),
            mtu=mtu,
            _netinfo=_netinfo,
            on_removal_just_detach_from_network=True,
        )
    elif nic:
        top_net_dev = Nic(nic, configurator, mtu=mtu, _netinfo=_netinfo)
    if vlan is not None:
        tag = _netinfo.vlans[vlan]['vlanid'] if vlan_id is None else vlan_id
        top_net_dev = Vlan(top_net_dev, tag, configurator, mtu=mtu, name=vlan)
    elif vlan_id is not None:
        top_net_dev = Vlan(top_net_dev, vlan_id, configurator, mtu=mtu)
    if bridge is not None:
        top_net_dev = Bridge(
            bridge,
            configurator,
            port=top_net_dev,
            mtu=mtu,
            stp=opts.get('stp', None),
        )
        # Inherit DUID from the port's possibly still active DHCP lease so the
        # bridge gets the same IP address. (BZ#1219429)
        if top_net_dev.port and bootproto == 'dhcp':
            top_net_dev.duid_source = top_net_dev.port.name
    if top_net_dev is None:
        raise ConfigNetworkError(
            ne.ERR_BAD_PARAMS, 'Network defined without ' 'devices.'
        )
    top_net_dev.ipv4 = IPv4(ipaddr, netmask, gateway, defaultRoute, bootproto)
    top_net_dev.ipv6 = IPv6(
        ipv6addr, ipv6gateway, defaultRoute, ipv6autoconf, dhcpv6
    )
    top_net_dev.blockingdhcp = configurator._inRollback or tobool(blockingdhcp)
    top_net_dev.nameservers = nameservers
    return top_net_dev