Revision b7311f3d snf-cyclades-app/synnefo/api/management/commands/subnet-create.py

b/snf-cyclades-app/synnefo/api/management/commands/subnet-create.py
35 35

  
36 36
from django.core.management.base import BaseCommand, CommandError
37 37
from synnefo.management import common
38
from snf_django.management.utils import parse_bool
38 39

  
39 40
from synnefo.logic import subnets
40 41

  
......
52 53
    option_list = BaseCommand.option_list + (
53 54
        make_option("--network-id", dest="network_id",
54 55
                    help="Specify the Network to attach the subnet. To get the"
55
                         " networks of a user, use snf-manage network-list"
56
                         " --user ID."),
56
                         " networks of a user, use snf-manage network-list"),
57 57
        make_option("--cidr", dest="cidr",
58 58
                    help="The CIDR of the subnet, e.g., 192.168.42.0/24"),
59 59
        make_option("--allocation-pools", dest="allocation_pools",
......
63 63
                    "[192.168.42.220,129.168.42.240]]'"),
64 64
        make_option("--name", dest="name",
65 65
                    help="An arbitrary string for naming the subnet."),
66
        make_option("--ip-version", dest="ipversion",
67
                    help="IP version of the CIDR. The only acceptable value"
68
                    " is 4 or 6. The value must also be in sync with the"
69
                    " CIDR. Default value: 4"),
66
        make_option("--ip-version", dest="ipversion", choices=["4", "6"],
67
                    metavar="4|6",
68
                    help="IP version of the CIDR. The value must be in sync"
69
                    " with the CIDR. Default value: 4"),
70 70
        make_option("--gateway", dest="gateway",
71 71
                    help="An IP to use as a gateway for the subnet."
72 72
                    " The IP must be inside the CIDR range and cannot be the"
73
                    " subnet or broadcast IP. If no value is specified, the"
74
                    " first available IP of the subnet will be used."),
75
        make_option("--no-dhcp", action="store_true", dest="dhcp",
76
                    default=False,
77
                    help="True/False value for DHCP/SLAAC. True by default."),
73
                    " subnet or broadcast IP. If no value is specified, a"
74
                    " gateway will not be set."),
75
        make_option("--dhcp", dest="dhcp", default="True",
76
                    choices=["True", "False"], metavar="True|False",
77
                    help="Value for DHCP/SLAAC. True by default."),
78 78
        make_option("--dns", dest="dns",
79 79
                    help="DNS nameservers to be used by the VMs in the subnet."
80 80
                    " For the time being, this option isn't supported."),
......
98 98
            raise CommandError("cidr is mandatory")
99 99

  
100 100
        user_id = common.get_network(network_id).userid
101
        name = options["name"]
101
        name = options["name"] or ""
102 102
        allocation_pools = options["allocation_pools"]
103
        ipversion = options["ipversion"]
104
        if not ipversion:
105
            ipversion = 4
106
        else:
107
            try:
108
                ipversion = int(ipversion)
109
            except ValueError:
110
                raise CommandError("ip-version must be 4 or 6")
111

  
103
        ipversion = options["ipversion"] or 4
104
        ipversion = int(ipversion)
112 105
        gateway = options["gateway"]
113
        if not gateway:
114
            gateway = ""
115
        dhcp = options["dhcp"]
116
        dhcp = False if dhcp else True
106
        dhcp = parse_bool(options["dhcp"])
117 107
        dns = options["dns"]
118 108
        host_routes = options["host_routes"]
119 109

  
......
124 114
                              gateway=gateway,
125 115
                              ipversion=ipversion,
126 116
                              dhcp=dhcp,
127
                              slac=dhcp,
117
                              slaac=dhcp,
128 118
                              dns_nameservers=dns,
129 119
                              host_routes=host_routes,
130 120
                              user_id=user_id)

Also available in: Unified diff