You are here: Home Documents Programming

Programming

Case study of simple Python app writing
(verified 2010 Apr. / EOS 4.3.0 / DCS-7120T-4S 03.01)

bash access

There is bash utility in Arista, to invoke it, do bash command of enable mode of EOS CLI as follows;
mypc$ slogin -l admin arista.example.com
Password:
localhost>enable
localhost#bash
Arista Networks EOS shell
[admin@localhost ~]$

Writing a program

There are several pathways to place your program to Arista directory, as follows;
  1. Edit code in direct by vi command from bash of Arista.
  2. Copy and paste from external system through the remote terminal. You need do "cat > sample" or something on Arista side.
  3. Copy from USB memory. (Just insert USB storage then "cp /mnt/flash/sample ." or something.)
  4. Place it on Web directory then get by wget command. (Arista has /usr/bin/wget in initial condition.)
/tmp directory is always writable. After you remount the partition as read write mode, it is possible to write somewhere else. But all modifications will be initialized when you restart the system. If you want to keep your files, you can use /persist/local directory instead.

Example: counting ports

Here is a simple Python script to access the SysDB and count the ports of the box.
--------------- 
[admin@localhost tmp]$ cat fanCount
#!/usr/bin/env python
import EntityManager, TnDiagLib, Tracing
import sys, os, __builtin__
sysname = 'ar'
em = EntityManager.Sysdb( sysname )
(config,status) = TnDiagLib.mountEntities( em )
phyCount = len( config.phyConfig )
print "PHY Count is", phyCount
sys.stdout.flush()
[admin@localhost tmp]$

---------------

 

Here is the result;

 

---------------

[admin@localhost tmp]$ ./fanCount
PHY Count is 20
[admin@localhost tmp]$

---------------

To execute the program like above, it needs to set the execute permission.
Just do "chmod a+x fanCount", the same way as ordinary Unix system.


Please look at the "sysname" of the sample code. "sysname" and "ar" are the typical combination to handle SysDB. You can find a lot of "ar" hardcoded implementation in the source code and it may help to trace the system code.

Filed under: