Skip to content

Instantly share code, notes, and snippets.

@ianunruh
Last active August 29, 2015 14:03
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 ianunruh/3116708135f26917f510 to your computer and use it in GitHub Desktop.
Save ianunruh/3116708135f26917f510 to your computer and use it in GitHub Desktop.
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