root / snf-cyclades-app / synnefo / volume / util.py @ 79a1e9bd
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 |
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 |
try:
|
19 |
return get_image_dict(snapshot_id, user_id)
|
20 |
except faults.ItemNotFound:
|
21 |
raise exception("Snapshot %s not found" % snapshot_id) |
22 |
|
23 |
|
24 |
def get_image(user_id, image_id, exception=faults.ItemNotFound): |
25 |
try:
|
26 |
return get_image_dict(image_id, user_id)
|
27 |
except faults.ItemNotFound:
|
28 |
raise exception("Image %s not found" % image_id) |
29 |
|
30 |
|
31 |
def get_server(user_id, server_id, for_update=False, |
32 |
exception=faults.ItemNotFound): |
33 |
try:
|
34 |
return get_vm(server_id, user_id, for_update=for_update,
|
35 |
non_deleted=True, non_suspended=True) |
36 |
except faults.ItemNotFound:
|
37 |
raise exception("Server %s not found" % server_id) |