Revision 0d1f9117

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
b/snf-cyclades-app/synnefo/api/management/commands/subnet-create.py
110 110
        dns = options["dns"]
111 111
        host_routes = options["host_routes"]
112 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")
113
        alloc = subnets.parse_allocation_pools(allocation_pools)
122 114

  
123 115
        sub = subnets.create_subnet(name=name,
124 116
                                    network_id=network_id,
b/snf-cyclades-app/synnefo/logic/subnets.py
283 283
                raise faults.BadRequest("Invalid network IPv6 gateway")
284 284
            if not gateway6 in network6:
285 285
                raise faults.BadRequest("Invalid network IPv6 gateway")
286

  
287

  
288
def parse_allocation_pools(allocation_pools):
289
    alloc = list()
290
    for pool in allocation_pools:
291
        try:
292
            start, end = pool.split(',')
293
            alloc.append([ipaddr.IPv4Address(start),
294
                          ipaddr.IPv4Address(end)])
295
        except ValueError:
296
            raise CommandError("Malformed IPv4 address")
297

  
298
    return alloc

Also available in: Unified diff