leverage LFID authentication to pod creation
[releng.git] / utils / test / testapi / opnfv_testapi / resources / models.py
index e8fc532..e70a6ed 100644 (file)
@@ -48,6 +48,29 @@ class ModelBase(object):
 
         return t
 
+    @classmethod
+    def from_dict_with_raise(cls, a_dict):
+        if a_dict is None:
+            return None
+
+        attr_parser = cls.attr_parser()
+        t = cls()
+        for k, v in a_dict.iteritems():
+            if k not in t.__dict__:
+                raise AttributeError(
+                    '{} has no attribute {}'.format(cls.__name__, k))
+            value = v
+            if isinstance(v, dict) and k in attr_parser:
+                value = attr_parser[k].from_dict_with_raise(v)
+            elif isinstance(v, list) and k in attr_parser:
+                value = []
+                for item in v:
+                    value.append(attr_parser[k].from_dict_with_raise(item))
+
+            t.__setattr__(k, value)
+
+        return t
+
     @staticmethod
     def attr_parser():
         return {}