root / snf-cyclades-app / synnefo / volume / util.py @ 19b2c29d
History | View | Annotate | Download (1.2 kB)
1 |
from synnefo.db import models |
---|---|
2 |
from snf_django.lib.api import faults |
3 |
from synnefo.api.util import get_image_dict, get_vm, image_backend |
4 |
|
5 |
|
6 |
def get_volume(user_id, volume_id, for_update=False, |
7 |
exception=faults.ItemNotFound): |
8 |
volumes = models.Volume.objects |
9 |
if for_update:
|
10 |
volumes = volumes.select_for_update() |
11 |
try:
|
12 |
return volumes.get(id=volume_id, userid=user_id)
|
13 |
except models.Volume.DoesNotExist:
|
14 |
raise exception("Volume %s not found" % volume_id) |
15 |
|
16 |
|
17 |
def get_snapshot(user_id, snapshot_id, exception=faults.ItemNotFound): |
18 |
with image_backend(user_id) as b: |
19 |
return b.get_snapshot(user_id, snapshot_id)
|
20 |
|
21 |
|
22 |
def get_image(user_id, image_id, exception=faults.ItemNotFound): |
23 |
try:
|
24 |
return get_image_dict(image_id, user_id)
|
25 |
except faults.ItemNotFound:
|
26 |
raise exception("Image %s not found" % image_id) |
27 |
|
28 |
|
29 |
def get_server(user_id, server_id, for_update=False, |
30 |
exception=faults.ItemNotFound): |
31 |
try:
|
32 |
return get_vm(server_id, user_id, for_update=for_update,
|
33 |
non_deleted=True, non_suspended=True) |
34 |
except faults.ItemNotFound:
|
35 |
raise exception("Server %s not found" % server_id) |