Skip to content

Instantly share code, notes, and snippets.

@sky-joker

sky-joker/get_vm_list.py

Last active Dec 10, 2016
Embed
What would you like to do?
#!/usr/bin/python3
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import ssl
import atexit
if __name__ == '__main__':
# 接続情報
host = 'IP or FQDN'
username = 'administrator@vsphere.local'
password = ''
# SSL証明書対策
context = None
if hasattr(ssl, '_create_unverified_context'):
context = ssl._create_unverified_context()
# vCenterへ接続
si = SmartConnect(host = host,
user = username,
pwd = password,
sslContext = context)
# 処理完了時にvCenterから切断
atexit.register(Disconnect, si)
# VM情報の取得
content = si.content
vm_list = content.viewManager.CreateContainerView(content.rootFolder,
[vim.VirtualMachine],
True)
for i in vm_list.view:
print(i.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.