Thursday, October 22, 2015

Nexus 9k Scripting - Part I

Today I have spent some minutes trying out new ways to automate Nexus 9k.

Out of the box, you can get in to Nexus 9k linux OS. Jut do the following:

Switch(config)# feature bash-shell

Switch# run bash
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$ cat /proc/cpu
cat: /proc/cpu: No such file or directory
bash-4.2$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i3-3227U CPU @ 2.50GHz
stepping        : 9
microcode       : 0x19
cpu MHz         : 2500.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5001.98
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i3-3227U CPU @ 2.50GHz
stepping        : 9
microcode       : 0x19
cpu MHz         : 2500.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5001.98
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i3-3227U CPU @ 2.50GHz
stepping        : 9
microcode       : 0x19
cpu MHz         : 2500.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5001.98
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 58
model name      : Intel(R) Core(TM) i3-3227U CPU @ 2.50GHz
stepping        : 9
microcode       : 0x19
cpu MHz         : 2500.000
cache size      : 4096 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 2
apicid          : 3
initial apicid  : 3
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5001.98
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

bash-4.2$

! If you want to be root just do the following
bash-4.2# sudo su root
bash-4.2# whoami
root
bash-4.2#
bash-4.2# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.0G  485M  540M  48% /
none            1.0G  468M  557M  46% /isan
none             40M   40M     0 100% /nxos/tmp
none             50M  8.1M   42M  17% /var/log
none            5.0M   12K  5.0M   1% /var/home
none            300M  156K  300M   1% /var/tmp
none            3.5G  2.0M  3.5G   1% /var/sysmgr
none            600M  201M  400M  34% /var/sysmgr/ftp
none            100M     0  100M   0% /var/sysmgr/srv_logs
none             10M     0   10M   0% /var/sysmgr/ftp/debug_logs
none            3.0G  310M  2.7G  11% /dev/shm
none            600M     0  600M   0% /volatile
none            5.0M   12K  5.0M   1% /debug
/dev/sda5       4.7G  139M  4.3G   4% /mnt/cfg/0
/dev/sda6       4.7G  139M  4.3G   4% /mnt/cfg/1
/dev/sda4        21G  474M   20G   3% /bootflash
none            400M  3.3M  397M   1% /var/sysmgr/startup-cfg
/dev/sda3       4.7G  139M  4.3G   4% /mnt/pss
/dev/sda2       2.4G   69M  2.2G   4% /mnt/plog
/dev/sda7        21G  254M   20G   2% /logflash
bash-4.2#

bash-4.2$ sudo su -
Linux#
Linux#
Linux#
Linux#
Linux#
Linux#
Linux# whoami
root
Linux#
Linux#
Linux#
Linux#
Linux#
Linux#
Linux#
Linux# cat /proc/meminfo
MemTotal:       16402672 kB
MemFree:        12235656 kB
Buffers:          471856 kB
Cached:          1947636 kB
SwapCached:            0 kB
Active:          2382132 kB
Inactive:        1276432 kB
Active(anon):    1552648 kB
Inactive(anon):  1240200 kB
Active(file):     829484 kB
Inactive(file):    36232 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 4 kB
Writeback:             0 kB
AnonPages:       1239144 kB
Mapped:           174804 kB
Shmem:           1553800 kB
Slab:              83676 kB
SReclaimable:      34568 kB
SUnreclaim:        49108 kB
KernelStack:        3440 kB
PageTables:        16296 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     8201336 kB
Committed_AS:   10795204 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      887816 kB
VmallocChunk:   34358789872 kB
HardwareCorrupted:     0 kB
DirectMap4k:       14336 kB
DirectMap2M:    16754688 kB
Linux# run bash ps -el
-su: run: command not found
Linux# python


bash-4.2$ pwd
/bootflash/scripts
bash-4.2$ vi myteste-tcl
! write your script
bash-4.2$ cat myteste-tcl
puts "my first tcl script in Nexus 9k"
bash-4.2$ exit
Switch#  tcl bootflash:/scripts/myteste-tcl
my first tcl script in Nexus 9k
Switch#


No comments: