Revision 6f99f94f snf-cyclades-app/synnefo/api/management/commands/subnet-list.py

b/snf-cyclades-app/synnefo/api/management/commands/subnet-list.py
33 33

  
34 34
from optparse import make_option
35 35

  
36
from snf_django.management.commands import ListCommand
36
from snf_django.management.commands import ListCommand, CommandError
37 37
from synnefo.management.common import get_backend
38 38
from synnefo.api.util import get_subnet
39 39
from synnefo.settings import (CYCLADES_SERVICE_TOKEN as ASTAKOS_TOKEN,
40 40
                              ASTAKOS_BASE_URL)
41
from synnefo.db.models import Subnet, Network
42

  
41 43
from logging import getLogger
42 44
log = getLogger(__name__)
43 45

  
......
66 68
            help="List only subnets that have DHCP/SLAC enabled"),
67 69
    )
68 70

  
71
    def get_userid(sub):
72
        return Network.objects.get(id=sub.network.id).userid
73

  
74
    def get_network(net):
75
        return Network.objects.get(id=net.network.id).id
76

  
69 77
    object_class = Subnet
70
    # FIX ME, fix user id
71
    user_uuid_field = "userid"
72 78
    astakos_url = ASTAKOS_BASE_URL
73 79
    astakos_token = ASTAKOS_TOKEN
74 80

  
75 81
    FIELDS = {
76 82
        "id": ("id", "ID of the subnet"),
83
        "network": (get_network, "ID of the network the subnet belongs to"),
77 84
        "name": ("name", "Name of the subnet"),
78
        "user.uuid": ("userid", "The UUID of the subnet's owner"),
85
        "user.uuid": (get_userid, "The UUID of the subnet's owner"),
79 86
        "cidr": ("cidr", "The CIDR of the subnet"),
80 87
        "ipversion": ("ipversion", "The IP version of the subnet"),
81
        "gateway": ("The gateway IP of the subnet"),
82
        "dhcp": ("DHCP flag of the subnet"),
83
        "created": ("created", "The date the server was created"),
88
        "gateway": ("gateway", "The gateway IP of the subnet"),
89
        "dhcp": ("dhcp", "DHCP flag of the subnet"),
84 90
    }
85 91

  
86
    fields = ["id", "name", "user.uuid", "cidr", "ipversion", "gateway",
87
              "dhcp", "created"]
92
    fields = ["id", "network", "name", "user.uuid", "cidr", "ipversion",
93
              "gateway", "dhcp"]
88 94

  
89 95
    def handle_args(self, *args, **options):
90 96
        if options["ipv4"] and options["ipv6"]:
......
96 102
        if options["ipv6"]:
97 103
            self.filters["ipversion"] = 6
98 104

  
99
        if options["build"]:
105
        if options["dhcp"]:
100 106
            self.filters["dhcp"] = True

Also available in: Unified diff