Created
December 10, 2016 09:55
-
-
Save sky-joker/7fa61baa20170c63f991290889aae136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' | |
delete_snapshot_name = 'Snapshot01' | |
# 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) | |
# Snapshot情報取得 | |
snapshot_list = {} | |
for i in vm_list.view: | |
if(i.name == snapshot_vm): | |
r = i.snapshot.rootSnapshotList | |
for snapshots in r: | |
snapshot_list[snapshots.name] = snapshots.snapshot | |
childsnapshot = snapshots.childSnapshotList | |
while childsnapshot: | |
snapshot_list[childsnapshot[0].name] = childsnapshot[0].snapshot | |
childsnapshot = childsnapshot[0].childSnapshotList | |
# Snapshotを削除 | |
if(delete_snapshot_name in snapshot_list): | |
snapshot_list[delete_snapshot_name].RemoveSnapshot_Task(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment