Adam Pridgen (apridgen) <adam pridgen gmail com> |
Tuesday, April 22 2008 20:32.48 CDT |
I am not sure how many people use PyVix, but I took some time to go through and update the project. The project was originally developed by David S. Rushby, and the project provides Python Bindings for VMWare's VIX SDK.
It looks like the API has not been updated in a while, so rather than just throwing a patch somewhere on the web just to be lost, I posted my updates on Google Code. The source code can be downloaded from here:
svn checkout http://randomizedcode.googlecode.com/svn/trunk/pyvix-branch pyvix
or in tar ball form here:
http://randomizedcode.googlecode.com/files/latest-pyvix-4.22.2008.tgz
I have only installed this on Linux, but it should install in Windows too.
Prerequisites:
VMWare's VIX SDK
C/C++ compiler (MinGW/GCC)
To Install, drop prompt:
sudo python setup.py install
Updates:
1) I ran into some problems building on Windows Vista for 6.03 using mingw32, so I am still trying to figure out how to build them at this time,
2) Adam35413 pointed this out, and the path needs to be updated to include the _vixmodule.so's path, or it can simply be added to /lib.
Sorry if anyone ran into problems.
Hmm.. I'm doing something REALLY wrong here..
cowmix@homewerk5:~/VMWARE/pyvix/latest-pyvix-4.22.2008$ sudo python setup.py install
running install
running build
running build_py
copying ./vix.py -> build/lib.linux-i686-2.5/pyvix
running build_ext
building 'pyvix._vixmodule' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -UNDEBUG -I/usr/include/vmware-vix/ -I/usr/include/python2.5 -c _vixmodule.c -o build/temp.linux-i686-2.5/_vixmodule.o -fno-strict-aliasing
In file included from _vixmodule.c:10:
util.c: In function �pyf_extractNthProperty�:
util.c:98: warning: implicit declaration of function �VixJob_GetNthProperties�
In file included from _vixmodule.c:13:
callback_accumulator.c: In function �VixCallback_accumulateProcessList�:
callback_accumulator.c:120: warning: implicit declaration of function �VixJob_GetNumProperties�
callback_accumulator.c:120: error: �VIX_PROPERTY_JOB_RESULT_ITEM_NAME� undeclared (first use in this function)
callback_accumulator.c:120: error: (Each undeclared identifier is reported only once
callback_accumulator.c:120: error: for each function it appears in.)
callback_accumulator.c:137: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_ID� undeclared (first use in this function)
callback_accumulator.c:140: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_OWNER� undeclared (first use in this function)
callback_accumulator.c:145: error: �VIX_PROPERTY_JOB_RESULT_PROCESS_COMMAND� undeclared (first use in this function)
callback_accumulator.c: In function �VixCallback_accumulateDirectoryList�:
------------------------- etc, etc, etc.................... |
You need to install the vmware vix SDK from vmware.com.
http://www.vmware.com/download/sdk/vmauto.html
With that and python-dev on Ubuntu 8.04 I got as far as the module compiling and installing but now I get a segfault when I
~$ python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvix.vix import *
>>> h = Host()
Segmentation fault |
Recently saw your update to PyVix. Thank you!
I'm trying to get it running, but came across some issues, one I fixed, one I cannot:
1) For some installations, the Registry Key is located in 'SOFTWARE\VMware, Inc.\VMware VIX' Code for an updated _support.py after the comment. It looks first in that location, and if an exception occurs (registry key doesn't exist), looks in the previous location.
2) Can't seem to getting the C code compiling on Windows. Any one else have any luck?
# pyvix - Miscellaneous Utility Code
# Copyright 2006 David S. Rushby
# Available under the MIT license (see docs/license.txt for details).
import os.path, sys
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
def findVixDir():
if PLATFORM_IS_WINDOWS:
import _winreg
r = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
try:
serverInstKey = _winreg.OpenKey(r,
r'SOFTWARE\VMware, Inc.\VMware VIX'
)
print serverInstKey
try:
serverInstDir = _winreg.QueryValueEx(
serverInstKey, 'InstallPath'
)[0]
finally:
_winreg.CloseKey(serverInstKey)
vixDir = serverInstDir
except WindowsError:
try:
serverInstKey = _winreg.OpenKey(r,
r'SOFTWARE\VMware, Inc.\VMware Server'
)
try:
serverInstDir = _winreg.QueryValueEx(
serverInstKey, 'InstallPath'
)[0]
finally:
_winreg.CloseKey(serverInstKey)
finally:
vixDir = os.path.join(serverInstDir, os.pardir, 'VMware VIX')
finally:
r.Close()
if vixDir.endswith(os.sep):
vixDir = vixDir[:-len(os.sep)]
vixDir = os.path.normpath(vixDir)
return vixDir
|
I got it compiled, but it still does not work yet.
To get it compiled, I just ran 'python setup.py install' after having MS Visual Studio 2003 installed. I also had copy a number of dll and lib files from my VMware VIX directory to the directory where the pyvix source was located.
The VMware VIX had several folders with some of the files in them: server-1, ws-1, ws-2, ws-3, ws-5. I guess these correspond to the different VMware apps you intend this to work with. Since I'm woring VMware Player, and there isn't an option for it, I went with ws-5.
The in python, I run
>>> import pyvix.vix
and the result is an error popping up in Windows with:
"python.exe - Unable To Locate Component"
------------------------------------------
This application has failed to start because VIX.DLL was not found. Re-installing the application may fix this problem.
And an error in Python:
Traceback <most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\site=packages\py-vix\vix.py, line 18, in <module>
import _vixmodule as _v # the underlying C mode
ImportError: DLL load failed: The specified module could not be found.
Not really sure why. _vixmodule.pyd was successfully compiled and stored in that directory.
Any ideas |
Ahh!
I needed to copy all those dlls and libs to the directory in the python library as well, not just the one I compiled from.
Now that I can successfully run >>> from pyvix.vix import *
I just need to figure out how to use the library and actually see if it will do what I need!
|
How to connect to a remote VMWare server using the Host object of pyvix.vix module. For a Server running locally, I can do h = Host() and it can provide paths of all running VM's etc.
Thanks |
Just the same as for the local case, but you add some extra named parameters to the Host() constructor, e.g.:
remote = Host(hostName='foo.bar.com',
username='someone',password='secret')
for p in remote.findRunningVMPaths():
print p
|
I installed VMware-vix-1.1.5-109488.exe under Windows XP and have not been able to compile using the default setup.py (some symbols seems missing in "C:\Program Files\VMware\VMware VIX\vix.lib").
As noted by clintd, one can choose a specific vix.lib; the ViX documentation (available in "C:\Program Files\VMware\VMware VIX\doc") calls this "Compiling Without the Wrapper Library", and hints that ws-1 is for VMware Server 1.0, ws-2 for Workstation 6.0 and ws-3 for Workstation 6.0.1 (I found no description of ws-4 and ws-5, though).
But another mode of compilation is described as "Compiling Using the Wrapper Library" and seems more generic: here, the proper lib is loaded as needed, depending on the VMWare product used.
To enable it, I replaced:
libNames.append('vix')
by:
libNames.append('VixAllProducts')
libNames.append('kernel32')
libNames.append('user32')
libNames.append('advapi32')
libNames.append('ole32')
libNames.append('oleaut32')
libNames.append('ws2_32')
HTH. |
Well, no luck.
When compiling without the wrapper library, I get :
Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvix.vix import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\Lib\site-packages\pyvix\vix.py", line 18, in <module>
import _vixmodule as _v # The underlying C module.
ImportError: DLL load failed: The specified procedure could not be found.
And when compiling using the wrapper library, "from pyvix.vix import *" is successful but "h=Host()" segfaults, similarly to pseudoyodel above :-(
How would you debug those?
Regards. |
It works better now.
I have installed the lastest VIX distribution (1.6.2) and added a dependency to setup.py, which now reads:
libDirs.append(vixDir)
libNames.append('VixAllProducts')
libNames.append('kernel32')
libNames.append('user32')
libNames.append('advapi32')
libNames.append('ole32')
libNames.append('oleaut32')
libNames.append('ws2_32')
libNames.append('shell32') # Needed by VIX 1.6.2
Note that I do not link in vix.lib; VixAllProducts does it on demand.
I also edited vm.c due to a crash in pyf_VM_powerOnOrOff: when no argument was passed, "args" was null which confused PyArg_ParseTuple. Hence the fix is:
if (args != NULL && !PyArg_ParseTuple(args, "|i",&options)) { goto fail; }
I can now register and power on a VM from pyvix.
HTH!
On a related note, is there any gathering of pyvix users somewhere, or is this largely an abandonned project? I fail to see why, since python is considered a nice language for system administration, and pyvix definitely looks like a good tool for the trade considering how hot virtualization is currently.
Feel free to comment ;-) |
|