Beispiel #1
0
def take_gateway(netspace, ip, host):
    net = Network.get_by_netspace(netspace)
    if not net:
        print 'net %s not found' % netspace
        return
    ipnum = IPAddress(ip).value
    rds.srem(net.gatekey, ipnum)
    VLanGateway.create(ipnum, net.id, host.id)
    print '%s on %s --> %s done' % (ip, host.ip, netspace)
Beispiel #2
0
def take_gateway(netspace, ip, host):
    net = Network.get_by_netspace(netspace)
    if not net:
        print 'net %s not found' % netspace
        return
    ipnum = IPAddress(ip).value
    rds.srem(net.gatekey, ipnum)
    VLanGateway.create(ipnum, net.id, host.id)
    print '%s on %s --> %s done' % (ip, host.ip, netspace)
Beispiel #3
0
def test_network(test_db):
    n = Network.create('net', '10.1.0.0/16')
    assert n is not None
    assert len(n.ips.all()) == 0
    assert n.hostmask_string == '16'
    assert n.pool_size == 65436
    assert n.used_count == 0
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100

    ip = n.acquire_ip()
    assert ip is not None
    assert ip.network_id == n.id
    assert ip.vethname == ''
    assert not ip.container_id
    assert ip.hostmask == n.hostmask_string
    assert ip.vlan_seq_id == n.id
    assert ip.address.startswith('10.1')

    assert len(n.ips.all()) == 1
    assert n.pool_size == 65435
    assert n.used_count == 1

    ip.release()
    assert len(n.ips.all()) == 0
    assert n.pool_size == 65436
    assert n.used_count == 0

    p = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(p, random_ipv4(), random_string(prefix='host'),
                       random_uuid(), 4, 4096)

    gate = n.acquire_gateway_ip(host)
    assert gate is not None
    assert gate.network_id == n.id
    assert gate.vlan_address.startswith('10.1.0.')
    assert gate.vlan_seq_id == n.id
    assert gate.name == 'vlan.%02d.br' % n.id

    g = VLanGateway.get_by_host_and_network(host.id, n.id)
    assert g is not None
    assert g.id == gate.id
    assert len(host.list_vlans()) == 1

    assert n.used_gate_count == 1
    assert n.gate_pool_size == 99

    gate.release()
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100
    assert VLanGateway.get_by_host_and_network(host.id, n.id) is None
    assert len(host.list_vlans()) == 0
Beispiel #4
0
def test_network(test_db):
    n = Network.create('net', '10.1.0.0/16')
    assert n is not None
    assert len(n.ips.all()) == 0
    assert n.hostmask_string == '16'
    assert n.pool_size == 65436
    assert n.used_count == 0
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100

    ip = n.acquire_ip()
    assert ip is not None
    assert ip.network_id == n.id
    assert ip.vethname == ''
    assert not ip.container_id
    assert ip.hostmask == n.hostmask_string
    assert ip.vlan_seq_id == n.id
    assert ip.address.startswith('10.1')

    assert len(n.ips.all()) == 1
    assert n.pool_size == 65435
    assert n.used_count == 1

    ip.release()
    assert len(n.ips.all()) == 0
    assert n.pool_size == 65436
    assert n.used_count == 0

    p = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(p, random_ipv4(), random_string(prefix='host'), random_uuid(), 4, 4096)

    gate = n.acquire_gateway_ip(host)
    assert gate is not None
    assert gate.network_id == n.id
    assert gate.vlan_address.startswith('10.1.0.')
    assert gate.vlan_seq_id == n.id
    assert gate.name == 'vlan.%02d.br' % n.id

    g = VLanGateway.get_by_host_and_network(host.id, n.id)
    assert g is not None
    assert g.id == gate.id
    assert len(host.list_vlans()) == 1

    assert n.used_gate_count == 1
    assert n.gate_pool_size == 99

    gate.release()
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100
    assert VLanGateway.get_by_host_and_network(host.id, n.id) is None
    assert len(host.list_vlans()) == 0
Beispiel #5
0
def macvlan(id_or_name):
    host = _get_host(id_or_name)
    if request.method == 'GET':
        return host.list_vlans(g.start, g.limit)

    data = request.get_json()
    netname = data.get('network', '')
    network = Network.get_by_name(netname)
    if not network:
        abort(404, 'Network not found')

    vg = VLanGateway.get_by_host_and_network(host.id, network.id)
    if request.method == 'POST':
        return vg or network.acquire_gateway_ip(host)
    elif request.method == 'DELETE':
        if vg:
            vg.release()
        return {'r': 0, 'msg': consts.OK}
Beispiel #6
0
def macvlan(id_or_name):
    host = _get_host(id_or_name)
    if request.method == 'GET':
        return host.list_vlans(g.start, g.limit)

    data = request.get_json()
    netname = data.get('network', '')
    network = ipam.get_pool(netname)
    if not network:
        abort(404, 'Network not found')

    vg = VLanGateway.get_by_host_and_network(host.id, network.id)
    if request.method == 'POST':
        return vg or network.acquire_gateway_ip(host)
    elif request.method == 'DELETE':
        if vg:
            vg.release()
        return DEFAULT_RETURN_VALUE