Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / volume / util.py @ 0a83201b

History | View | Annotate | Download (1.2 kB)

1 79a1e9bd Christos Stavrakakis
from synnefo.db import models
2 79a1e9bd Christos Stavrakakis
from snf_django.lib.api import faults
3 79a1e9bd Christos Stavrakakis
from synnefo.api.util import get_image_dict, get_vm
4 79a1e9bd Christos Stavrakakis
5 79a1e9bd Christos Stavrakakis
6 79a1e9bd Christos Stavrakakis
def get_volume(user_id, volume_id, for_update=False,
7 79a1e9bd Christos Stavrakakis
               exception=faults.ItemNotFound):
8 79a1e9bd Christos Stavrakakis
    volumes = models.Volume.objects
9 79a1e9bd Christos Stavrakakis
    if for_update:
10 79a1e9bd Christos Stavrakakis
        volumes = volumes.select_for_update()
11 79a1e9bd Christos Stavrakakis
    try:
12 79a1e9bd Christos Stavrakakis
        return volumes.get(id=volume_id, userid=user_id)
13 79a1e9bd Christos Stavrakakis
    except models.Volume.DoesNotExist:
14 79a1e9bd Christos Stavrakakis
        raise exception("Volume %s not found" % volume_id)
15 79a1e9bd Christos Stavrakakis
16 79a1e9bd Christos Stavrakakis
17 79a1e9bd Christos Stavrakakis
def get_snapshot(user_id, snapshot_id, exception=faults.ItemNotFound):
18 79a1e9bd Christos Stavrakakis
    try:
19 79a1e9bd Christos Stavrakakis
        return get_image_dict(snapshot_id, user_id)
20 79a1e9bd Christos Stavrakakis
    except faults.ItemNotFound:
21 79a1e9bd Christos Stavrakakis
        raise exception("Snapshot %s not found" % snapshot_id)
22 79a1e9bd Christos Stavrakakis
23 79a1e9bd Christos Stavrakakis
24 79a1e9bd Christos Stavrakakis
def get_image(user_id, image_id, exception=faults.ItemNotFound):
25 79a1e9bd Christos Stavrakakis
    try:
26 79a1e9bd Christos Stavrakakis
        return get_image_dict(image_id, user_id)
27 79a1e9bd Christos Stavrakakis
    except faults.ItemNotFound:
28 79a1e9bd Christos Stavrakakis
        raise exception("Image %s not found" % image_id)
29 79a1e9bd Christos Stavrakakis
30 79a1e9bd Christos Stavrakakis
31 79a1e9bd Christos Stavrakakis
def get_server(user_id, server_id, for_update=False,
32 79a1e9bd Christos Stavrakakis
               exception=faults.ItemNotFound):
33 79a1e9bd Christos Stavrakakis
    try:
34 79a1e9bd Christos Stavrakakis
        return get_vm(server_id, user_id, for_update=for_update,
35 79a1e9bd Christos Stavrakakis
                      non_deleted=True, non_suspended=True)
36 79a1e9bd Christos Stavrakakis
    except faults.ItemNotFound:
37 79a1e9bd Christos Stavrakakis
        raise exception("Server %s not found" % server_id)