Commit 62c0e08e authored by Milosz Wasilewski's avatar Milosz Wasilewski Committed by stevanradakovic
Browse files

scheduler/api: fix XML-RPC API for Aliases

Signed-off-by: default avatarMilosz Wasilewski <>
parent ec74e9ed
......@@ -23,12 +23,12 @@ from django.forms import ValidationError
from linaro_django_xmlrpc.models import ExposedV2API
from lava_scheduler_app.api import check_perm
from lava_scheduler_app.models import Alias
from lava_scheduler_app.models import Alias, DeviceType
class SchedulerAliasesAPI(ExposedV2API):
def add(self, name):
def add(self, name, device_type_name):
......@@ -43,17 +43,26 @@ class SchedulerAliasesAPI(ExposedV2API):
`name`: string
Name of the alias
'device_type_name': string
Name of the device type to alias
Return value
alias = Alias(name=name)
dt = DeviceType.objects.get(name=device_type_name)
if not dt.some_devices_visible_to(self.user):
raise xmlrpc.client.Fault(
404, "Device-type '%s' was not found." % device_type_name
alias = Alias(name=name, device_type=dt)
except ValidationError as e:
raise xmlrpc.client.Fault(404, e.message)
except DeviceType.DoesNotExist as nf:
raise xmlrpc.client.Fault(400, "Bad request. DeviceType does not exist")
except IntegrityError:
raise xmlrpc.client.Fault(
400, "Bad request. Alias or DeviceType name already exists."
......@@ -132,10 +141,9 @@ class SchedulerAliasesAPI(ExposedV2API):
except Alias.DoesNotExist:
raise xmlrpc.client.Fault(404, "Alias '%s' was not found." % name)
device_types = []
for dt in alias.device_types.all():
if dt.owners_only and dt.some_devices_visible_to(self.user):
if alias.device_type.owners_only and alias.device_type.some_devices_visible_to(
return {"name":, "device_type": ""}
return {"name":, "device_types": device_types}
return {"name":, "device_type":}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment