Пример #1
0
def _translate_ipaddr(attributes, net_attr):
    attributes['bootproto'] = 'dhcp' if net_attr['dhcpv4'] else 'none'
    attributes['dhcpv6'] = net_attr['dhcpv6']
    attributes['ipv6autoconf'] = net_attr['ipv6autoconf']

    dg_obj = routes.getDefaultGateway()
    dg = dg_obj.via if dg_obj else None
    if dg and net_attr['gateway']:
        attributes['defaultRoute'] = (dg == net_attr['gateway'])
    else:
        attributes['defaultRoute'] = False

    # only static addresses are part of {Persistent,Running}Config.
    if attributes['bootproto'] == 'none':
        if net_attr['addr']:
            attributes['ipaddr'] = net_attr['addr']
        if net_attr['netmask']:
            attributes['netmask'] = net_attr['netmask']
        if net_attr['gateway']:
            attributes['gateway'] = net_attr['gateway']
    if not attributes['dhcpv6']:
        if net_attr['ipv6addrs']:
            attributes['ipv6addr'] = net_attr['ipv6addrs']
        if net_attr['ipv6gateway'] != '::':
            attributes['ipv6gateway'] = net_attr['ipv6gateway']
Пример #2
0
def _translate_ipaddr(attributes, net_attr):
    attributes['bootproto'] = 'dhcp' if net_attr['dhcpv4'] else 'none'
    attributes['dhcpv6'] = net_attr['dhcpv6']
    attributes['ipv6autoconf'] = net_attr['ipv6autoconf']

    dg_obj = routes.getDefaultGateway()
    dg = dg_obj.via if dg_obj else None
    if dg and net_attr['gateway']:
        attributes['defaultRoute'] = (dg == net_attr['gateway'])
    else:
        attributes['defaultRoute'] = False

    # only static addresses are part of {Persistent,Running}Config.
    if attributes['bootproto'] == 'none':
        if net_attr['addr']:
            attributes['ipaddr'] = net_attr['addr']
        if net_attr['netmask']:
            attributes['netmask'] = net_attr['netmask']
        if net_attr['gateway']:
            attributes['gateway'] = net_attr['gateway']
    if not attributes['dhcpv6']:
        if net_attr['ipv6addrs']:
            attributes['ipv6addr'] = net_attr['ipv6addrs']
        if net_attr['ipv6gateway'] != '::':
            attributes['ipv6gateway'] = net_attr['ipv6gateway']
Пример #3
0
def preserve_default_route():
    ipv4_dg_data = routes.getDefaultGateway()
    ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None
    ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None

    ipv6_dg_data = routes.ipv6_default_gateway()
    ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None
    ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None

    try:
        yield
    finally:
        if ipv4_gateway and not routes.is_default_route(ipv4_gateway):
            address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device)
        if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway):
            address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
Пример #4
0
def preserve_default_route():
    ipv4_dg_data = routes.getDefaultGateway()
    ipv4_gateway = ipv4_dg_data.via if ipv4_dg_data else None
    ipv4_device = ipv4_dg_data.device if ipv4_dg_data else None

    ipv6_dg_data = routes.ipv6_default_gateway()
    ipv6_gateway = ipv6_dg_data.via if ipv6_dg_data else None
    ipv6_device = ipv6_dg_data.device if ipv6_dg_data else None

    try:
        yield
    finally:
        if ipv4_gateway and not routes.is_default_route(ipv4_gateway):
            address.set_default_route(ipv4_gateway, family=4, dev=ipv4_device)
        if ipv6_gateway and not routes.is_ipv6_default_route(ipv6_gateway):
            address.set_default_route(ipv6_gateway, family=6, dev=ipv6_device)
Пример #5
0
    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
Пример #6
0
    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