Revision 55480205

b/snf-cyclades-app/synnefo/api/management/commands/subnet-create.py
37 37
from synnefo.management import common
38 38
from snf_django.management.utils import parse_bool
39 39
from synnefo.management import pprint
40

  
41 40
from synnefo.logic import subnets
42 41

  
42
import ipaddr
43

  
43 44
HELP_MSG = """
44 45

  
45 46
Create a new subnet without authenticating the user. The limit of one
......
58 59
        make_option("--cidr", dest="cidr",
59 60
                    help="The CIDR of the subnet, e.g., 192.168.42.0/24"),
60 61
        make_option("--allocation-pools", dest="allocation_pools",
62
                    action="append",
61 63
                    help="IP allocation pools to be used for assigning IPs to"
62
                    " VMs. Syntax: \n"
63
                    "'[[192.168.42.100,192.168.42.200],"
64
                    "[192.168.42.220,129.168.42.240]]'"),
64
                    " VMs. Can be used multiple times. Syntax: \n"
65
                    "192.168.42.220,192.168.42.240. Starting IP must proceed "
66
                    "ending IP."),
65 67
        make_option("--name", dest="name",
66 68
                    help="An arbitrary string for naming the subnet."),
67 69
        make_option("--ip-version", dest="ipversion", choices=["4", "6"],
......
108 110
        dns = options["dns"]
109 111
        host_routes = options["host_routes"]
110 112

  
113
        #Parsing allocation pools
114
        alloc = list()
115
        for pool in allocation_pools:
116
            try:
117
                start, end = pool.split(',')
118
                alloc.append([ipaddr.IPv4Address(start),
119
                              ipaddr.IPv4Address(end)])
120
            except ValueError:
121
                raise CommandError("Malformed IPv4 address")
122

  
111 123
        sub = subnets.create_subnet(name=name,
112 124
                                    network_id=network_id,
113 125
                                    cidr=cidr,
114
                                    allocation_pools=allocation_pools,
126
                                    allocation_pools=sorted(alloc),
115 127
                                    gateway=gateway,
116 128
                                    ipversion=ipversion,
117 129
                                    dhcp=dhcp,

Also available in: Unified diff