Skip to content

Instantly share code, notes, and snippets.

@sky-joker
Created December 10, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sky-joker/d77d97f015bf2d4b99403e6065257880 to your computer and use it in GitHub Desktop.
Save sky-joker/d77d97f015bf2d4b99403e6065257880 to your computer and use it in GitHub Desktop.
#!/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 = ''
snapshot_vm = 'CentOS7_Develop'
snapshot_name = 'Snapshot01'
snapshot_description = 'test snapshot'
# 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:
if(i.name == snapshot_vm):
i.CreateSnapshot(snapshot_name, snapshot_description, False, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment