13. 貼上以下 [需自行修改 vcenter ip username / password]
import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
session = requests.session()
# Disable cert verification for demo purpose.
# This is not recommended in a production environment.
session.verify = False
# Disable the secure connection warning for demo purpose.
# This is not recommended in a production environment.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
14. # Connect to a vCenter Server using username and password
vsphere_client = create_vsphere_client(server='192.168.100.101',
username='administrator@vsphere.local', password='P@ssw0rd', session=session)
# List all VMs inside the vCenter Server
vsphere_client.vcenter.VM.list()
vsphere_client.vcenter.VM.list() 會列出現行系統 VM 列表
15. 例:列出 VM FREENAS 資源狀態
client.vcenter.VM.list(client.vcenter.VM.FilterSpec(names={'FREENAS'}))
接著就依自行需要執行 python API
備註:
Python 程序副檔為.py 可以命令列方式行
Windows 環境變數 PATH 如果不在請自行手動加。
http://code.vmware.com/ > API Explorer https://developer.vmware.com/ 有完整
API