Last active
August 29, 2015 14:03
-
-
Save ianunruh/3116708135f26917f510 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
from pysphere import VIServer, VITask | |
from pysphere.resources import VimService_services as VI | |
server = VIServer() | |
server.connect('HOST', 'USER', 'PASSWORD') | |
vm = server.get_vm_by_name('VM_NAME') | |
backing = VI.ns0.VirtualSerialPortPipeBackingInfo_Def('VirtualSerialPortPipeBackingInfo').pyclass() | |
backing.Endpoint = 'PIPE_NAME' | |
port = VI.ns0.VirtualSerialPort_Def('VirtualSerialPort').pyclass() | |
port.YieldOnPoll = True | |
port.Backing = backing | |
port.Key = 9000 | |
request = VI.ReconfigVM_TaskRequestMsg() | |
_this = request.new__this(vm._mor) | |
_this.set_attribute_type(vm._mor.get_attribute_type()) | |
request.set_element__this(_this) | |
spec = request.new_spec() | |
dc = spec.new_deviceChange() | |
dc.Operation = 'add' | |
dc.Device = port | |
spec.DeviceChange = [dc] | |
request.Spec = spec | |
retval = server._proxy.ReconfigVM_Task(request)._returnval | |
vi_task = VITask(retval, server) | |
status = vi_task.wait_for_status([vi_task.STATE_SUCCESS, vi_task.STATE_ERROR]) | |
print status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment