sonic-buildimage/platform/s3ip-sysfs/scripts/s3ip_load.py
tianshangfei f7d80e63db
The user framework module complies with s3ip sysfs specification (#12894)
Why I did it
The user framework module complies with s3ip sysfs specification

How I did it
1、 create a s3ip_sysfs service
2、 the s3ip_sysfs service call the “s3ip_sysfs_tool.sh” to install kernel module and run s3ip_load.py
3、 s3ip_load.py will parse the s3ip_sysfs_conf.json configuration file and create /sys_switch/ directory

How to verify it
A demo driver base on this framework will display the sysfs node wich conform to the s3ip sysfs specification
2022-12-14 22:34:55 +08:00

33 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
import os
if __name__ == '__main__':
os.system("sudo rm -rf /sys_switch;sudo mkdir -p -m 777 /sys_switch")
with open('/etc/s3ip/s3ip_sysfs_conf.json', 'r') as jsonfile:
json_string = json.load(jsonfile)
for s3ip_sysfs_path in json_string['s3ip_syfs_paths']:
#print('path:' + s3ip_sysfs_path['path'])
#print('type:' + s3ip_sysfs_path['type'])
#print('value:' + s3ip_sysfs_path['value'])
if s3ip_sysfs_path['type'] == "string" :
(path, file) = os.path.split(s3ip_sysfs_path['path'])
#创建文件
command = "sudo mkdir -p -m 777 " + path
#print(command)
os.system(command)
command = "sudo echo " + "\"" + s3ip_sysfs_path['value'] + "\"" + " > " + s3ip_sysfs_path['path']
#print(command)
os.system(command)
elif s3ip_sysfs_path['type'] == "path" :
command = "sudo ln -s " + s3ip_sysfs_path['value'] + " " + s3ip_sysfs_path['path']
#print(command)
os.system(command)
else:
print('error type:' + s3ip_sysfs_path['type'])
os.system("tree -l /sys_switch")