コード例 #1
0
def get_if_from_hwaddr(hwaddr):
    import sioc
    devs = sioc.gifconf()
    for dev in devs:
        dev_hwaddr = sioc.gifhwaddr(dev)
        if dev_hwaddr == hwaddr: return dev
    return None
コード例 #2
0
ファイル: tools.py プロジェクト: fdawg4l/NodeManager
def get_if_from_hwaddr(hwaddr):
    import sioc
    devs = sioc.gifconf()
    for dev in devs:
        dev_hwaddr = sioc.gifhwaddr(dev)
        if dev_hwaddr == hwaddr: return dev
    return None
コード例 #3
0
ファイル: net.py プロジェクト: fdawg4l/NodeManager
def InitNAT(plc, data):

    # query running network interfaces
    devs = sioc.gifconf()
    ips = dict(zip(devs.values(), devs.keys()))
    macs = {}
    for dev in devs:
        macs[sioc.gifhwaddr(dev).lower()] = dev

    ipt = iptables.IPTables()
    for interface in data[KEY_NAME]:
        # Get interface name preferably from MAC address, falling
        # back on IP address.
        hwaddr=interface['mac']
        if hwaddr <> None: hwaddr=hwaddr.lower()
        if hwaddr in macs:
            dev = macs[interface['mac']]
        elif interface['ip'] in ips:
            dev = ips[interface['ip']]
        else:
            logger.log('net: %s: no such interface with address %s/%s' % (interface['hostname'], interface['ip'], interface['mac']))
            continue

        try:
            settings = plc.GetInterfaceTags({'interface_tag_id': interface['interface_tag_ids']})
        except:
            continue

        for setting in settings:
            if setting['category'].upper() != 'FIREWALL':
                continue
            if setting['name'].upper() == 'EXTERNAL':
                # Enable NAT for this interface
                ipt.add_ext(dev)
            elif setting['name'].upper() == 'INTERNAL':
                ipt.add_int(dev)
            elif setting['name'].upper() == 'PF': # XXX Uglier code is hard to find...
                for pf in setting['value'].split("\n"):
                    fields = {}
                    for field in pf.split(","):
                        (key, val) = field.split("=", 2)
                        fields[key] = val
                    if 'new_dport' not in fields:
                        fields['new_dport'] = fields['dport']
                    if 'source' not in fields:
                        fields['source'] = "0.0.0.0/0"
                    ipt.add_pf(fields)
    ipt.commit()
コード例 #4
0
def InitNAT(plc, data):

    # query running network interfaces
    devs = sioc.gifconf()
    ips = dict(zip(devs.values(), devs.keys()))
    macs = {}
    for dev in devs:
        macs[sioc.gifhwaddr(dev).lower()] = dev

    ipt = iptables.IPTables()
    for interface in data[KEY_NAME]:
        # Get interface name preferably from MAC address, falling
        # back on IP address.
        hwaddr=interface['mac']
        if hwaddr <> None: hwaddr=hwaddr.lower()
        if hwaddr in macs:
            dev = macs[interface['mac']]
        elif interface['ip'] in ips:
            dev = ips[interface['ip']]
        else:
            logger.log('net: %s: no such interface with address %s/%s' % (interface['hostname'], interface['ip'], interface['mac']))
            continue

        try:
            settings = plc.GetInterfaceTags({'interface_tag_id': interface['interface_tag_ids']})
        except:
            continue

        for setting in settings:
            if setting['category'].upper() != 'FIREWALL':
                continue
            if setting['name'].upper() == 'EXTERNAL':
                # Enable NAT for this interface
                ipt.add_ext(dev)
            elif setting['name'].upper() == 'INTERNAL':
                ipt.add_int(dev)
            elif setting['name'].upper() == 'PF': # XXX Uglier code is hard to find...
                for pf in setting['value'].split("\n"):
                    fields = {}
                    for field in pf.split(","):
                        (key, val) = field.split("=", 2)
                        fields[key] = val
                    if 'new_dport' not in fields:
                        fields['new_dport'] = fields['dport']
                    if 'source' not in fields:
                        fields['source'] = "0.0.0.0/0"
                    ipt.add_pf(fields)
    ipt.commit()
コード例 #5
0
ファイル: net.py プロジェクト: fdawg4l/NodeManager
def InitNodeLimit(data):

    # query running network interfaces
    devs = sioc.gifconf()
    ips = dict(zip(devs.values(), devs.keys()))
    macs = {}
    for dev in devs:
        macs[sioc.gifhwaddr(dev).lower()] = dev

    for interface in data[KEY_NAME]:
        # Get interface name preferably from MAC address, falling
        # back on IP address.
        hwaddr=interface['mac']
        if hwaddr <> None: hwaddr=hwaddr.lower()
        if hwaddr in macs:
            dev = macs[interface['mac']]
        elif interface['ip'] in ips:
            dev = ips[interface['ip']]
        else:
            logger.log('net: %s: no such interface with address %s/%s' % (interface['hostname'], interface['ip'], interface['mac']))
            continue

        # Get current node cap
        try:
            old_bwlimit = bwlimit.get_bwcap(dev)
        except:
            old_bwlimit = None

        # Get desired node cap
        if interface['bwlimit'] is None or interface['bwlimit'] < 0:
            new_bwlimit = bwlimit.bwmax
        else:
            new_bwlimit = interface['bwlimit']

        if old_bwlimit != new_bwlimit:
            # Reinitialize bandwidth limits
            bwlimit.init(dev, new_bwlimit)
コード例 #6
0
def InitNodeLimit(data):

    # query running network interfaces
    devs = sioc.gifconf()
    ips = dict(zip(devs.values(), devs.keys()))
    macs = {}
    for dev in devs:
        macs[sioc.gifhwaddr(dev).lower()] = dev

    for interface in data[KEY_NAME]:
        # Get interface name preferably from MAC address, falling
        # back on IP address.
        hwaddr=interface['mac']
        if hwaddr <> None: hwaddr=hwaddr.lower()
        if hwaddr in macs:
            dev = macs[interface['mac']]
        elif interface['ip'] in ips:
            dev = ips[interface['ip']]
        else:
            logger.log('net: %s: no such interface with address %s/%s' % (interface['hostname'], interface['ip'], interface['mac']))
            continue

        # Get current node cap
        try:
            old_bwlimit = bwlimit.get_bwcap(dev)
        except:
            old_bwlimit = None

        # Get desired node cap
        if interface['bwlimit'] is None or interface['bwlimit'] < 0:
            new_bwlimit = bwlimit.bwmax
        else:
            new_bwlimit = interface['bwlimit']

        if old_bwlimit != new_bwlimit:
            # Reinitialize bandwidth limits
            bwlimit.init(dev, new_bwlimit)
コード例 #7
0
ファイル: plnet.py プロジェクト: dreibh/planetlab-lxc-pyplnet
def InitInterfaces(logger, plc, data, root="", files_only=False, program="NodeManager"):
    global version

    sysconfig = "%s/etc/sysconfig/network-scripts" % root
    try:
        os.makedirs(sysconfig)
    except OSError, e:
        if e.errno != errno.EEXIST:
            raise e

    # query running network interfaces
    devs = sioc.gifconf()
    ips = dict(zip(devs.values(), devs.keys()))
    macs = {}
    for dev in devs:
        macs[sioc.gifhwaddr(dev).lower()] = dev

    devices_map = {}
    device_id = 1
    hostname = data.get('hostname',socket.gethostname())
    gateway = None
    # assume data['interfaces'] contains this node's Interfaces
    # can cope with 4.3 ('networks') or 5.0 ('interfaces')
    try:
        interfaces = data['interfaces']
    except:
        interfaces = data['networks']
    failedToGetSettings = False

    # NOTE: GetInterfaces/NodeNetworks does not necessarily order the interfaces
    # returned.  Because 'interface' is decremented as each interface is processed,