xuru / pyvisdk Goto Github PK
View Code? Open in Web Editor NEWvSphere SDK for Python
Home Page: http://xuru.github.com/pyvisdk/
License: MIT License
vSphere SDK for Python
Home Page: http://xuru.github.com/pyvisdk/
License: MIT License
Also no longer needed
The data object [http://vijava.sourceforge.net/vSphereAPIDoc/ver5/ReferenceGuide/vim.vApp.VmConfigInfo.html] has a property named "property",
but in the generated vm_config_info.py, it is named "property_", and this raises a InvalidArgumentError when parsing VM hardware configuration.
I don't like manually modifying generated code, so how do I re-generate the do module?
According to the documentation, it should have three parameters: entity, key, value.
They are missing in pyvisdk.
Hi,
I've been trying to compile pyvisdk on Ubuntu 10.04 (64bit) and notice that the installer fails midway with some error messages that are suggestive of a possible bug in one of the python tools packages. The package gets installed without errors on Ubuntu 12 but I wanted to check if anyone has had success with building it on Ubuntu 10.04.
Here are the last few lines from the output of python setup.py install
Installed /usr/local/lib/python2.6/dist-packages/enum-0.4.4-py2.6.egg
Searching for dataflake.cache
Reading http://pypi.python.org/simple/dataflake.cache/
Best match: dataflake.cache 1.4
Downloading http://pypi.python.org/packages/source/d/dataflake.cache/dataflake.cache-1.4.tar.gz#md5=5da22ec2cf9714eea08b0134888fd2d8
Processing dataflake.cache-1.4.tar.gz
Running dataflake.cache-1.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tfNGnB/dataflake.cache-1.4/egg-dist-tmp-zKViML
Checking .pth file support in .
/usr/bin/python -E -c pass
Searching for setuptools-git
Reading http://pypi.python.org/simple/setuptools-git/
Best match: setuptools-git 0.4.2
Downloading http://pypi.python.org/packages/source/s/setuptools-git/setuptools-git-0.4.2.tar.gz#md5=6e2de2238d768f0197f8c041c1f0f5b5
Processing setuptools-git-0.4.2.tar.gz
Running setuptools-git-0.4.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tfNGnB/dataflake.cache-1.4/temp/easy_install-h60Cv6/setuptools-git-0.4.2/egg-dist-tmp-wlj_J0
zip_safe flag not set; analyzing archive contents...
Installed /tmp/easy_install-tfNGnB/dataflake.cache-1.4/setuptools_git-0.4.2-py2.6.egg
Adding dataflake.cache 1.4 to easy-install.pth file
Installed /usr/local/lib/python2.6/dist-packages/dataflake.cache-1.4-py2.6.egg
Searching for suds-jurko
Reading http://pypi.python.org/simple/suds-jurko/
Reading https://bitbucket.org/jurko/suds
Best match: suds-jurko 0.4.1.jurko.4
Downloading https://bitbucket.org/jurko/suds/downloads/suds-jurko-0.4.1.jurko.4.tar.bz2
Processing suds-jurko-0.4.1.jurko.4.tar.bz2
Running suds-jurko-0.4.1.jurko.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-wTLC6l/suds-jurko-0.4.1.jurko.4/egg-dist-tmp-YWSXcc
Traceback (most recent call last):
File "setup.py", line 57, in
include_package_data=True,
File "/usr/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/usr/lib/python2.6/dist-packages/setuptools/command/install.py", line 73, in run
self.do_egg_install()
File "/usr/lib/python2.6/dist-packages/setuptools/command/install.py", line 101, in do_egg_install
cmd.run()
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 254, in run
self.easy_install(spec, not self.no_deps)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 470, in easy_install
return self.install_item(None, spec, tmpdir, deps, True)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 521, in install_item
self.process_distribution(spec, dist, deps)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 562, in process_distribution
[requirement], self.local_index, self.easy_install
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 538, in resolve
dist = best[req.key] = env.best_match(req, self, installer)
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 780, in best_match
return self.obtain(req, installer) # try and download/install
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 792, in obtain
return installer(requirement)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 489, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 519, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 698, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 975, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py", line 964, in run_setup
run_setup(setup_script, args)
File "/usr/lib/python2.6/dist-packages/setuptools/sandbox.py", line 29, in run_setup
lambda: execfile(
File "/usr/lib/python2.6/dist-packages/setuptools/sandbox.py", line 70, in run
return func()
File "/usr/lib/python2.6/dist-packages/setuptools/sandbox.py", line 31, in
{'file':setup_script, 'name':'main'}
File "setup.py", line 59, in
File "", line 15
^
Thanks,
ravi
I was installing using setup.py on Mac OS X Lion which comes by default with python2.7. In the setup.py requires importlib is listed but not required since it is already included. Removing it from the requires allows the install to succeed.
Consider the following case:
Fetching the information from vCenter SDK on each request is not good. Using a time-based cache isn't good either, because the data being presented from vCenter does not change often.
The solution would be creating a new PropertyCollector, a ContainerView and a PropertyCollectorSpec that fetches the information you need. Then, monitor for changes through either CheckForUpdate or WaitForUpdatesEx methods, and refresh the cache only when there's a change.
It takes time to learn how to work with PropertyCollectors, it makes sense to have a high-level API for working with such collections.
There are cases in which you have the moref, and would like to get managed object without traversing the rootFolder.
I needed this in vCenter plug-in development, where the vCenter client sends in the URL the moref of the object its viewing the UI (Host, Datastore, etc).
Not a high priority, but its annoying that importing pyvisdk takes a lot of time.
Too much stuff is going on during the import
Hey guys,
just wondering -- what's the reason behind usage of eval in pyvisdk/core.py#253 ? I mean this piece of code:
def _create_do_obj(self, class_name, obj_content, parent):
mod_name = 'pyvisdk.do.%s' % camel_to_under(class_name)
do = import_string('%s.%s' % (mod_name, class_name))
kwargs = {}
for attr_name in filter(lambda x: not x.startswith('_'), dir(obj_content)):
# evil eval
attr_data = eval('obj_content.%s' % attr_name)
kwargs[attr_name] = self._parse_object_content(attr_data, parent=do)
rv = do(self, **kwargs)
return rv
It seems like you could just use getattr() here.
I'm asking because I've got a SyntaxError recently because one of the returned types contained python keywords in it (the "from" property of an Alarm object or something). My workaround was to replace the eval with
attr_data = getattr(obj_content, attr_name)
When fetching attributes containing unicode characters, pyvisdk raises UnicodeEncodeError.
Here's an example:
In [5]: vim.getVirtualMachine('vmware-studio-01').config
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
/Users/guy/Code/vendata/vmware-powertools/<ipython-input-5-476cb3c76ca4> in <module>()
----> 1 vim.getVirtualMachine('vmware-studio-01').config
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/mo/virtual_machine.pyc in config(self)
34 def config(self):
35 '''Configuration of this virtual machine, including the name and UUID.'''
---> 36 return self.update('config')
37 @property
38 def datastore(self):
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/base/base_entity.pyc in update(self, prop)
109 data = self.cache.get(prop, default=None)
110 if not data:
--> 111 data = self.core.getObjectProperties(self.ref, prop, parent=self)
112 if isinstance(data, list) and len(data) == 1:
113 data = data[0]
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in getObjectProperties(self, mobj, properties, parent)
124
125 obj_content = self.property_collector.RetrieveProperties([spec])
--> 126 return self._parse_object_content(obj_content, parent=parent)
127
128 def getDecendentsByName(self, _type, properties=["name"], name=None, root=None):
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
179 rv = []
180 for obj in obj_content:
--> 181 rv.append(self._parse_object_content(obj, parent))
182
183 elif type(obj_content) == types.NoneType:
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
196 if hasattr(obj_content, "propSet"):
197 for prop in obj_content.propSet:
--> 198 rv.append(self._parse_object_content(prop.val))
199 if len(rv) == 1:
200 rv = rv[0]
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
206
207 elif class_name in DataObjectTypes:
--> 208 rv = self._create_do_obj(class_name, obj_content, parent)
209
210 elif class_name == 'Text':
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _create_do_obj(self, class_name, obj_content, parent)
249 for attr_name in filter(lambda x: not x.startswith('_'), dir(obj_content)):
250 attr_data = eval('obj_content.%s' % attr_name)
--> 251 kwargs[attr_name] = self._parse_object_content(attr_data, parent=do)
252
253 rv = do(self, **kwargs)
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
206
207 elif class_name in DataObjectTypes:
--> 208 rv = self._create_do_obj(class_name, obj_content, parent)
209
210 elif class_name == 'Text':
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _create_do_obj(self, class_name, obj_content, parent)
249 for attr_name in filter(lambda x: not x.startswith('_'), dir(obj_content)):
250 attr_data = eval('obj_content.%s' % attr_name)
--> 251 kwargs[attr_name] = self._parse_object_content(attr_data, parent=do)
252
253 rv = do(self, **kwargs)
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
179 rv = []
180 for obj in obj_content:
--> 181 rv.append(self._parse_object_content(obj, parent))
182
183 elif type(obj_content) == types.NoneType:
/Users/guy/Code/vendata/vmware-powertools/eggs/pyvisdk-0.9.1.alpha2dev_20120420-py2.7.egg/pyvisdk/core.pyc in _parse_object_content(self, obj_content, parent)
209
210 elif class_name == 'Text':
--> 211 rv = str(obj_content)
212
213 elif class_name in ['long', 'bool', 'int', 'datetime', 'str']:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 71: ordinal not in range(128)
All tests pass without it
It's spelled with an 's': 'descendants',
so maybe namepyvisdk.mo.datacenter.Datacenter.getDescendants should exist also, to avoid confusion.
Hi Eric:
I am using pyvisdk and I got this error while cloning and VM.
The code looks like that::
def createvm(buildreq):
relocSpec = VirtualMachineRelocateSpec( conn
, datastore = ds_depesx1.ref
, host = esx_depesx1.ref
, pool = esx_depesx1.parent.ref)
cloneSpec = VirtualMachineCloneSpec( conn
, location = relocSpec
, powerOn = False
, template = False)
tmpl_vmbuild.CloneVM_Task(getFolder(buildreq), buildreq.hostname, cloneSpec)
..
And the error messages looks like this::
$ python createvm.py
[2012-03-01 11:23:57,333][INFO ] vim.login:41 Successfully logged into https://vcenter.fqdn/sdk
[2012-03-01 11:24:02,311][ERROR ] client.send:648 <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="urn:vim25" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:CloneVM_Task>
<ns0:_this type="VirtualMachine">vm-739</ns0:_this>
<ns0:folder type="Folder">group-v10255</ns0:folder>
<ns0:name>cdcchinarch1.cdc</ns0:name>
<ns0:spec>
<ns0:location>
<ns0:datastore type="Datastore">datastore-6143</ns0:datastore>
<ns0:pool type="ClusterComputeResource">domain-c565</ns0:pool>
<ns0:host type="HostSystem">host-6140</ns0:host>
<ns0:transform/>
</ns0:location>
<ns0:template>false</ns0:template>
<ns0:powerOn>false</ns0:powerOn>
<ns0:snapshot/>
</ns0:spec>
</ns0:CloneVM_Task>
</ns1:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
File "createvm.py", line 89, in <module>
createvm(req)
File "createvm.py", line 84, in createvm
tmpl_vmbuild.CloneVM_Task(getFolder(buildreq), buildreq.hostname, cloneSpec)
File "/home/shhgs/.local/lib/python2.7/site-packages/pyvisdk-0.9dev_20120228-py2.7.egg/pyvisdk/mo/virtual_machine.py", line 200, in CloneVM_Task
return self.delegate("CloneVM_Task")(folder, name, spec)
File "/home/shhgs/.local/lib/python2.7/site-packages/pyvisdk-0.9dev_20120228-py2.7.egg/pyvisdk/base/base_entity.py", line 46, in __call__
rv = self.__target(*args, **kwargs)
File "/home/shhgs/.local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/home/shhgs/.local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/home/shhgs/.local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 649, in send
result = self.failed(binding, e)
File "/home/shhgs/.local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/client.py", line 702, in failed
r, p = binding.get_fault(reply)
File "/home/shhgs/.local/lib/python2.7/site-packages/suds-0.4-py2.7.egg/suds/bindings/binding.py", line 265, in get_fault
raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Invalid argument'
..
I don't know much about the VMware SDK, so can you please help troubleshooting this problem?
Thanks
The original suds project has VERY low activity.
There an active fork of it: https://bitbucket.org/jurko/suds/
Very large undertaking and should be broken down into sub-test areas.
Because of this, _init of ContainerView raises an exception.
In [2]: from pyvisdk.mo.container_view import ContainerView
In [3]: ContainerView(None)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/guy/Code/github/pyvisdk/<ipython-input-3-ee8db15f871b> in <module>()
----> 1 ContainerView(None)
/Users/guy/Code/github/pyvisdk/pyvisdk/mo/container_view.py in __init__(self, core, name, ref, type)
26
27 def __init__(self, core, name=None, ref=None, type=ManagedObjectTypes.ContainerView):
---> 28 super(ContainerView, self).__init__(core, name=name, ref=ref, type=type)
29
30
/Users/guy/Code/github/pyvisdk/pyvisdk/mo/managed_object_view.py in __init__(self, core, name, ref, type)
19
20 def __init__(self, core, name=None, ref=None, type=ManagedObjectTypes.ManagedObjectView):
---> 21 super(ManagedObjectView, self).__init__(core, name=name, ref=ref, type=type)
22
23
/Users/guy/Code/github/pyvisdk/pyvisdk/mo/view.py in __init__(self, core, name, ref, type)
26
27 def __init__(self, core, name=None, ref=None, type=ManagedObjectTypes.View):
---> 28 super(View, self).__init__(core, name=name, ref=ref, type=type)
29
30
/Users/guy/Code/github/pyvisdk/pyvisdk/base/base_entity.py in __init__(self, core, name, ref, type)
73 self._name = name
74 self.ref = ref
---> 75 self.type = type
76
77 self.cache = TimeoutCache()
AttributeError: can't set attribute
Vim.connect method takes a long time, and not because of the SSL handshake.
The most time-consuming operating is the creation of the suds client, namely parsing the WDSL.
suds.client.Client that has clone method that shares the WDL between the 1st client and its clones.
This will save time
is pyvsdk support extension service of vcenter.
i got a VM in vcenter, i got some scripts running on the VM managing VMs, NETWORKs on vcenter.
but i don't want to store vcenter password on the VM, is there anyway for the VM to register its self as a vcenter extension service. then it will not keep any password on the VM
This allows extensions to log-in to vCenter.
Do also note that this requires to connect through a HTTP tunnel
# We need to login to vCenter server as an extension and this means that
# vCenter needs to be able to see our certificate.
# If we just connect to the vCenter server HTTPS
# reverse proxy at https://<vcenter>/sdk, the certificate is not forwarded to
# the vCenter server endpoint. We will get an HTTPS connection to the reverse
# proxy, but the connection from the reverse proxy to vCenter will be HTTP.
#
# To handle this we need to tunnel all our traffic through the proxy server
# when talking to vCenter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.