Revision b7d38981 snf-cyclades-app/synnefo/api/networks.py
b/snf-cyclades-app/synnefo/api/networks.py | ||
---|---|---|
90 | 90 |
d['gateway'] = network.gateway |
91 | 91 |
d['gateway6'] = network.gateway6 |
92 | 92 |
d['dhcp'] = network.dhcp |
93 |
d['type'] = network.type
|
|
93 |
d['type'] = network.flavor
|
|
94 | 94 |
d['updated'] = util.isoformat(network.updated) |
95 | 95 |
d['created'] = util.isoformat(network.created) |
96 | 96 |
d['status'] = network.state |
... | ... | |
169 | 169 |
subnet6 = d.get('cidr6', None) |
170 | 170 |
gateway = d.get('gateway', None) |
171 | 171 |
gateway6 = d.get('gateway6', None) |
172 |
net_type = d.get('type', 'PRIVATE_MAC_FILTERED')
|
|
172 |
flavor = d.get('type', 'MAC_FILTERED')
|
|
173 | 173 |
public = d.get('public', False) |
174 | 174 |
dhcp = d.get('dhcp', True) |
175 | 175 |
except (KeyError, ValueError): |
... | ... | |
178 | 178 |
if public: |
179 | 179 |
raise Forbidden('Can not create a public network.') |
180 | 180 |
|
181 |
if net_type not in ['PUBLIC_ROUTED', 'PRIVATE_MAC_FILTERED', |
|
182 |
'PRIVATE_PHYSICAL_VLAN', 'CUSTOM_ROUTED', |
|
183 |
'CUSTOM_BRIDGED']: |
|
184 |
raise BadRequest("Invalid network type: %s", net_type) |
|
185 |
if net_type not in settings.ENABLED_NETWORKS: |
|
186 |
raise Forbidden("Can not create %s network" % net_type) |
|
181 |
if flavor not in Network.FLAVORS.keys(): |
|
182 |
raise BadRequest("Invalid network flavors %s" % flavor) |
|
183 |
|
|
184 |
if flavor not in settings.API_ENABLED_NETWORK_FLAVORS: |
|
185 |
raise Forbidden("Can not create %s network" % flavor) |
|
187 | 186 |
|
188 | 187 |
cidr_block = int(subnet.split('/')[1]) |
189 | 188 |
if not util.validate_network_size(cidr_block): |
... | ... | |
198 | 197 |
serial.save() |
199 | 198 |
|
200 | 199 |
try: |
201 |
link, mac_prefix = util.net_resources(net_type) |
|
202 |
if not link: |
|
203 |
raise Exception("Can not create network. No connectivity link.") |
|
204 |
|
|
200 |
mode, link, mac_prefix, tags = util.values_from_flavor(flavor) |
|
205 | 201 |
network = Network.objects.create( |
206 | 202 |
name=name, |
207 | 203 |
userid=user_id, |
... | ... | |
210 | 206 |
gateway=gateway, |
211 | 207 |
gateway6=gateway6, |
212 | 208 |
dhcp=dhcp, |
213 |
type=net_type, |
|
209 |
flavor=flavor, |
|
210 |
mode=mode, |
|
214 | 211 |
link=link, |
215 | 212 |
mac_prefix=mac_prefix, |
213 |
tags=tags, |
|
216 | 214 |
action='CREATE', |
217 | 215 |
state='PENDING', |
218 | 216 |
serial=serial) |
219 | 217 |
except EmptyPool: |
220 | 218 |
log.error("Failed to allocate resources for network of type: %s", |
221 |
net_type)
|
|
219 |
flavor)
|
|
222 | 220 |
raise ServiceUnavailable("Failed to allocate resources for network") |
223 | 221 |
|
224 | 222 |
# Create BackendNetwork entries for each Backend |
Also available in: Unified diff