Revision e6680c60 snf-cyclades-app/synnefo/neutron/subnet_views.py

b/snf-cyclades-app/synnefo/neutron/subnet_views.py
42 42
from models import Subnet, Network
43 43
from synnefo.logic import networks
44 44

  
45
from ipaddr import IPv4Network, IPv6Network
45
from ipaddr import IPv4Network, IPv6Network, IPv4Address
46 46

  
47 47
log = getLogger(__name__)
48 48

  
......
95 95
    except KeyError:
96 96
        raise api.faults.BadRequest("Malformed request")
97 97

  
98
    try:
99
        network = Network.objects.get(id=network_id)
100
    except Network.DoesNotExist:
101
        raise api.faults.ItemNotFound("No networks found with that id")
102

  
103 98
    if user_id != network.userid:
104 99
        raise api.faults.Unauthorized("Unauthorized operation")
105 100

  
......
107 102
    if ipversion not in [4, 6]:
108 103
        raise api.faults.BadRequest("Malformed IP version type")
109 104

  
110
    dhcp = check_dhcp_value(subnet.get('enable_dhcp', True))
111
    name = check_name_length(subnet.get('name', None))
112

  
113 105
    # Returns the first available IP in the subnet
114 106
    if ipversion == 6:
115 107
        potential_gateway = str(IPv6Network(cidr).network + 1)
......
125 117
    else:
126 118
        networks.validate_network_params(cidr, gateway)
127 119

  
120
    try:
121
        allocation_pools = subnet['allocation_pools']
122
    except KeyError:
123
        pass
124

  
125
    if allocation_pools:
126
        for pool in allocation_pools:
127
            start = pool['start']
128
            end = pool['end']
129
            networks.validate_network_params(cidr, start)
130
            networks.validate_network_params(cidr, end)
131
            start = IPv4Address(start)
132
            end = IPv4Address(end)
133
            if start >= end:
134
                raise api.faults.BadRequest("Invalid IP pool range")
135
    else:
136
        start =
137

  
138
    dhcp = check_dhcp_value(subnet.get('enable_dhcp', True))
139
    name = check_name_length(subnet.get('name', None))
140

  
128 141
    check_for_hosts_dns(subnet)
129 142

  
143
    try:
144
        network = Network.objects.get(id=network_id)
145
    except Network.DoesNotExist:
146
        raise api.faults.ItemNotFound("No networks found with that id")
147

  
130 148
    # FIX ME
131 149
    try:
132 150
        sub = Subnet.objects.create(name=name, network=network, cidr=cidr,
......
188 206
                                    "updated")
189 207
    if subnet.get('allocation_pools', None):
190 208
        raise api.faults.BadRequest("Malformed request, allocation pools "
191
                                    "cannot be updated")
209
                                   "cannot be updated")
192 210

  
193 211
    check_for_hosts_dns(subnet)
194 212
    name = subnet.get('name', original_dict['name'])

Also available in: Unified diff