Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Added utilities to populate system eeprom and system info for management framework to support openconfig platform and system components #1

Merged
merged 5 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions scripts/syseeprom-to-json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/awk -f

BEGIN { print "{"; n = 0 }

function sep()
{
if (n > 0) print ", ";
++n;
}

/Product Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Part Number/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Serial Number/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Base MAC Address/ { sep(); print "\"" $1 " " $2 " " $3 "\": \"" $6 "\""; }
/Manufacture Date/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Device Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Label Revision/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Platform Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/ONIE Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/MAC Addresses/ { sep(); print "\"" $1 " " $2 "\": " $5; }
/Manfacturer/ { sep(); print "\"" $1 "\": \"" $4 "\""; }
/Manfacture Country/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Vendor Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Diag Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Service Tag/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Hardware Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Software Version/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Manfacture Date/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }
/Model Name/ { sep(); print "\"" $1 " " $2 "\": \"" $5 "\""; }

END { print "}" }
48 changes: 48 additions & 0 deletions scripts/syspoll
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python

import sys
import os
import subprocess
import json
import time

progname = sys.argv[0]

outfile = '/var/platform/system'
tmpfile = '/var/platform/system.tmp'

ticks_per_sec = os.sysconf(os.sysconf_names['SC_CLK_TCK'])

while True:
d = {}
d['hostname'] = subprocess.check_output(['hostname']).rstrip()
w = subprocess.check_output(['free']).split('\n')[1].split()
d['total'] = int(w[1])
d['used'] = int(w[2])
d['free'] = int(w[3])
btime = int(subprocess.check_output(['bash', '-c', "cat /proc/stat | grep '^btime'"]).split()[1])
cpus = []
for li in subprocess.check_output(['bash', '-c', "cat /proc/stat | grep '^cpu'"]).rstrip().split('\n'):
w = li.split()
cpus.append({'user': int(w[1]) + int(w[2]), 'system': int(w[3]), 'idle': int(w[4])})
d['cpus'] = cpus
procs = {}
for li in subprocess.check_output(['ps', 'aux']).rstrip().split('\n')[1:]:
w = li.split()
cmd = ' '.join(w[10:])
if progname in cmd:
continue
pid = w[1]
try:
w2 = subprocess.check_output(['bash', '-c', 'cat /proc/{}/stat 2>/dev/null'.format(pid)]).split()
except subprocess.CalledProcessError:
continue
procs[pid] = {'cmd': cmd, 'start': btime + int(w2[21]) / ticks_per_sec, 'user': int(w2[13]), 'system': int(w2[14]), 'mem': int(w[4]), 'cpuitil': float(w[2]), 'memutil': float(w[3])}
d['procs'] = procs

f = open(tmpfile, 'w')
json.dump(d, f)
f.close()
os.rename(tmpfile, outfile)

time.sleep(1)
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
'scripts/route_check.py',
'scripts/route_check_test.sh',
'scripts/sfpshow',
'scripts/syseeprom-to-json',
'scripts/syspoll',
'scripts/teamshow',
'scripts/warm-reboot',
'scripts/watermarkstat',
Expand Down