Revision 3165f027 snf-cyclades-app/synnefo/api/networks.py
b/snf-cyclades-app/synnefo/api/networks.py | ||
---|---|---|
46 | 46 |
from synnefo.api.common import method_not_allowed |
47 | 47 |
from synnefo.api.faults import (BadRequest, Unauthorized, |
48 | 48 |
NetworkInUse, OverLimit) |
49 |
from synnefo.db.models import Network |
|
49 |
from synnefo.db.models import Network, Pool |
|
50 |
|
|
50 | 51 |
from synnefo.logic import backend |
51 | 52 |
from synnefo.settings import MAX_CIDR_BLOCK |
52 | 53 |
|
... | ... | |
163 | 164 |
subnet6 = d.get('cidr6', None) |
164 | 165 |
gateway = d.get('gateway', None) |
165 | 166 |
gateway6 = d.get('gateway6', None) |
166 |
type = d.get('type', 'PRIVATE_MAC_FILTERED')
|
|
167 |
typ = d.get('type', 'PRIVATE_MAC_FILTERED') |
|
167 | 168 |
dhcp = d.get('dhcp', True) |
168 | 169 |
except (KeyError, ValueError): |
169 | 170 |
raise BadRequest('Malformed request.') |
170 | 171 |
|
171 |
if type == 'PUBLIC_ROUTED':
|
|
172 |
if typ == 'PUBLIC_ROUTED': |
|
172 | 173 |
raise Unauthorized('Can not create a public network.') |
173 | 174 |
|
174 | 175 |
cidr_block = int(subnet.split('/')[1]) |
... | ... | |
176 | 177 |
raise OverLimit("Network size is to big. Please specify a network" |
177 | 178 |
" smaller than /" + str(MAX_CIDR_BLOCK) + '.') |
178 | 179 |
|
179 |
link, mac_prefix = util.network_specs_from_type(type) |
|
180 |
if not link: |
|
181 |
raise Exception("Can not create network. No connectivity link.") |
|
182 |
|
|
183 |
network = Network.objects.create( |
|
184 |
name=name, |
|
185 |
userid=request.user_uniq, |
|
186 |
subnet=subnet, |
|
187 |
subnet6=subnet6, |
|
188 |
gateway=gateway, |
|
189 |
gateway6=gateway6, |
|
190 |
dhcp=dhcp, |
|
191 |
type=type, |
|
192 |
link=link, |
|
193 |
mac_prefix=mac_prefix, |
|
194 |
state='PENDING') |
|
180 |
try: |
|
181 |
link = util.network_link_from_type(typ) |
|
182 |
if not link: |
|
183 |
raise Exception("Can not create network. No connectivity link.") |
|
184 |
|
|
185 |
network = Network.objects.create( |
|
186 |
name=name, |
|
187 |
userid=request.user_uniq, |
|
188 |
subnet=subnet, |
|
189 |
subnet6=subnet6, |
|
190 |
gateway=gateway, |
|
191 |
gateway6=gateway6, |
|
192 |
dhcp=dhcp, |
|
193 |
type=typ, |
|
194 |
link=link, |
|
195 |
state='PENDING') |
|
196 |
except Pool.PoolExhausted: |
|
197 |
raise OverLimit('Network count limit exceeded.') |
|
195 | 198 |
|
196 | 199 |
backend.create_network(network) |
197 | 200 |
|
Also available in: Unified diff