- # Override descriptor with query string kwargs
- if kwargs:
- try:
- for k, v in kwargs.items():
- update_content = content
- kitem_old = None
- klist = k.split(".")
- for kitem in klist:
- if kitem_old is not None:
- update_content = update_content[kitem_old]
- if isinstance(update_content, dict):
- kitem_old = kitem
- elif isinstance(update_content, list):
- kitem_old = int(kitem)
- else:
- raise EngineException(
- "Invalid query string '{}'. Descriptor is not a list nor dict at '{}'".format(k, kitem))
- update_content[kitem_old] = v
- except KeyError:
- raise EngineException(
- "Invalid query string '{}'. Descriptor does not contain '{}'".format(k, kitem_old))
- except ValueError:
- raise EngineException("Invalid query string '{}'. Expected integer index list instead of '{}'".format(
- k, kitem))
- except IndexError:
- raise EngineException(
- "Invalid query string '{}'. Index '{}' out of range".format(k, kitem_old))
- if not indata and item not in ("nsds", "vnfds"):
- raise EngineException("Empty payload")
+ try:
+ item_envelop = item
+ if item in ("nsds", "vnfds"):
+ item_envelop = "userDefinedData"
+ content = self._remove_envelop(item_envelop, indata)
+
+ # Override descriptor with query string kwargs
+ self._update_descriptor(content, kwargs)
+ if not indata and item not in ("nsds", "vnfds"):
+ raise EngineException("Empty payload")
+
+ validate_input(content, item, new=True)
+
+ if item == "nsrs":
+ # in this case the imput descriptor is not the data to be stored
+ ns_request = content
+ content = self.new_nsr(session, ns_request)
+
+ self._validate_new_data(session, item_envelop, content)
+ if item in ("nsds", "vnfds"):
+ content = {"_admin": {"userDefinedData": content}}
+ self._format_new_data(session, item, content)
+ _id = self.db.create(item, content)
+ if item == "nsrs":
+ pass
+ # self.msg.write("ns", "created", _id) # sending just for information.
+ elif item == "vim_accounts":
+ msg_data = self.db.get_one(item, {"_id": _id})
+ msg_data.pop("_admin", None)
+ self.msg.write("vim_account", "create", msg_data)
+ elif item == "sdns":
+ msg_data = self.db.get_one(item, {"_id": _id})
+ msg_data.pop("_admin", None)
+ self.msg.write("sdn", "create", msg_data)
+ return _id
+ except ValidationError as e:
+ raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
+
+ def new_nslcmop(self, session, nsInstanceId, action, params):
+ now = time()
+ _id = str(uuid4())
+ nslcmop = {
+ "id": _id,
+ "_id": _id,
+ "operationState": "PROCESSING", # COMPLETED,PARTIALLY_COMPLETED,FAILED_TEMP,FAILED,ROLLING_BACK,ROLLED_BACK
+ "statusEnteredTime": now,
+ "nsInstanceId": nsInstanceId,
+ "lcmOperationType": action,
+ "startTime": now,
+ "isAutomaticInvocation": False,
+ "operationParams": params,
+ "isCancelPending": False,
+ "links": {
+ "self": "/osm/nslcm/v1/ns_lcm_op_occs/" + _id,
+ "nsInstance": "/osm/nslcm/v1/ns_instances/" + nsInstanceId,
+ }
+ }
+ return nslcmop