[CORD-2068] [CORD-2069] [CORD-2070] [CORD-2071] [CORD-2072] [CORD-2073]
Exposing parsing and saving errors
Change-Id: I98ded64a9d5b09a2e69e8f47242be4f775075b00
diff --git a/src/grpc_client/models_accessor.py b/src/grpc_client/models_accessor.py
index 079915a..b51ee90 100644
--- a/src/grpc_client/models_accessor.py
+++ b/src/grpc_client/models_accessor.py
@@ -30,8 +30,11 @@
if data.get('name'):
used_key = 'name'
else:
- # FIXME apparently we're not matching model without a name field
- used_key = data.keys()[0]
+ if len(data.keys()) > 0:
+ # FIXME apparently we're not matching model without a name field
+ used_key = data.keys()[0]
+ else:
+ used_key = None
key = "%s~%s" % (username, password)
if not key in RESOURCES:
@@ -40,7 +43,11 @@
raise Exception('[XOS-TOSCA] The model you are trying to create (%s: %s, class: %s) is not know by xos-core' % (used_key, data[used_key], class_name))
cls = RESOURCES[key][class_name]
- models = cls.objects.filter(**{used_key: data[used_key]})
+ if used_key:
+ models = cls.objects.filter(**{used_key: data[used_key]})
+ else:
+ # NOTE if we don't have a way to track the model, create a new one
+ models = []
if len(models) == 1:
print "[XOS-Tosca] Model %s already exist, retrieving instance..." % data[used_key]
@@ -51,7 +58,8 @@
raise Exception("[XOS-TOSCA] Model %s:%s has property 'must-exist' but cannot be found" % (class_name, data[used_key]))
model = cls.objects.new()
- print "[XOS-Tosca] Model %s is new, creating new instance..." % data[used_key]
+ print "[XOS-Tosca] Model %s is new, creating new instance..." % data[used_key] if used_key else class_name
else:
raise Exception("[XOS-Tosca] Model %s has multiple instances, I can't handle it" % data[used_key])
+
return model
\ No newline at end of file