-
-class ScalingRpcHandler(mano_dts.DtsHandler):
- """ The Network service Monitor DTS handler """
- SCALE_IN_INPUT_XPATH = "I,/nsr:exec-scale-in"
- SCALE_IN_OUTPUT_XPATH = "O,/nsr:exec-scale-in"
-
- SCALE_OUT_INPUT_XPATH = "I,/nsr:exec-scale-out"
- SCALE_OUT_OUTPUT_XPATH = "O,/nsr:exec-scale-out"
-
- ACTION = Enum('ACTION', 'SCALE_IN SCALE_OUT')
-
- def __init__(self, log, dts, loop, callback=None):
- super().__init__(log, dts, loop)
- self.callback = callback
- self.last_instance_id = defaultdict(int)
-
- @asyncio.coroutine
- def register(self):
-
- @asyncio.coroutine
- def on_scale_in_prepare(xact_info, action, ks_path, msg):
- assert action == rwdts.QueryAction.RPC
-
- try:
- if self.callback:
- self.callback(xact_info.xact, msg, self.ACTION.SCALE_IN)
-
- rpc_op = NsrYang.YangOutput_Nsr_ExecScaleIn.from_dict({
- "instance_id": msg.instance_id})
-
- xact_info.respond_xpath(
- rwdts.XactRspCode.ACK,
- self.__class__.SCALE_IN_OUTPUT_XPATH,
- rpc_op)
-
- except Exception as e:
- self.log.exception(e)
- xact_info.respond_xpath(
- rwdts.XactRspCode.NACK,
- self.__class__.SCALE_IN_OUTPUT_XPATH)
-
- @asyncio.coroutine
- def on_scale_out_prepare(xact_info, action, ks_path, msg):
- assert action == rwdts.QueryAction.RPC
-
- try:
- scaling_group = msg.scaling_group_name_ref
- if not msg.instance_id:
- last_instance_id = self.last_instance_id[scale_group]
- msg.instance_id = last_instance_id + 1
- self.last_instance_id[scale_group] += 1
-
- if self.callback:
- self.callback(xact_info.xact, msg, self.ACTION.SCALE_OUT)
-
- rpc_op = NsrYang.YangOutput_Nsr_ExecScaleOut.from_dict({
- "instance_id": msg.instance_id})
-
- xact_info.respond_xpath(
- rwdts.XactRspCode.ACK,
- self.__class__.SCALE_OUT_OUTPUT_XPATH,
- rpc_op)
-
- except Exception as e:
- self.log.exception(e)
- xact_info.respond_xpath(
- rwdts.XactRspCode.NACK,
- self.__class__.SCALE_OUT_OUTPUT_XPATH)
-
- scale_in_hdl = rift.tasklets.DTS.RegistrationHandler(
- on_prepare=on_scale_in_prepare)
- scale_out_hdl = rift.tasklets.DTS.RegistrationHandler(
- on_prepare=on_scale_out_prepare)
-
- with self.dts.group_create() as group:
- group.register(
- xpath=self.__class__.SCALE_IN_INPUT_XPATH,
- handler=scale_in_hdl,
- flags=rwdts.Flag.PUBLISHER)
- group.register(
- xpath=self.__class__.SCALE_OUT_INPUT_XPATH,
- handler=scale_out_hdl,
- flags=rwdts.Flag.PUBLISHER)
-
-