add tsg_sn_update.py, tsg_monit_device.py
This commit is contained in:
32
py_test/shell_cmd.py
Normal file
32
py_test/shell_cmd.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
class CommandException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def tsg_get_device_list_info_by_sn(sn):
|
||||
command = "consul kv get device_list/%s" %(sn)
|
||||
exitcode, output = subprocess.getstatusoutput(command)
|
||||
#print("%d" %(exitcode))
|
||||
if exitcode != 0:
|
||||
raise CommandException(output)
|
||||
return ""
|
||||
else:
|
||||
return output
|
||||
|
||||
def tsg_get_tags_by_sn(sn):
|
||||
dev_list_info = tsg_get_device_list_info_by_sn(sn)
|
||||
if len(dev_list_info) <= 0:
|
||||
#写个空json
|
||||
return "{}"
|
||||
|
||||
json_dict = json.loads(dev_list_info)
|
||||
tags = json_dict['tags']
|
||||
#重新组织成合法的json格式
|
||||
dict_to_json = json.dumps(tags)
|
||||
json_tags = "{\"tags\":%s}" %(dict_to_json)
|
||||
return json_tags
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(tsg_get_tags_by_sn("CBT2201925000001"))
|
||||
Reference in New Issue
Block a user