pyvmomi
        
            VMware vSphere API Python Bindings
           
               
           
            
        
            
             
              
      
                 
                
                
            
            
I am trying to restart an ESX management network through Python Pyvmomi.
Even after Google search I did not find any relevant API to do so.
Please help me if there is any API which can restart/stop ESX management network which is managed by VCentre.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I have a task of implementing a basic backup and recovery system within a django app. I have heard of pyvmomi, but never used it before.
My specific tasks at hand is:
1)  make a call to a vCenter, pass the vm name, and request to make a snapshot
2)  obtain the file location of the snapshot
3) and upload the snapshot file into an OpenStack Swift object store
What is the actual syntax of creating a vm snapshot using pyvmomi?
Also - what is the syntax to request the actual snapshot file from vCenter?
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I am using pyvmomi for capturing vcenter events using WaitForUpdatesEx method.
But it is not able to capture vm's reset event as there is no property change in this case.
It is capturing poweron, poweroff, suspend events as state changes for them.
For all other vm related events, i am in constant state of waiting using WaitForUpdatesEx method.
Can anyone help me as i have a case where i want to perform some specific action in case vm reset event has occurred.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I have a lot of VM (dispatch with 2 hosts) and I would like to list all of them.
TO do that, i use this:
atexit.register(connect.Disconnect, self.si)
content = self.si.RetrieveContent()
children = content.rootFolder.childEntity
    for child in content.rootFolder.childEntity:
        if hasattr(child, 'vmFolder'):
            datacenter = child
            vmFolder = datacenter.vmFolder
            vmList = vmFolder.childEntity
        for vm in vmList:
            self._getInfosVms(vm)
For my main method with this method:
 def _getInfosVms(self, vm, depth = 1, i = 0):
        maxdepth = 10
        if hasattr(vm, 'childEntity'):
            if depth > maxdepth:
                return
            vmList = vm.childEntity
            for c in vmList:
                self._getInfosVms(c, depth+1)
            return
        print(vm.summary)
This code list all basic informations about vms but for some vm I have an error.
I can't display vm.summry but I can print vm.
error:
File "/python_project/packages/pyVmomi/VmomiSupport.py", line 560,
in call
 return self.f(*args, **kwargs)
File "/python_project/packages/pyVmomi/VmomiSupport.py", line 383,
in _InvokeAccessor
 return self._stub.InvokeAccessor(self, info)
File "/python_project/packages/pyVmomi/StubAdapterAccessorImpl.py",
line 42, in InvokeAccessor
 options=self._pcType.RetrieveOptions(maxObjects=1))
File "/python_project/packages/pyVmomi/VmomiSupport.py", line 566,
in 
 self.f(*(self.args + (obj,) + args), **kwargs)
File "/python_project/packages/pyVmomi/VmomiSupport.py", line 375,
in _InvokeMethod
 return self._stub.InvokeMethod(self, info, args)
File "/python_project/packages/pyVmomi/SoapAdapter.py", line 1291,
in InvokeMethod
     raise exc
pyVmomi.SoapAdapter.ParserError: 'xml document:
\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xedZ[o\xe3\xba\x11~\xdf_A\xf8\xa9\x05"\xcb\xb2|I\x0c\xae\x0e\x12\xc7\xd9\x04\x8d\xb3\x86\x9d\r\x82S\x14\x05-\xd11\x1b\x89\xd4!);>\xbf\xbeCJ\xf2J\xbe\x9d\x05Z\xbf\xe5\xc9\xe2\xcc7\x17\x0e\x87\xd4\x0ce\xfc\xdbG\x12\xa3\x15\x95\x8a\t\xfe\xb5\xe15[\rDy("\xc6\xdf\xbe6~<\xdf9\x97\x8d\xdf\x82/X\t\x92R\xbe\x1a\x8c\xf8\x8a\xc6"\xa5\x08\xc4\xb8\x1a\xe4\xe4\xf0kc\xa9u:p]\x15.iBT\x13\xb8\x86\xd5\x14\xf2\xcd5\x0fn\xa9\xd3m|\xa9\x89\xae~E47\xf9S\xf4CE[\xb1\xf5z\xdd\\\xfb\x16\xddn\xb5<\xf7u\xfc8\xb3\x9a*h\xf6\xd7h\x87q\xa5\t\x0fi\xa32\xd9\x1b\x11m`8\xa5Z2\xba\xa2\x13\t^H\xcd\xa8\x1a}L\xa9J\x05WE\x1c\xbe62\xc9\x07+\x96\xb4\xbb\x8d\x00K\xaaa\xb8"q\x80\xc5\xfc?4\xd4\xca>
\xbdI\xe9\xd7\xc6\x0b\x93:#\xf1\x98\x84K\xc6\xc1\xdc*q<\xaf\x83]@\x048\x05\x133\xaa\x03\xcc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x17\xbb]\x1av\x0f\xec\xadz\xe6\xd6\x89\xb6\xc8\xcfO\x9f\xfc\xdf$\xee\xf6\x7f(n\xe5\xcf)\xee\xa9?\xb6\x04_\xb0\xbb\xf3?\x18w\xf7O@\xc1\x7f\x01\xf4\x96\x1dv>$\x00\x00
parse error at: line:1, col:0'
Thanks for ur help.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
i'm currently working on the VMware SDK in python (with Pyvmomi) and I see in all sample or example this line:
atexit.register(Disconnect, self.si)
Does anyone know what does is supposed do ? I don't understand, thanks for ur help.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I've done a good bit of research over the last day or two, both on here and good ole Google and can't seem to find any examples of adding orphaned vms to inventory with pyVmomi(or any other vSphere module for that matter). 
Thanks to some examples on github, I was able to FIND the orphaned vms using pyVmomi, but man.. pyVmomi doesn't have any good documentation.
So, now I'm going to post my own question! 
Thanks for any tips/help!
-Chris Mulliner
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I'm trying to set the IP,NetMask,Gateway and VLAN of a VMWare Instance
so far I have: 
si = connectToVCenter('192.168.7.2','nunya','vmware')
content = si.RetrieveContent()
vm = getByName(content,'sfo-lab-cob01')
for device in vm.config.hardware.device:
    if isinstance(device, vim.vm.device.VirtualEthernetCard):
        nicspec = vim.vm.device.VirtualDeviceSpec()
        nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.edit
        nicspec.device = device
        nicspec.device.wakeOnLanEnabled = True
        nicspec.device.connectable.startConnected = True
        nicspec.device.connectable.allowGuestControl = True
        nicspec.device.addressType = 'static'
        network = getObj(content,
          [vim.dvs.DistributedVirtualPortgroup],
          'VLAN324mgmt')
        pprint(dir(device))
So what is the directive I'm looking for to set the IP/Gateway/NetMask and VLAN ? 
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I am trying to deploy OVF to vSphere 5.5 by a python script using pyvmomi due to an error The operation is not supported on the object. The deepest I could get into this error was by printing ImportVApp.error which has this output.
(vmodl.fault.NotSupported) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = 'The operation is not supported on the object.',
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) []
}
The lease is giving my error after initialising and giving the error above. You can find my script here.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
Trying to execute this sample code as I need to create a vm using pyvmomi.
But the execution fails at the start in from tools import tasks with the error:  ImportError: cannot import name tasks.
I have tried for long but could not resolve the error. I have python 2.7 on centOS 6.4
tools module is installed but do not have tasks.py inside /usr/local/lib/python2.7/site-packages/tools/
Not sure which tools packages have to be installed.
Please guide.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I am using pyVmomi api to automate some of vshpere stuff, we have recently upgragded vspher5.5 to vsphre6.0 then we started seeing error 
MethodNotFound: 
    (vmodl.fault.MethodNotFound) 
    {
    dynamicType = <unset>, 
    dynamicProperty = (vmodl.DynamicProperty) [], 
    msg = <unset>, 
    faultCause = <unset>,
    faultMessage = (vmodl.LocalizableMessage) [], 
    receiver = 'vim.dvs.VmwareDistributedVirtualSwitch:***',
    method = 'LookupPortgroup' 
   }
When I looked deeper then realize that it has been thrown from 
port_group_obj = dvs.LookupDvPortGroup(port_group_key)
Placing entire code for your reference:
def getvmnics(self, vm):
        nics = []
        host_page_dict = self.get_hosts_port_groups(self.hosts)
        for dev in vm.config.hardware.device:
            if isinstance(dev, vim.vm.device.VirtualEthernetCard):
                dev_backing = dev.backing
                if hasattr(dev_backing, 'port'):
                    port_group_key = dev.backing.port.portgroupKey
                    dvs_uuid = dev.backing.port.switchUuid
                    try:
                        dvs = self.content.dvSwitchManager.QueryDvsByUuid(dvs_uuid)
                    except:
                        port_group_name = "** Error: DVS not found **"
                        vlan_id = "NA"
                        v_switch = "NA"
                    else:
                        port_group_obj = dvs.LookupDvPortGroup(port_group_key)
                        port_group_name = port_group_obj.config.name
                        vlan_id = str(port_group_obj.config.defaultPortConfig.vlan.vlanId)
                        v_switch = str(dvs.name)
                else:
                    port_group_name = dev.backing.network.name
                    vmHost = vm.runtime.host
                    # global variable hosts is a list, not a dict
                    hosts = self.get_vm_hosts
                    host_pos = hosts.index(vmHost)
                    viewHost = hosts[host_pos]
                    # global variable hostPgDict stores portgroups per host
                    pgs = host_page_dict[viewHost]
                    for p in pgs:
                        if port_group_name in p.key:
                            vlan_id = str(p.spec.vlanId)
                            v_switch = str(p.spec.vswitchName)
                if port_group_name is None:
                    port_group_name = 'NA'
                nics.append({
                    'mac_address': dev.macAddress,
                    'portGroup': port_group_name,
                    'nic_number': dev.deviceInfo.label,
                    'vSwitch': v_switch,
                    'VLan': vlan_id
                })
        return nics
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
Can you use pyvmomi to track things like when an account hasn't been used for 100days?
What attributes would I need to read up on?
        Source: (StackOverflow)
                  
                 
            
                 
                 
            
                 
                
                
            
            
Currently I've got a pice of code that lists all the vmFolder.Childentities through pyVmomi, these are used to structurize the VM's in vCenter. 
But now I want to change the vmFolder of an existing virtual machine. 
PS: I can't show any code because I'm currently at work
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I know that there are some entries that touch this point but I am yet to find a simple vCenter VM creation example using pyVmomi. There doesn't seem to be a straight forward deploy example in the community samples (https://github.com/vmware/pyvmomi-community-samples) either.
I am looking to deploy a VM from scratch using an OVA or OVF file.
Any help would be much appreciated.
        Source: (StackOverflow)
                  
                 
            
                 
                
                
            
            
I would like to request a pyvmomi sample which would demonstrate how to to a VM snapshot. What is the Web page that I could use to enter such a request?
        Source: (StackOverflow)