Revision a31ff6cb api/handlers.py
b/api/handlers.py | ||
---|---|---|
8 | 8 |
from synnefo.api.faults import fault, noContent, accepted, created |
9 | 9 |
from synnefo.api.helpers import instance_to_server, paginator |
10 | 10 |
from synnefo.util.rapi import GanetiRapiClient, GanetiApiError |
11 |
from synnefo.db.models import VirtualMachine, Flavor, Image, User, id_from_instance_name
|
|
11 |
from synnefo.db.models import *
|
|
12 | 12 |
from util.rapi import GanetiRapiClient |
13 | 13 |
|
14 | 14 |
|
... | ... | |
283 | 283 |
return noContent |
284 | 284 |
|
285 | 285 |
|
286 |
class VirtualMachineGroupHandler(BaseHandler): |
|
287 |
allowed_methods = ('GET', 'POST', 'DELETE') |
|
288 |
|
|
289 |
def read(self, request, id=None): |
|
290 |
"""List Groups""" |
|
291 |
vmgroups = VirtualMachineGroup.objects.all() |
|
292 |
vmgroups = [ {'id': vmgroup.id, \ |
|
293 |
'name': vmgroup.name, \ |
|
294 |
'server_id': [machine.id for machine in vmgroup.machines.all()] \ |
|
295 |
} for vmgroup in vmgroups] |
|
296 |
if rapi: # Group info is stored in the DB. Ganeti is not aware of this |
|
297 |
if id == "detail": |
|
298 |
return { "groups": vmgroups } |
|
299 |
elif id is None: |
|
300 |
return { "groups": [ { "id": s['id'], "name": s['name'] } for s in vmgroups ] } |
|
301 |
else: |
|
302 |
return { "groups": vmgroups[0] } |
|
303 |
|
|
304 |
|
|
305 |
def create(self, request, id): |
|
306 |
"""Creates a Group""" |
|
307 |
return created |
|
308 |
|
|
309 |
def delete(self, request, id): |
|
310 |
"""Deletes a Group""" |
|
311 |
return noContent |
|
312 |
|
|
313 |
|
|
314 |
|
|
286 | 315 |
class LimitHandler(BaseHandler): |
287 | 316 |
allowed_methods = ('GET',) |
288 | 317 |
|
Also available in: Unified diff