Revision ab6d1a2f snf-cyclades-app/synnefo/api/management/commands/network-list.py

b/snf-cyclades-app/synnefo/api/management/commands/network-list.py
52 52
            dest='public',
53 53
            default=False,
54 54
            help="List only public networks"),
55
        make_option(
56
            '--ipv6',
57
            action='store_true',
58
            dest='ipv6',
59
            default=False,
60
            help="Include IPv6 information"),
61 55
    )
62 56

  
63 57
    object_class = Network
......
66 60
    astakos_url = ASTAKOS_BASE_URL
67 61
    astakos_token = ASTAKOS_TOKEN
68 62

  
63
    def get_subnets(network):
64

  
65
        def help_str((a, b)):
66
            return (str(a), b)
67
        lista = network.subnets.values_list("id", "cidr")
68
        lista = map(help_str, lista)
69
        lista = map(" ".join, lista)
70
        return " ".join(lista)
71

  
69 72
    def get_machines(network):
70 73
        return network.machines.filter(deleted=False).count()
71 74

  
......
79 82
        "public": ("public", "Whether network is public or private"),
80 83
        "flavor": ("flavor", "The network's flavor"),
81 84
        "state": ("state", "The network's state"),
82
        "dhcp": ("dhcp", "Whether network uses nfdhcpd or not"),
83
        "subnet.ipv4": ("subnet", "The IPv4 subnet of the network"),
84
        "gateway.ipv4": ("gateway", "The IPv4 gateway of the network"),
85
        "subnet.ipv6": ("subnet6", "The IPv6 subnet of the network"),
86
        "gateway.ipv6": ("gateway6", "The IPv6 gateway of the network"),
87 85
        "created": ("created", "The date the network was created"),
88 86
        "updated": ("updated", "The date the network was updated"),
89 87
        "deleted": ("deleted", "Whether the network is deleted or not"),
......
94 92
        "vms": (get_machines, "Number of connected servers"),
95 93
        "backends": (get_backends, "IDs of Ganeti backends that the network is"
96 94
                                   " connected to"),
95
        "subnets": (get_subnets, "IDs of subnets that the network is"
96
                                   " associated with"),
97 97
        "pool": ("floating_ip_pool", "Whether the network is a floating"
98 98
                                     " IP pool"),
99 99
    }
100 100

  
101
    fields = ["id", "name", "user.uuid", "state", "public", "subnet.ipv4",
102
              "gateway.ipv4", "link", "mac_prefix", "dhcp", "drained", "pool"]
101
    fields = ["id", "name", "user.uuid", "state", "public", "link",
102
              "mac_prefix", "drained", "pool", "subnets"]
103 103

  
104 104
    def handle_args(self, *args, **options):
105 105
        if options["public"]:
106 106
            self.filters["public"] = True
107
        if options["ipv6"]:
108
            self.fields.extend(["subnet.ipv6", "gateway.ipv6"])

Also available in: Unified diff