This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nms-oam/gloam_shell/remote_config
2018-09-27 16:28:35 +08:00

43 lines
1.2 KiB
Python

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# created by tanghao
from sys import argv
import json
import os
import shutil
def trans_list(data):
result=''
for i in range(len(data)):
if(isinstance(data[i],dict)):
result=trans_dic(data[i])
return result
def trans_dic(data):
count = len(data) - 1
result='[{'
for key in data:
if (count == 0):
if(isinstance(data[key],list)):
methodResult=trans_list(data[key])
result +='\\\"' + key + '\\\"' + ":" + methodResult
elif(isinstance(data[key],dict)):
methodResult =trans_dic(data[key])
result += '\\\"' + key + '\\\"' + ":" + methodResult
else:
result += '\\\"' + key + '\\\"' + ":\\\"" + data[key] + "\\\""
else:
result += '\\\"' + key + '\\\"' + ":\\\"" + data[key] + "\\\","
count = count - 1
result+='}]'
return result
if __name__ == '__main__':
data = json.loads(argv[1])[0]
ip=data['ip']
jsonStr=trans_dic(data)
result=os.system('ssh -o ConnectTimeout=3 '+ip+' \'device_config "'+jsonStr+'"\'')
exit(0)