- self._parent._acctmgr.del_sdn_account(account_name)
-
- def _update_sdn_account(self, account):
- self._log.info("Updating sdn account: {}".format(account))
- # No need to update locally saved sdn_account's updated fields, as they
- # are not used anywhere. Call the parent's update callback.
- self._parent._acctmgr.update_sdn_account(account)
-
- @asyncio.coroutine
- def register(self):
- def apply_config(dts, acg, xact, action, _):
- self._log.debug("Got sdn account apply config (xact: %s) (action: %s)", xact, action)
- if action == rwdts.AppconfAction.INSTALL and xact.id is None:
- self._log.debug("No xact handle. Skipping apply config")
- return RwTypes.RwStatus.SUCCESS
-
- return RwTypes.RwStatus.SUCCESS
-
- @asyncio.coroutine
- def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch):
- """ Prepare callback from DTS for SDN Account config """
-
- self._log.info("SDN Cloud account config received: %s", msg)
-
- fref = ProtobufC.FieldReference.alloc()
- fref.goto_whole_message(msg.to_pbcm())
-
- if fref.is_field_deleted():
- # Delete the sdn account record
- self._del_sdn_account(msg.name)
- else:
- # If the account already exists, then this is an update.
- if msg.name in self._sdn_account:
- self._log.debug("SDN account already exists. Invoking on_prepare update request")
- if msg.has_field("account_type"):
- errmsg = "Cannot update SDN account's account-type."
- self._log.error(errmsg)
- xact_info.send_error_xpath(RwTypes.RwStatus.FAILURE,
- SDNAccountDtsHandler.XPATH,
- errmsg)
- raise SdnAccountError(errmsg)
-
- # Update the sdn account record
- self._update_sdn_account(msg)
- else:
- self._log.debug("SDN account does not already exist. Invoking on_prepare add request")
- if not msg.has_field('account_type'):
- errmsg = "New SDN account must contain account-type field."
- self._log.error(errmsg)
- xact_info.send_error_xpath(RwTypes.RwStatus.FAILURE,
- SDNAccountDtsHandler.XPATH,
- errmsg)
- raise SdnAccountError(errmsg)
-
- # Set the sdn account record
- self._set_sdn_account(msg)
-
- xact_info.respond_xpath(rwdts.XactRspCode.ACK)
-
-
- self._log.debug("Registering for Sdn Account config using xpath: %s",
- SDNAccountDtsHandler.XPATH,
- )
-
- acg_handler = rift.tasklets.AppConfGroup.Handler(
- on_apply=apply_config,
- )
-
- with self._dts.appconf_group_create(acg_handler) as acg:
- acg.register(
- xpath=SDNAccountDtsHandler.XPATH,
- flags=rwdts.Flag.SUBSCRIBER | rwdts.Flag.DELTA_READY,
- on_prepare=on_prepare
- )