276 |
276 |
except (KeyError, AssertionError):
|
277 |
277 |
raise faults.BadRequest("Malformed request")
|
278 |
278 |
|
279 |
|
if len(personality) > settings.MAX_PERSONALITY:
|
280 |
|
raise faults.OverLimit("Maximum number of personalities exceeded")
|
281 |
|
|
282 |
|
for p in personality:
|
283 |
|
# Verify that personalities are well-formed
|
284 |
|
try:
|
285 |
|
assert isinstance(p, dict)
|
286 |
|
keys = set(p.keys())
|
287 |
|
allowed = set(['contents', 'group', 'mode', 'owner', 'path'])
|
288 |
|
assert keys.issubset(allowed)
|
289 |
|
contents = p['contents']
|
290 |
|
if len(contents) > settings.MAX_PERSONALITY_SIZE:
|
291 |
|
# No need to decode if contents already exceed limit
|
292 |
|
raise faults.OverLimit("Maximum size of personality exceeded")
|
293 |
|
if len(b64decode(contents)) > settings.MAX_PERSONALITY_SIZE:
|
294 |
|
raise faults.OverLimit("Maximum size of personality exceeded")
|
295 |
|
except AssertionError:
|
296 |
|
raise faults.BadRequest("Malformed personality in request")
|
297 |
|
|
298 |
|
image = {}
|
299 |
|
img = util.get_image(image_id, request.user_uniq)
|
300 |
|
properties = img.get('properties', {})
|
301 |
|
image['backend_id'] = img['location']
|
302 |
|
image['format'] = img['disk_format']
|
303 |
|
image['metadata'] = dict((key.upper(), val) \
|
304 |
|
for key, val in properties.items())
|
305 |
|
|
306 |
|
# Ensure that request if for active flavor
|
|
279 |
# Verify that personalities are well-formed
|
|
280 |
util.verify_personalitity(personality)
|
|
281 |
# Get image information
|
|
282 |
image = util.get_image_dict(image_id, user_id)
|
|
283 |
# Get flavor (ensure it is active)
|
307 |
284 |
flavor = util.get_flavor(flavor_id, include_deleted=False)
|
308 |
|
|
|
285 |
# Allocate VM to backend
|
309 |
286 |
backend_allocator = BackendAllocator()
|
310 |
287 |
backend = backend_allocator.allocate(request.user_uniq, flavor)
|
311 |
288 |
|
... | ... | |
318 |
295 |
else:
|
319 |
296 |
transaction.commit()
|
320 |
297 |
|
|
298 |
# Allocate IP from public network
|
321 |
299 |
try:
|
322 |
300 |
(network, address) = util.get_public_ip(backend)
|
323 |
301 |
nic = {'ip': address, 'network': network.backend_id}
|
... | ... | |
327 |
305 |
else:
|
328 |
306 |
transaction.commit()
|
329 |
307 |
|
330 |
|
|
331 |
308 |
try:
|
332 |
309 |
# Issue commission
|
333 |
310 |
serial = quotas.issue_vm_commission(user_id, flavor)
|