Created
September 28, 2015 11:57
-
-
Save rgerganov/12fdd2ded8d80f36230f to your computer and use it in GitHub Desktop.
relocate VM with pyvmomi
This file contains hidden or 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/env python | |
import atexit | |
import time | |
from pyVim import connect | |
from pyVmomi import vim | |
def wait_for_task(task): | |
while True: | |
if task.info.state == vim.TaskInfo.State.success: | |
return | |
if task.info.state == vim.TaskInfo.State.error: | |
raise Exception('task failed') | |
time.sleep(1) | |
def main(): | |
si = connect.SmartConnect(host='rgerganov-vc', user='root', pwd='vmware', port=443) | |
atexit.register(connect.Disconnect, si) | |
vm = vim.VirtualMachine('vm-1411', si._stub) | |
spec = vim.VirtualMachineRelocateSpec() | |
spec.pool = vim.ResourcePool('resgroup-8', si._stub) | |
spec.datastore = vim.Datastore('datastore-11', si._stub) | |
task = vm.RelocateVM_Task(spec) | |
wait_for_task(task) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment