def start(self): super().start() self.log.info("Starting MonitoringParameterTasklet") self.log.debug("Registering with dts") self.dts = rift.tasklets.DTS(self.tasklet_info, NsrYang.get_schema(), self.loop, self.on_dts_state_change)
def on_prepare(dts, acg, xact, xact_info, ks_path, msg): """ Prepare calllback from DTS for NSR """ xpath = ks_path.to_xpath(NsrYang.get_schema()) action = xact_info.query_action self._log.debug( "Got Nsr prepare callback (xact: %s) (action: %s) (info: %s), %s:%s)", xact, action, xact_info, xpath, msg ) fref = ProtobufC.FieldReference.alloc() fref.goto_whole_message(msg.to_pbcm()) if action in [rwdts.QueryAction.CREATE, rwdts.QueryAction.UPDATE]: pass # Ensure the Cloud account has been specified if this is an NSR create #if msg.id not in self._nsm.nsrs: # if not msg.has_field("cloud_account"): # raise NsrInstantiationFailed("Cloud account not specified in NSR") # We do not allow scaling actions to occur if the NS is not in running state #elif msg.has_field("scaling_group"): # nsr = self._nsm.nsrs[msg.id] # if nsr.state != NetworkServiceRecordState.RUNNING: # raise ScalingOperationError("Unable to perform scaling action when NS is not in running state") # if len(msg.scaling_group) > 1: # raise ScalingOperationError("Only a single scaling group can be configured at a time") # for group_msg in msg.scaling_group: # num_new_group_instances = len(group_msg.instance) # if num_new_group_instances > 1: # raise ScalingOperationError("Only a single scaling instance can be created at a time") # elif num_new_group_instances == 1: # scale_group = nsr.scaling_groups[group_msg.scaling_group_name_ref] # if len(scale_group.instances) == scale_group.max_instance_count: # raise ScalingOperationError("Max instances for %s reached" % scale_group) acg.handle.prepare_complete_ok(xact_info.handle)
def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch): """ Prepare calllback from DTS for NSR """ xpath = ks_path.to_xpath(NsrYang.get_schema()) action = xact_info.query_action self._log.debug( "Got Nsr prepare callback (xact: %s) (action: %s) (info: %s), %s:%s)", xact, action, xact_info, xpath, msg) fref = ProtobufC.FieldReference.alloc() fref.goto_whole_message(msg.to_pbcm()) if action in [rwdts.QueryAction.CREATE, rwdts.QueryAction.UPDATE]: pass # Ensure the Cloud account has been specified if this is an NSR create #if msg.id not in self._nsm.nsrs: # if not msg.has_field("cloud_account"): # raise NsrInstantiationFailed("Cloud account not specified in NSR") # We do not allow scaling actions to occur if the NS is not in running state #elif msg.has_field("scaling_group"): # nsr = self._nsm.nsrs[msg.id] # if nsr.state != NetworkServiceRecordState.RUNNING: # raise ScalingOperationError("Unable to perform scaling action when NS is not in running state") # if len(msg.scaling_group) > 1: # raise ScalingOperationError("Only a single scaling group can be configured at a time") # for group_msg in msg.scaling_group: # num_new_group_instances = len(group_msg.instance) # if num_new_group_instances > 1: # raise ScalingOperationError("Only a single scaling instance can be created at a time") # elif num_new_group_instances == 1: # scale_group = nsr.scaling_groups[group_msg.scaling_group_name_ref] # if len(scale_group.instances) == scale_group.max_instance_count: # raise ScalingOperationError("Max instances for %s reached" % scale_group) acg.handle.prepare_complete_ok(xact_info.handle)
def configure_schema(cls): return NsrYang.get_schema()