+ self.logger.error("Updating {} _id={}: {}".format(item, _id, e))
+
+ async def create_vim(self, vim_content, order_id):
+ vim_id = vim_content["_id"]
+ logging_text = "Task create_vim={} ".format(vim_id)
+ self.logger.debug(logging_text + "Enter")
+ db_vim = None
+ exc = None
+ try:
+ step = "Getting vim from db"
+ db_vim = self.db.get_one("vims", {"_id": vim_id})
+ if "_admin" not in db_vim:
+ db_vim["_admin"] = {}
+ if "deploy" not in db_vim["_admin"]:
+ db_vim["_admin"]["deploy"] = {}
+ db_vim["_admin"]["deploy"]["RO"] = None
+
+ step = "Creating vim at RO"
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ vim_RO = deepcopy(vim_content)
+ vim_RO.pop("_id", None)
+ vim_RO.pop("_admin", None)
+ vim_RO.pop("schema_version", None)
+ vim_RO.pop("schema_type", None)
+ vim_RO.pop("vim_tenant_name", None)
+ vim_RO["type"] = vim_RO.pop("vim_type")
+ vim_RO.pop("vim_user", None)
+ vim_RO.pop("vim_password", None)
+ desc = await RO.create("vim", descriptor=vim_RO)
+ RO_vim_id = desc["uuid"]
+ db_vim["_admin"]["deploy"]["RO"] = RO_vim_id
+ self.update_db("vims", vim_id, db_vim)
+
+ step = "Attach vim to RO tenant"
+ vim_RO = {"vim_tenant_name": vim_content["vim_tenant_name"],
+ "vim_username": vim_content["vim_user"],
+ "vim_password": vim_content["vim_password"],
+ "config": vim_content["config"]
+ }
+ desc = await RO.attach_datacenter(RO_vim_id , descriptor=vim_RO)
+ db_vim["_admin"]["operationalState"] = "ENABLED"
+ self.update_db("vims", vim_id, db_vim)
+
+ self.logger.debug(logging_text + "Exit Ok RO_vim_id".format(RO_vim_id))
+ return RO_vim_id
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_vim:
+ db_vim["_admin"]["operationalState"] = "ERROR"
+ db_vim["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("vims", vim_id, db_vim)
+
+ async def edit_vim(self, vim_content, order_id):
+ vim_id = vim_content["_id"]
+ logging_text = "Task edit_vim={} ".format(vim_id)
+ self.logger.debug(logging_text + "Enter")
+ db_vim = None
+ exc = None
+ step = "Getting vim from db"
+ try:
+ db_vim = self.db.get_one("vims", {"_id": vim_id})
+ if db_vim.get("_admin") and db_vim["_admin"].get("deploy") and db_vim["_admin"]["deploy"].get("RO"):
+ RO_vim_id = db_vim["_admin"]["deploy"]["RO"]
+ step = "Editing vim at RO"
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ vim_RO = deepcopy(vim_content)
+ vim_RO.pop("_id", None)
+ vim_RO.pop("_admin", None)
+ vim_RO.pop("schema_version", None)
+ vim_RO.pop("schema_type", None)
+ vim_RO.pop("vim_tenant_name", None)
+ vim_RO["type"] = vim_RO.pop("vim_type")
+ vim_RO.pop("vim_user", None)
+ vim_RO.pop("vim_password", None)
+ if vim_RO:
+ desc = await RO.edit("vim", RO_vim_id, descriptor=vim_RO)
+
+ step = "Editing vim-account at RO tenant"
+ vim_RO = {}
+ for k in ("vim_tenant_name", "vim_password", "config"):
+ if k in vim_content:
+ vim_RO[k] = vim_content[k]
+ if "vim_user" in vim_content:
+ vim_content["vim_username"] = vim_content["vim_user"]
+ if vim_RO:
+ desc = await RO.edit("vim_account", RO_vim_id, descriptor=vim_RO)
+ db_vim["_admin"]["operationalState"] = "ENABLED"
+ self.update_db("vims", vim_id, db_vim)
+
+ self.logger.debug(logging_text + "Exit Ok RO_vim_id".format(RO_vim_id))
+ return RO_vim_id
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_vim:
+ db_vim["_admin"]["operationalState"] = "ERROR"
+ db_vim["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("vims", vim_id, db_vim)
+
+ async def delete_vim(self, vim_id, order_id):
+ logging_text = "Task delete_vim={} ".format(vim_id)
+ self.logger.debug(logging_text + "Enter")
+ db_vim = None
+ exc = None
+ step = "Getting vim from db"
+ try:
+ db_vim = self.db.get_one("vims", {"_id": vim_id})
+ if db_vim.get("_admin") and db_vim["_admin"].get("deploy") and db_vim["_admin"]["deploy"].get("RO"):
+ RO_vim_id = db_vim["_admin"]["deploy"]["RO"]
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ step = "Detaching vim from RO tenant"
+ try:
+ await RO.detach_datacenter(RO_vim_id)
+ except ROclient.ROClientException as e:
+ if e.http_code == 404: # not found
+ self.logger.debug(logging_text + "RO_vim_id={} already detached".format(RO_vim_id))
+ else:
+ raise
+
+ step = "Deleting vim from RO"
+ try:
+ await RO.delete("vim", RO_vim_id)
+ except ROclient.ROClientException as e:
+ if e.http_code == 404: # not found
+ self.logger.debug(logging_text + "RO_vim_id={} already deleted".format(RO_vim_id))
+ else:
+ raise
+ else:
+ # nothing to delete
+ self.logger.error(logging_text + "Skipping. There is not RO information at database")
+ self.db.del_one("vims", {"_id": vim_id})
+ self.logger.debug("delete_vim task vim_id={} Exit Ok".format(vim_id))
+ return None
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_vim:
+ db_vim["_admin"]["operationalState"] = "ERROR"
+ db_vim["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("vims", vim_id, db_vim)
+
+ async def create_sdn(self, sdn_content, order_id):
+ sdn_id = sdn_content["_id"]
+ logging_text = "Task create_sdn={} ".format(sdn_id)
+ self.logger.debug(logging_text + "Enter")
+ db_sdn = None
+ exc = None
+ try:
+ step = "Getting sdn from db"
+ db_sdn = self.db.get_one("sdns", {"_id": sdn_id})
+ if "_admin" not in db_sdn:
+ db_sdn["_admin"] = {}
+ if "deploy" not in db_sdn["_admin"]:
+ db_sdn["_admin"]["deploy"] = {}
+ db_sdn["_admin"]["deploy"]["RO"] = None
+
+ step = "Creating sdn at RO"
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ sdn_RO = deepcopy(sdn_content)
+ sdn_RO.pop("_id", None)
+ sdn_RO.pop("_admin", None)
+ sdn_RO.pop("schema_version", None)
+ sdn_RO.pop("schema_type", None)
+ desc = await RO.create("sdn", descriptor=sdn_RO)
+ RO_sdn_id = desc["uuid"]
+ db_sdn["_admin"]["deploy"]["RO"] = RO_sdn_id
+ db_sdn["_admin"]["operationalState"] = "ENABLED"
+ self.update_db("sdns", sdn_id, db_sdn)
+ self.logger.debug(logging_text + "Exit Ok RO_sdn_id".format(RO_sdn_id))
+ return RO_sdn_id
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_sdn:
+ db_sdn["_admin"]["operationalState"] = "ERROR"
+ db_sdn["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("sdns", sdn_id, db_sdn)
+
+ async def edit_sdn(self, sdn_content, order_id):
+ sdn_id = sdn_content["_id"]
+ logging_text = "Task edit_sdn={} ".format(sdn_id)
+ self.logger.debug(logging_text + "Enter")
+ db_sdn = None
+ exc = None
+ step = "Getting sdn from db"
+ try:
+ db_sdn = self.db.get_one("sdns", {"_id": sdn_id})
+ if db_sdn.get("_admin") and db_sdn["_admin"].get("deploy") and db_sdn["_admin"]["deploy"].get("RO"):
+ RO_sdn_id = db_sdn["_admin"]["deploy"]["RO"]
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ step = "Editing sdn at RO"
+ sdn_RO = deepcopy(sdn_content)
+ sdn_RO.pop("_id", None)
+ sdn_RO.pop("_admin", None)
+ sdn_RO.pop("schema_version", None)
+ sdn_RO.pop("schema_type", None)
+ if sdn_RO:
+ desc = await RO.edit("sdn", RO_sdn_id, descriptor=sdn_RO)
+ db_sdn["_admin"]["operationalState"] = "ENABLED"
+ self.update_db("sdns", sdn_id, db_sdn)
+
+ self.logger.debug(logging_text + "Exit Ok RO_sdn_id".format(RO_sdn_id))
+ return RO_sdn_id
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_sdn:
+ db_sdn["_admin"]["operationalState"] = "ERROR"
+ db_sdn["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("sdns", sdn_id, db_sdn)
+
+ async def delete_sdn(self, sdn_id, order_id):
+ logging_text = "Task delete_sdn={} ".format(sdn_id)
+ self.logger.debug(logging_text + "Enter")
+ db_sdn = None
+ exc = None
+ step = "Getting sdn from db"
+ try:
+ db_sdn = self.db.get_one("sdns", {"_id": sdn_id})
+ if db_sdn.get("_admin") and db_sdn["_admin"].get("deploy") and db_sdn["_admin"]["deploy"].get("RO"):
+ RO_sdn_id = db_sdn["_admin"]["deploy"]["RO"]
+ RO = ROclient.ROClient(self.loop, **self.ro_config)
+ step = "Deleting sdn from RO"
+ try:
+ await RO.delete("sdn", RO_sdn_id)
+ except ROclient.ROClientException as e:
+ if e.http_code == 404: # not found
+ self.logger.debug(logging_text + "RO_sdn_id={} already deleted".format(RO_sdn_id))
+ else:
+ raise
+ else:
+ # nothing to delete
+ self.logger.error(logging_text + "Skipping. There is not RO information at database")
+ self.db.del_one("sdns", {"_id": sdn_id})
+ self.logger.debug("delete_sdn task sdn_id={} Exit Ok".format(sdn_id))
+ return None
+
+ except (ROclient.ROClientException, DbException) as e:
+ self.logger.error(logging_text + "Exit Exception {}".format(e))
+ exc = e
+ except Exception as e:
+ self.logger.critical(logging_text + "Exit Exception {}".format(e), exc_info=True)
+ exc = e
+ finally:
+ if exc and db_sdn:
+ db_sdn["_admin"]["operationalState"] = "ERROR"
+ db_sdn["_admin"]["detailed-status"] = "ERROR {}: {}".format(step , exc)
+ self.update_db("sdns", sdn_id, db_sdn)