在excel文件中有一些部件、序列号和配置ID
Part - Serial - Config.
223-234 - 345 - PLU9.
904-567 - 987 - GJK0.
232-589 - 890 - LOM7.
230-978 - 356 - GJK0.
我想使用API动态检查这些数字,在rundeck 中输入这个文件
https://prcmf.uslp07.app.xvz.com/api/c7/parts?include=name&selector=name,price,country&part=223-234&serial=345&config=PLU9
我希望动态更改和搜索部件、序列号和配置,并在Rundeck 中使用python获得输出
https://prcmf.uslp07.app.xvz.com/api/c7/partsinclude=name&selector=name,price,country&part=@option.part@&serial=@option.serial@&config=@option.config@
如何在Rundeck中使用此功能?
您可以使用此python示例代码将任何值传递给Rundeck作业上的任何选项。只需更改";字符串";变量从任何源(另一个API调用、fuzzytable输出等(转换为您的值。
import requests
# host definition
rdeck_instance = "localhost"
rdeck_port = "4440"
rdeck_api = "35"
rdeck_token = "lL4CwBiHHmxirZtTUHDJEHu4ZGTontjX"
jobid = "f68e73cb-54e5-483e-b451-b7ae484c54fe"
# variable strings (for testing, in this case, you can put from the result from any source: another API call, fuzzy table output, etc.)
string1="one"
string2="two"
string3="three"
s = requests.Session()
r = s.post("http://" + rdeck_instance + ":" + rdeck_port +"/api/" + rdeck_api + "/job/" + jobid + "/run?authtoken=" + rdeck_token,
headers = {"Accept" : "application/json"},
data = { "argString" : "-opt1 {} -opt2 {} -opt3 {}".format(string1, string2, string3)})
# print data (for debug)
print ('######################')
print (r.status_code)
print (r.url)
print ('######################')
# json response
print(r.json())