Nano Services
Last updated
Last updated
NSO services are deployed sequentially. Each service aquires a lock, so services will be queued if multiple services are provisioned at once. For this reason, each service should run very fast. You don’t want a service to reach out to an external system via an API call that takes many seconds to return, for example.
A solution to this issue is to use nano services, which use reactive fastman (RFM). In a nano service, you have multiple stages. If a stage is being processed, the system does not have a lock and can continue processing other stages or services. Once that stage is complete, NSO re-evaluates the service and proceeds to the next step. This adds a lot of complexity, but offers a method to do complex tasks such as creating a service that spins up a VM and must wait minutes for it to come online. Without nano services, NSO would be stuck for minutes unable to process any other new service requests.
When using nano services, the stages are defined in “states.” Each state can have a post action which is used for changes that have “side effects.” A side effect means that something has changed outside of NSO, which NSO cannot automatically reverse. An example would be an IP address allocation action from IPAM. NSO cannot inherinetly know about this change and automatically reverse it via the CDB and fastman process. This is a good use-case for an action which should go in a post action. Post actions are outside the scope of fastman and are not executed when using commit dry-run.
States can have preconditions, which are defined using XPATH expressions. In order to transition to that state, the precondition must evaluate to true. A kicker is automatically created for states with unfulfilled preconditions. So if the service runs, and then finds that the next state has a condition which is false, a kicker is created to watch for the condition to become true. Once it does, the kicker re-deploys the service.
An example of a nano service with a state that has a precondition is below. The pre-condition specifies the XPATH to monitor. The nano-callback means that python code is executed once you are running this stage. Every component needs an init state and ready state. The operator-configured loopback-configured state is where the custom options are added. This is wrapped in a plan-outline which controls the overall nano service.
The plan outline belongs to a behavior-tree, which links the plan outline to the service model. These can be convoluted with loops and multiple components.
Add identities for the component and service plan to the YANG module:
Add the plan outpline:
Add the behavior tree. Make sure the name of the behavior-tree matches the servicepoint.
Add uses ncs:nano-plan-data; to the list.
In the python code, change the Service references to NanoService and use cb_nano_create instead of cb_create. Also change self.register_service to self.register_nano_service. Additionally there are several more paramenters to include in these functions.