Exemplo n.º 1
0
def index():
    """ basic list of all the objects. """
    show, show_filter = request_args()
    records = find_records(show + show_filter)
    print "records: %s" % records
    return render_template("index.html",
                           records=records,
                           show=show
    )
def instance2rtb(instance):
    sn_ids = instance['subnets']
    find_sn = "_type=subnets subnets.in.%s" % sn_ids
    # RouteTable lookup
    find_rtb = "_type=rtb subnetid.in.%s" % sn_ids
    try:
        rtb = find_records(find_rtb)
    except Exception:
        rtb = []
    return rtb
def show_routes(rtb, step=0, target_filter=None):
    for r in rtb:
        r_name = r['routetableid']
        for route in r['routes']:
            (target, destination) = route.split()
            if target_filter:
                if IPAddress(target.split('/')[0]) not in IPNetwork(target_filter):
                    continue
            print ' '*step, route, " rtb:", r['name'], r_name
            if destination.startswith('i-'):
                destination = destination.replace('i-', '')
                instance = find_records("_type=instances instances~%s" % destination)[0]
                local_rtb = instance2rtb(instance)
                show_routes(local_rtb, step+3, target)
Exemplo n.º 4
0
def search(query):
    "Basic search"
    show, show_filter = request_args(query)
    records = find_records(show + show_filter)

    if len(records) == 1:
        record = records[0]
        record_name = record['name']
        return single_record(name=record_name)

    print "len(records): %d" % len(records)
    return render_template("index.html",
                           records=records,
                           query=query,
                           show=show
    )
Exemplo n.º 5
0
def single_record(name):
    full_record = find_records("name=%s" % name)[0]
    return render_template("full_record.html",
                           full_record=sorted(full_record.items())
    )
    for r in rtb:
        r_name = r['routetableid']
        for route in r['routes']:
            (target, destination) = route.split()
            if target_filter:
                if IPAddress(target.split('/')[0]) not in IPNetwork(target_filter):
                    continue
            print ' '*step, route, " rtb:", r['name'], r_name
            if destination.startswith('i-'):
                destination = destination.replace('i-', '')
                instance = find_records("_type=instances instances~%s" % destination)[0]
                local_rtb = instance2rtb(instance)
                show_routes(local_rtb, step+3, target)


for instance in find_records("_type=instances %s" % rk_filter):
    print
    # Security group lookup
    sg_ids = ','.join(instance['securitygroups_ids'])
    find_sg = "_type=securitygroups securitygroups_ids.in.%s" % sg_ids
    sg = find_records(find_sg)

    # subnet lookup
    sn_ids = instance['subnets']
    find_sn = "_type=subnets subnets.in.%s" % sn_ids
    sn = find_records(find_sn)

    # nacl lookup
    find_nacl = "_type=acls subnetid.in.%s" % sn_ids
    nacl = find_records(find_nacl)
        rtb = find_records(find_rtb)
    except Exception:
        rtb = []
    return rtb


def show_routes(rtb, step=0, target_filter=None):
    for r in rtb:
        r_name = r['routetableid']
        for route in r['routes']:
            (target, destination) = route.split()
            if target_filter:
                if IPAddress(target.split('/')[0]) not in IPNetwork(target_filter):
                    continue
            print ' '*step, route, " rtb:", r['name'], r_name
            if destination.startswith('i-'):
                destination = destination.replace('i-', '')
                instance = find_records("_type=instances instances~%s" % destination)[0]
                local_rtb = instance2rtb(instance)
                show_routes(local_rtb, step+3, target)


for instance in find_records("_type=instances %s" % rk_filter):
    print
    rtb = instance2rtb(instance)

    print "instance:", instance['name'], "id:", instance['instances']
    print "=" * 80
    show_routes(rtb)