Revision 2509ce17 snf-cyclades-app/synnefo/api/networks.py
b/snf-cyclades-app/synnefo/api/networks.py | ||
---|---|---|
147 | 147 |
|
148 | 148 |
|
149 | 149 |
@api.api_method(http_method='POST', user_required=True, logger=log) |
150 |
@quotas.uses_commission |
|
151 | 150 |
@transaction.commit_manually |
152 |
def create_network(serials, request):
|
|
151 |
def create_network(request): |
|
153 | 152 |
# Normal Response Code: 202 |
154 | 153 |
# Error Response Codes: computeFault (400, 500), |
155 | 154 |
# serviceUnavailable (503), |
... | ... | |
194 | 193 |
# Check that user provided a valid subnet |
195 | 194 |
util.validate_network_params(subnet, gateway, subnet6, gateway6) |
196 | 195 |
|
197 |
# Issue commission |
|
198 |
serial = quotas.issue_network_commission(user_id) |
|
199 |
serials.append(serial) |
|
200 |
# Make the commission accepted, since in the end of this |
|
201 |
# transaction the Network will have been created in the DB. |
|
202 |
serial.accepted = True |
|
203 |
serial.save() |
|
204 |
|
|
205 | 196 |
try: |
206 | 197 |
mode, link, mac_prefix, tags = util.values_from_flavor(flavor) |
207 | 198 |
network = Network.objects.create( |
... | ... | |
218 | 209 |
mac_prefix=mac_prefix, |
219 | 210 |
tags=tags, |
220 | 211 |
action='CREATE', |
221 |
state='PENDING', |
|
222 |
serial=serial) |
|
212 |
state='PENDING') |
|
223 | 213 |
except EmptyPool: |
224 | 214 |
log.error("Failed to allocate resources for network of type: %s", |
225 | 215 |
flavor) |
... | ... | |
227 | 217 |
|
228 | 218 |
# Create BackendNetwork entries for each Backend |
229 | 219 |
network.create_backend_network() |
220 |
# Issue commission to Quotaholder and accept it since at the end of |
|
221 |
# this transaction the Network object will be created in the DB. |
|
222 |
# Note: the following call does a commit! |
|
223 |
quotas.issue_and_accept_commission(network) |
|
230 | 224 |
except: |
231 | 225 |
transaction.rollback() |
232 | 226 |
raise |
Also available in: Unified diff