View a single pool

def view_pool(arg, opts, shell_opts):
    """ View a single pool
    """

    res = Pool.list({ 'name': arg })

    if len(res) == 0:
        print("No pool with name '%s' found." % arg)
        return

    p = res[0]

    vrf_rt = None
    vrf_name = None
    if p.vrf:
        vrf_rt = p.vrf.rt
        vrf_name = p.vrf.name

    print("-- Pool ")
    print("  %-26s : %d" % ("ID", p.id))
    print("  %-26s : %s" % ("Name", p.name))
    print("  %-26s : %s" % ("Description", p.description))
    print("  %-26s : %s" % ("Default type", p.default_type))
    print("  %-26s : %s / %s" % ("Implied VRF RT / name", vrf_rt, vrf_name))
    print("  %-26s : %s / %s" % ("Preflen (v4/v6)", str(p.ipv4_default_prefix_length), str(p.ipv6_default_prefix_length)))

    print("-- Extra Attributes")
    if p.avps is not None:
        for key in sorted(p.avps, key=lambda s: s.lower()):
            print("  %-26s : %s" % (key, p.avps[key]))

    print("-- Tags")
    for tag_name in sorted(p.tags, key=lambda s: s.lower()):
        print("  %s" % tag_name)

    # statistics
    print("-- Statistics")

    # IPv4 total / used / free prefixes
    if p.member_prefixes_v4 == 0:
        print("  IPv4 prefixes Used / Free  : N/A (No IPv4 member prefixes)")
    elif p.ipv4_default_prefix_length is None:
        print("  IPv4 prefixes Used / Free  : N/A (IPv4 default prefix length is not set)")
    else:
        if p.total_prefixes_v4 == 0:
            used_percent_v4 = 0
        else:
            used_percent_v4 = (float(p.used_prefixes_v4)/p.total_prefixes_v4)*100

        print("  %-26s : %.0f / %.0f (%.2f%% of %.0f)" % ("IPv4 prefixes Used / Free",
                p.used_prefixes_v4, p.free_prefixes_v4, used_percent_v4,
                p.total_prefixes_v4))

    # IPv6 total / used / free prefixes
    if p.member_prefixes_v6 == 0:
        print("  IPv6 prefixes Used / Free  : N/A (No IPv6 member prefixes)")
    elif p.ipv6_default_prefix_length is None:
        print("  IPv6 prefixes Used / Free  : N/A (IPv6 default prefix length is not set)")
    else:
        if p.total_prefixes_v6 == 0:
            used_percent_v6 = 0
        else:
            used_percent_v6 = (float(p.used_prefixes_v6)/p.total_prefixes_v6)*100
        print("  %-26s : %.4e / %.4e (%.2f%% of %.4e)" % ("IPv6 prefixes Used / Free",
                p.used_prefixes_v6, p.free_prefixes_v6, used_percent_v6,
                p.total_prefixes_v6))


    # IPv4 total / used / free addresses
    if p.member_prefixes_v4 == 0:
        print("  IPv4 addresses Used / Free  : N/A (No IPv4 member prefixes)")
    elif p.ipv4_default_prefix_length is None:
        print("  IPv4 addresses Used / Free  : N/A (IPv4 default prefix length is not set)")
    else:
        if p.total_addresses_v4 == 0:
            used_percent_v4 = 0
        else:
            used_percent_v4 = (float(p.used_addresses_v4)/p.total_addresses_v4)*100

        print("  %-26s : %.0f / %.0f (%.2f%% of %.0f)" % ("IPv4 addresses Used / Free",
                p.used_addresses_v4, p.free_addresses_v4, used_percent_v4,
                p.total_addresses_v4))

    # IPv6 total / used / free addresses
    if p.member_prefixes_v6 == 0:
        print("  IPv6 addresses Used / Free  : N/A (No IPv6 member prefixes)")
    elif p.ipv6_default_prefix_length is None:
        print("  IPv6 addresses Used / Free  : N/A (IPv6 default prefix length is not set)")
    else:
        if p.total_addresses_v6 == 0:
            used_percent_v6 = 0
        else:
            used_percent_v6 = (float(p.used_addresses_v6)/p.total_addresses_v6)*100
        print("  %-26s : %.4e / %.4e (%.2f%% of %.4e)" % ("IPv6 addresses Used / Free",
                p.used_addresses_v6, p.free_addresses_v6, used_percent_v6,
                p.total_addresses_v6))

    print("\n-- Prefixes in pool - v4: %d  v6: %d" % (p.member_prefixes_v4,
            p.member_prefixes_v6))

    res = Prefix.list({ 'pool_id': p.id})
    for pref in res:
        print("  %s" % pref.display_prefix)