Revision 0d1f9117 snf-cyclades-app/synnefo/api/management/commands/network-create.py

b/snf-cyclades-app/synnefo/api/management/commands/network-create.py
41 41
from synnefo.logic import networks, subnets
42 42
from synnefo.management import pprint
43 43

  
44
import ipaddr
45

  
44 46
NETWORK_FLAVORS = Network.FLAVORS.keys()
45 47

  
46 48

  
......
126 128
            choices=["True", "False"],
127 129
            metavar="True|False",
128 130
            help="Use the network as a Floating IP pool."),
131
        make_option(
132
            '--allocation-pools',
133
            dest='allocation_pools',
134
            action='append',
135
            help="IP allocation pools to be used for assigning IPs to"
136
                 " VMs. Can be used multiple times. Syntax: \n"
137
                 "192.168.42.220,192.168.42.240. Starting IP must proceed "
138
                 "ending IP."),
129 139
    )
130 140

  
131 141
    @convert_api_faults
......
145 155
        mac_prefix = options['mac_prefix']
146 156
        tags = options['tags']
147 157
        userid = options["owner"]
158
        allocation_pools = options["allocation_pools"]
148 159
        floating_ip_pool = parse_bool(options["floating_ip_pool"])
149 160
        dhcp = parse_bool(options["dhcp"])
150 161

  
......
158 169

  
159 170
        if subnet is None and gateway is not None:
160 171
            raise CommandError("Cannot use gateway without subnet")
172
        if subnet is None and allocation_pools is not None:
173
            raise CommandError("Cannot use allocation-pools without subnet")
161 174
        if subnet6 is None and gateway6 is not None:
162 175
            raise CommandError("Cannot use gateway6 without subnet6")
163 176

  
......
170 183
                                  floating_ip_pool=floating_ip_pool)
171 184

  
172 185
        if subnet is not None:
186
            alloc = subnets.parse_allocation_pools(allocation_pools)
173 187
            name = "IPv4 Subnet of Network %s" % network.id
174 188
            subnets.create_subnet(network.id, cidr=subnet, name=name,
175 189
                                  ipversion=4, gateway=gateway, dhcp=dhcp,
176
                                  user_id=userid)
190
                                  user_id=userid,
191
                                  allocation_pools=sorted(alloc))
177 192

  
178 193
        if subnet6 is not None:
179 194
            name = "IPv6 Subnet of Network %s" % network.id

Also available in: Unified diff