Exemple #1
0
def info(gandi, resource, ip):
    """Display information about a vlan."""
    output_keys = ['name', 'state', 'dc', 'subnet', 'gateway']

    datacenters = gandi.datacenter.list()

    vlan = gandi.vlan.info(resource)

    gateway = vlan['gateway']
    if not ip:
        output_vlan(gandi, vlan, datacenters, output_keys, justify=11)
        return vlan

    gateway_exists = False

    vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list()])
    ifaces = gandi.vlan.ifaces(resource)

    for iface in ifaces:
        for ip in iface['ips']:
            if gateway == ip['ip']:
                gateway_exists = True

    if gateway_exists:
        vlan.pop('gateway')
    else:
        vlan['gateway'] = ("%s don't exists" % gateway if gateway
                           else 'none')

    output_vlan(gandi, vlan, datacenters, output_keys, justify=11)

    output_keys = ['vm', 'bandwidth']
    for iface in ifaces:
        gandi.separator_line()
        output_iface(gandi, iface, datacenters, vms, output_keys,
                     justify=11)
        for ip in iface['ips']:
            output_ip(gandi, ip, None, None, None, ['ip'])
            if gateway == ip['ip']:
                output_line(gandi, 'gateway', 'true', justify=11)

    return vlan
Exemple #2
0
def info(gandi, resource, ip):
    """Display information about a vlan."""
    output_keys = ['name', 'state', 'dc', 'subnet', 'gateway']

    datacenters = gandi.datacenter.list()

    vlan = gandi.vlan.info(resource)

    gateway = vlan['gateway']
    if not ip:
        output_vlan(gandi, vlan, datacenters, output_keys, justify=11)
        return vlan

    gateway_exists = False

    vms = dict([(vm_['id'], vm_) for vm_ in gandi.iaas.list()])
    ifaces = gandi.vlan.ifaces(resource)

    for iface in ifaces:
        for ip in iface['ips']:
            if gateway == ip['ip']:
                gateway_exists = True

    if gateway_exists:
        vlan.pop('gateway')
    else:
        vlan['gateway'] = ("%s don't exists" % gateway if gateway
                           else 'none')

    output_vlan(gandi, vlan, datacenters, output_keys, justify=11)

    output_keys = ['vm', 'bandwidth']
    for iface in ifaces:
        gandi.separator_line()
        output_iface(gandi, iface, datacenters, vms, output_keys,
                     justify=11)
        for ip in iface['ips']:
            output_ip(gandi, ip, None, None, None, ['ip'])
            if gateway == ip['ip']:
                output_line(gandi, 'gateway', 'true', justify=11)

    return vlan