From a908da441bf6efcdb289a46d0c2761840138b1a5 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 8 Jun 2021 11:15:56 -0400 Subject: Draft for cloud-init file generation Signed-off-by: Sawyer Bergeron Signed-off-by: Sawyer Bergeron Change-Id: I07f3a4a1ab67531cba2cc7e3de22e9bb860706e1 Signed-off-by: Sawyer Bergeron --- src/dashboard/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/dashboard/utils.py') diff --git a/src/dashboard/utils.py b/src/dashboard/utils.py index d6b697a..e9ecb4e 100644 --- a/src/dashboard/utils.py +++ b/src/dashboard/utils.py @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import (ObjectDoesNotExist, MultipleObjectsReturned) class AbstractModelQuery(): @@ -38,7 +38,15 @@ class AbstractModelQuery(): @classmethod def get(cls, *args, **kwargs): + """ + Gets a single matching resource + Throws ObjectDoesNotExist if none found matching, or MultipleObjectsReturned if + the query does not narrow to a single object + """ try: + ls = cls.filter(*args, **kwargs) + if len(ls) > 1: + raise MultipleObjectsReturned() return cls.filter(*args, **kwargs)[0] except IndexError: raise ObjectDoesNotExist() -- cgit 1.2.3-korg