Python script implementation details

A python-script provides an intermediate abstraction layer between VSD and the router, translating the VSD data model into the 7750 SR, 7450 ESS, or 7950 XRS router CLI data model. VSD uses metadata key=value parameters to provision service-specific attributes on the 7750. The XMPP messages get to the 7750 and are passed transparently to the Python module so that the CLI is generated and the service created.

Note: The CLI generated by the python-script is not saved in the configuration file; it can be displayed by running the info include-dynamic command on the service contexts. The configuration generated by the python-script is protected and cannot be changed by a CLI user.

The following example shows how the python-script works for a VSD generated configuration:

The user should consider the following:

The following example shows the use of the tools perform service vsd evaluate-script command:

*A:PE1# tools perform service vsd evaluate-script domain-name "L2-DOMAIN-5" type l2-
domain action setup policy "py-l2" vni 64000 rt-i target:64000:64000 rt-
e target:64000:64000 metadata "rd=1:1, sap=1/1/10:3000"   

Success

The following example output shows a python-script that can set up or tear down L2-DOMAINs.

*A:PE1# show python python-script "l2-domain_services" source-in-use 

===============================================================================
Python script "l2-domain_services"
===============================================================================
Admin state   : inService
Oper state    : inService
Primary URL   : ftp://1.1.1.1/timos86/cses-V71/cf2/l2domain_service.py
Secondary URL : (Not Specified)
Tertiary URL  : (Not Specified)
Active URL    : primary

-------------------------------------------------------------------------------
Source (dumped from memory)
-------------------------------------------------------------------------------
      1 from alc import dyn
      2 
      3 def setup_script(vsdParams):
      4     
      5     print ("These are the VSD params: " + str(vsdParams))
      6     servicetype = vsdParams.get('servicetype')
      7     vni = vsdParams.get('vni')
      8     metadata = vsdParams['metadata']
      9     print ("VSD metadata: " + str(metadata))
     10     metadata = dict(e.split('=') for e in metadata.split(','))
     11     print ("Modified metadata: " + str(metadata))
     12     vplsSvc_id = dyn.select_free_id("service-id")
     13     print ("this is the free svc id picked up by the system: " + vplsSvc_id)
     14      
     15     if servicetype == "L2DOMAIN":
     16         rd = metadata['rd']
     17         sap_id = metadata[' sap']
     18         print ('servicetype, VPLS id, rd, sap:', servicetype, vplsSvc_id, rd
, sap_id)
     19         dyn.add_cli("""
     20           configure service
     21               vpls %(vplsSvc_id)s name evi%(vplsSvc_id)s customer 1 create
     22                   description vpls%(vplsSvc_id)s
     23                   bgp
     24                       route-distinguisher %(rd)s
     25                       route-target %(rt)s
     26                   exit
     27                   vxlan instance 1 vni %(vni)s create
     28                   exit
     29                   bgp-evpn 
     30                       evi %(vplsSvc_id)s
     31                       vxlan bgp 1 vxlan-instance 1
     32                           no shutdown
     33                       exit
     34                   exit
     35                   sap %(sap_id)s create
     36                   exit
     37                   no shutdown
     38                   exit
     39               exit
     40           exit
     41         """ % {'vplsSvc_id' : vplsSvc_id, 'vni' : vsdParams['vni'], 'rt' : v
sdParams['rt'], 'rd' : metadata['rd'], 'sap_id' : sap_id})
     42         # L2DOMAIN returns setupParams: vplsSvc_id, servicetype, vni, sap
     43         return {'vplsSvc_id' : vplsSvc_id, 'servicetype' : servicetype, 'vni
' : vni, 'sap_id' : sap_id}
     44 
     45 
     46 #---------------------------------------------------------------------------
     47 
     48 def teardown_script(setupParams):
     49     print ("These are the teardown_script setupParams: " + str(setupParams))
     50     servicetype = setupParams.get('servicetype')   
     51     if servicetype == "L2DOMAIN":
     52       dyn.add_cli("""
     53         configure service
     54             vpls %(vplsSvc_id)s
     55                 no description 
     56                 bgp-evpn 
     57                     vxlan 
     58                         shutdown
     59                     exit
     60                     no evi
     61                     exit
     62                 no vxlan instance 1 vni %(vni)s
     63                 bgp
     64                    no route-distinguisher 
     65                    no route-target 
     66                 exit
     67                 no bgp
     68                 no bgp-evpn
     69                 sap %(sap_id)s
     70                    shutdown
     71                    exit
     72                 no sap %(sap_id)s
     73                 shutdown
     74                 exit
     75                 no vpls %(vplsSvc_id)s
     76             exit
     77         exit                  
     78       """ % {'vplsSvc_id' : setupParams['vplsSvc_id'], 'vni' : setupParams['
vni'], 'sap_id' : setupParams['sap_id']})
     79       return setupParams
     80 
     81 
     82 d = { "script" : (setup_script, None, None, teardown_script) }
     83 
     84 dyn.action(d)
===============================================================================

For instance, assuming that the VSD sends the following:

{'rt': 'target:64000:64000', 'rte': 'target:64000:64000', 'domain': 'L2-DOMAIN-
5', 'servicetype': 'L2DOMAIN', 'vni': '64000', 'metadata': 'rd=1:1, sap=1/1/
10:3000 '}

The system executes the setup script as follows:

123 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base dyn-script req=setup
"dyn-script req=setup: L2-DOMAIN-5
  state=init->waiting-for-setup
"

124 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base dyn-script req=setup
"dyn-script req=setup: L2-DOMAIN-5
  state=waiting-for-setup->generating-setup
"

125 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base Python Output
"Python Output: l2-domain_services
These are the VSD params: {'rt': 'target:64000:64000', 'rte': 'target:64000:6400
0', 'domain': '', 'servicetype': 'L2DOMAIN', 'vni': '64000', 'metadata': 'rd=1:1
, sap=1/1/10:3000 '}
VSD metadata: rd=1:1, sap=1/1/10:3000 
Modified metadata: {'rd': '1:1', ' sap': '1/1/10:3000 '}
this is the free svc id picked up by the system: 64000
('servicetype, VPLS id, rd, sap:', 'L2DOMAIN', '64000', '1:1', '1/1/10:3000 ')
"
Success

126 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base Python Result
"Python Result: l2-domain_services
"

127 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base dyn-script req=setup
"dyn-script req=setup: L2-DOMAIN-5
  state=generating-setup->executing-setup
"

128 2015/06/16 23:35:40.22 UTC MINOR: DEBUG #2001 Base dyn-script cli 1/1
"dyn-script cli 1/1: script:L2-DOMAIN-5(cli 698 dict 0->126)

          configure service
              vpls 64000 name ‟evi64000” customer 1 create
                  description vpls64000
                  bgp
                      route-distinguisher 1:1
                      route-target target:64000:64000
                  exit
                  vxlan instance 1 vni 64000 create
                  exit
                  bgp-evpn 
                      evi 64000
                      vxlan bgp 1 vxlan-instance 1
                          no shutdown
                      exit
                  exit
                  sap 1/1/10:3000  create
                  exit
                  no shutdown
                  exit
              exit
          exit
        "

143 2015/06/16 23:35:40.23 UTC MINOR: DEBUG #2001 Base dyn-script req=setup
"dyn-script req=setup: L2-DOMAIN-5
  state=executing-setup->established"