from osm_nbi.authconn import AuthconnNotFoundException, AuthconnConflictException
from osm_common.dbbase import deep_update_rfc7396
import copy
+from osm_nbi.temporal.nbi_temporal import NbiTemporal
__author__ = "Alfonso Tierno <alfonso.tiernosepulveda@telefonica.com>"
return final_content
+ def _validate_input_edit(self, input, content, force=False):
+ """
+ Validates input user content for an edition. It uses jsonschema. Some overrides will use pyangbind
+ :param input: user input content for the new topic
+ :param force: may be used for being more tolerant
+ :return: The same input content, or a changed version of it.
+ """
+
+ if "vim_type" in content:
+ input["vim_type"] = content["vim_type"]
+ return super()._validate_input_edit(input, content, force)
+
def format_on_edit(self, final_content, edit_content):
"""
Modifies final_content inserting admin information upon edition
if session["force"]:
self.db.del_one(self.topic, {"_id": _id})
op_id = None
+ message = {"_id": _id, "op_id": op_id}
+ # The vim_type is a temporary hack to shim in temporal workflows in the create
+ if "vim_type" in db_content:
+ message["vim_type"] = db_content["vim_type"]
+
self._send_msg(
- "deleted", {"_id": _id, "op_id": op_id}, not_send_msg=not_send_msg
+ "deleted",
+ message,
+ not_send_msg=not_send_msg,
)
else:
update_dict = {"_admin.to_delete": True}
op_id = "{}:{}".format(
db_content["_id"], len(db_content["_admin"]["operations"])
)
+ message = {"_id": _id, "op_id": op_id}
+ # The vim_type is a temporary hack to shim in temporal workflows in the create
+ if "vim_type" in db_content:
+ message["vim_type"] = db_content["vim_type"]
+
self._send_msg(
- "delete", {"_id": _id, "op_id": op_id}, not_send_msg=not_send_msg
+ "delete",
+ message,
+ not_send_msg=not_send_msg,
)
return op_id
),
}
valid_paas_providers = ["juju"]
+ temporal = NbiTemporal()
def check_conflict_on_new(self, session, indata):
super().check_conflict_on_new(session, indata)
return indata.get("vim_type") and indata["vim_type"] == "paas"
def _check_paas_account(self, indata):
- if self._is_paas_vim_type(indata):
- self._check_paas_provider_is_valid(indata)
+ if not self._is_paas_vim_type(indata):
+ return
+ if not self._is_valid_paas_config(indata.get("config")):
+ raise EngineException(
+ "Invalid config for VIM account '{}'.".format(indata["name"]),
+ HTTPStatus.UNPROCESSABLE_ENTITY,
+ )
- def _check_paas_provider_is_valid(self, indata):
- try:
- paas_provider = indata["config"]["paas_provider"]
- if paas_provider in self.valid_paas_providers:
- return
- except Exception:
- pass
- raise EngineException(
- "Invalid paas_provider for VIM account '{}'.".format(indata["name"]),
- HTTPStatus.UNPROCESSABLE_ENTITY,
- )
+ def _is_valid_paas_config(self, config) -> bool:
+ if not config:
+ return False
+ paas_provider = config.get("paas_provider")
+ is_valid_paas_provider = paas_provider in self.valid_paas_providers
+ if paas_provider == "juju":
+ return self._is_valid_juju_paas_config(config)
+ return is_valid_paas_provider
+
+ def _is_valid_juju_paas_config(self, config) -> bool:
+ if not config:
+ return False
+ config_keys = [
+ "paas_provider",
+ "ca_cert_content",
+ "cloud",
+ "cloud_credentials",
+ "authorized_keys",
+ ]
+ return all(key in config for key in config_keys)
def check_conflict_on_del(self, session, _id, db_content):
"""
def _send_msg(self, action, content, not_send_msg=None):
if self._is_paas_vim_type(content):
+ self.temporal.start_vim_workflow(action, content)
return
+
super()._send_msg(action, content, not_send_msg)