Posted on January 20, 2016 2:28 pm
 |  Asked by Vongchai Suriyanonrin
 |  676 views
Tags:
0
0
Print Friendly, PDF & Email

I try to write eos sdk code for display route change via eos sdk. When I use on_route_set on fib handler, it’s shown error as “SyntaxError: invalid syntax”.

 

My code

#!/usr/bin/env python
import eossdk
import sys

class MyFibHandler( eossdk.AgentHandler, eossdk.FibHandler ):
def __init__( self, fibMgr, agentMgr ):
eossdk.AgentHandler.__init__( self, agentMgr )
eossdk.FibHandler.__init__( self, fibMgr )
self.intfMgr_ = fibMgr

def on_initialized( self ):
print “We are initialized!”

def on_fec_set(self, fec)
print fec

sdk = eossdk.Sdk()
mta = MyFibHandler( sdk.get_fib_mgr(), sdk.get_agent_mgr() )
sdk.main_loop( sys.argv )

 

Error message

File “./fib.py”, line 16
def on_fec_set(self, fec)

Marked as spam
0
Posted by Edmund
Answered on January 20, 2016 8:20 pm

 

The syntax error is a missing : in this line

def on_fec_set(self, fec) print fec

This should be

def on_fec_set(self, fec): print fec

You’re also not calling sdk.get_fib_mgr() correctly if you want to be notified.

https://github.com/aristanetworks/EosSdk/blob/ccd91a5f392fab2c84eb696d29807ac173585bf0/eos/fib.h

/**
* Returns the mode this manager is in.
* This mode is set during the construction of the manager, i.e.:
* `sdk.get_fib_mgr(MODE_TYPE_READ_NOTIFYING)`.
* If MODE_TYPE_READ_ONLY, only the getters and
* iterators of this manager will function.
*/

so you should use

sdk_.get_fib_mgr(eossdk.MODE_TYPE_READ_NOTIFYING))

Here’s a working example (I use .to_string() to get more readable output)

#!/usr/bin/env python

import eossdk
import sys

class FecAgent(eossdk.AgentHandler, eossdk.FibHandler):
    def __init__(self, agentMgr, fibMgr):
        eossdk.AgentHandler.__init__(self, agentMgr)
        eossdk.FibHandler.__init__(self, fibMgr)
        self.agentMgr_ = agentMgr
        self.fibMgr_ = fibMgr

    def on_route_del(self, key):
        print "route deleted %s" % key.to_string()

    def on_route_set(self, entry):
        print "route add %s" % entry.to_string()

    def on_fec_set(self,fec):
        print "fec add %s" % fec.to_string()

    def on_fec_del(self,fec_key):
        print "fec delete %s" % fec_key.to_string()

if __name__ == "__main__":
	sdk_  = eossdk.Sdk()
        _ = FecAgent(sdk_.get_agent_mgr(), sdk_.get_fib_mgr(eossdk.MODE_TYPE_READ_NOTIFYING))
        sdk_.main_loop(sys.argv)

 

and and example when I add and remove a static route after starting the script

Arista(config)#ip route 192.168.1.0/24 10.10.10.10
Arista(config)#no ip route 192.168.1.0/24 10.10.10.10
bash-4.1# ./fec.py
[Warning] AGENT_PROCESS_NAME is not set; using agent name 'fec'
route add fib_route_t(route_key=fib_route_key_t(prefix=192.168.1.0/24), preference=1, metric=0, route_type=ROUTE_TYPE_STATIC_CONFIG, fec_id=4294967312)
fec add fib_fec_t(fec_key=fib_fec_key_t(fec_id=4294967312), fec_type=FEC_TYPE_FORWARD, nexthop_group_name='', via='fib_via_t(hop=10.10.10.10, intf=Vlan10)')
route deleted fib_route_key_t(prefix=192.168.1.0/24)
fec delete fib_fec_key_t(fec_id=4294967312)

 

Post your Answer

You must be logged in to post an answer.