cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1463
Views
10
Helpful
3
Replies

Python check in service breaks service re-deploy and check-sync in NSO

RobvdL
Level 1
Level 1

I've developed for a service in Python a validation check. It will validate if the service.vlan_id is already in use on multiple devices which are added to a list inside NSO.

Because the network is a brownfield environment we want to have this check in place so we are certain that the vlan_id number is not used on any subinterfaces on routers or switches. Otherwise the service would overwrite existing network configurations which will disrupt production traffic. 

The check will raise an exception that the vlan_id is used on device X on port Y.

 

The python check works ok when creating new instances of the service. When I preconfigure a subinterface on device X with dot1q 100, and I want to create a new instance of the service, it reports that vlan_id 100 is already configured on device X.

 

But when I want to use the check-sync or re-deploy functionality, the check will break this functionality. If I create a valid service for customerA with vlan_id 200, the check-sync will report that vlan_id 200 is in use on all devices that are in scope of the service.

I previously build it also under the @ service.create callback, I thought maybe it will work under @ service.pre_modification but without any result.

Python needs to know if the service is being checked for sync or that the service is being redeployed. If Python is aware if this, I can build an IF statement so python will skip the check in those cases.

1 Accepted Solution

Accepted Solutions

RobvdL
Level 1
Level 1

I've found the solution.

I need to check what value 'op' has:

 

@Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):

op == 0 when doing a dry-run or a commit.

op == 1 when doing a re-deploy (reconcile), check-sync 

op == 2 when deleting the service.

 

The solution is 

 

 @Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):
        self.log.info('Service premod(service=', kp, ')')
        if op == 0:
            service = ncs.maagic.cd(root, kp)
            < do some checks over here >

View solution in original post

3 Replies 3

RobvdL
Level 1
Level 1

I've found the solution.

I need to check what value 'op' has:

 

@Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):

op == 0 when doing a dry-run or a commit.

op == 1 when doing a re-deploy (reconcile), check-sync 

op == 2 when deleting the service.

 

The solution is 

 

 @Service.pre_modification
    def cb_pre_modification(self, tctx, op, kp, root, proplist):
        self.log.info('Service premod(service=', kp, ')')
        if op == 0:
            service = ncs.maagic.cd(root, kp)
            < do some checks over here >

Great that you find your answer!

 

However, just wanted to correct one point. The possible values for operations are:

    NCS_SERVICE_CREATE = 0,
    NCS_SERVICE_UPDATE = 1,
    NCS_SERVICE_DELETE = 2

This means that "0" is the original creation of the service instance and "2" is the deletion of the full service instance.

Now, "1" will include changes to the re-deploy counter (you figured this out) but also service intend changes (like changing the VLAN value after the initial commit was done). It may be that your code is doing the verification when you first configure the vlan but not after that for modifications. If you want to check what caused the update (like a service modification to check if the vlan is being modified), you can also do this via creating an iterator.

randreetta
Level 1
Level 1

hi, how can you be sure that all interfaces are in sync before doing the check ? do you simply perform the check using the 'root' object and checking all the configs data ? using something like:

 

       root = ncs.maagic.get_root(t)

       device = root.devices.device[device_name]

       for interface in device.interface[interface_type]:

          print (interface.name)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: