设置url、用户名、密码
VC_ADDRESS="https://192.168.1.200"
VC_USER="administrator@vsphere.local"
VC_PASSWORD="password"
获取cookie
-
方式一:BASE64加密一下
VC_BASE64=$(echo -n "$VC_USER:$VC_PASSWORD" | base64)
curl -X POST -H "Authorization: Basic $VC_BASE64" -k https://$VC_ADDRESS/rest/com/vmware/cis/session --cookie-jar cookies.txt
-
方式二:直接-u获取
curl -u "$VC_USER:$VC_PASSWORD" -X POST "$VC_ADDRESS/rest/com/vmware/cis/session" --cookie-jar cookies.txt -k
使用示例,获取vm列表
curl -b cookies.txt -k "$VC_ADDRESS/rest/vcenter/vm"
评论区