Infinidat / infi.pyvmomi_wrapper

BSD 3-Clause "New" or "Revised" License
14 stars 11 forks source link

Error in using infi.pyvmomi_wrapper #5

Closed shyamachilles closed 8 years ago

shyamachilles commented 8 years ago

@wiggin15 Hello ! I am trying to exercise vim sms API's and getting below error. Could you please help.

My environment is as follows -

pip2.7 freeze | grep -i py

infi.pyutils==1.1.2 infi.pyvmomi-wrapper==0.1.18 pyvim==0.0.18 pyvmomi==6.0.0.2016.4

python

Python 2.7.10 (default, Aug 13 2015, 15:15:40) [GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

from infi.pyvmomi_wrapper import Client from pyVmomi import vim client = Client("dl380pg8-141-vm01.3pardata.com","administrator@vsphere.local", "Admin!23") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/infi/pyvmomi_wrapper/client.py", line 15, in init certfile=certfile, keyfile=keyfile, sslContext=sslContext) File "/usr/local/lib/python2.7/site-packages/infi/pyvmomi_wrapper/connect.py", line 106, in Connect sslContext) TypeError: __FindSupportedVersion() takes exactly 5 arguments (6 given)

wiggin15 commented 8 years ago

The function __FindSupportedVersion in pyvmomi 6.0.0.2016.4 takes 6 arguments (https://github.com/vmware/pyvmomi/blob/v6.0.0.2016.4/pyVim/connect.py#L645), not 5. It looks like you are somehow using an older version of pyvmomi. Check the versions again. Try the following to know where the pyvmomi code is taken from:

import pyVmomi
print pyVmomi.__path__
shyamachilles commented 8 years ago

import pyVmomi print pyVmomi.path ['/home/usr/banalas/IDART/testSW/lib/pyVmomi']

So I removed the pyVmomi package from /home/usr/banalas/IDART/testSW/lib location

and exported PYTHONPATH with site packages -

$ echo $PYTHONPATH /home/usr/banalas/avenger-test/sbin:/home/usr/banalas/IDART/testSW/lib

$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages:/home/usr/banalas/avenger-test/sbin:/home/usr/banalas/IDART/testSW/lib

Now am getting a runtime error -

from pyVmomi import vim from infi.pyvmomi_wrapper import Client from infi.pyvmomi_wrapper.sms import SmsClient Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/infi/pyvmomi_wrapper/sms/init.py", line 1, in import SmsObjects File "/usr/local/lib/python2.7/site-packages/infi/pyvmomi_wrapper/sms/SmsObjects.py", line 152, in CreateManagedType("sms.ServiceInstance", "SmsServiceInstance", "vmodl.ManagedObject", "sms.version.version1", None, [("queryStorageManager", "QueryStorageManager", "sms.version.version2", (), (0, "sms.StorageManager", "sms.StorageManager"), "StorageViews.View", None), ("querySessionManager", "QuerySessionManager", "sms.version.version5", (), (0, "sms.auth.SessionManager", "sms.auth.SessionManager"), "System.Anonymous", None), ("queryAboutInfo", "QueryAboutInfo", "sms.version.version2", (), (0, "sms.AboutInfo", "sms.AboutInfo"), "StorageViews.View", None)]) File "/usr/local/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 751, in CreateManagedType _SetWsdlMethod(typeNs, meth[1], dic) File "/usr/local/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 1191, in _SetWsdlMethod (ns, wsdlName, inputMM[0], curMM[0])) RuntimeError: Duplicate wsdl method urn:sms QueryStorageManager (new class sms.ServiceInstance vs existing sms.ServiceInstance)

Could you please help -

wiggin15 commented 8 years ago

Both pyvmomi and infi.pyvmomi_wrapper have unreleased commits. You must use the latest development branches in order to use the SMS APIs. The best way to install the newest development branches of both projects is as follows:

easy_install infi.projector
git clone https://github.com/Infinidat/infi.pyvmomi_wrapper.git
cd infi.pyvmomi_wrapper
projector devenv build
python setup.py install
cd ..
git clone https://github.com/vmware/pyvmomi.git
cd pyvmomi
python setup.py install
shyamachilles commented 8 years ago

Thanks @wiggin15 , I made some progress in creating a client object, but below is the issue when I am trying to create SmsClient object. Could you please help.

from pyVmomi import vim from infi.pyvmomi_wrapper import Client from infi.pyvmomi_wrapper.sms import SmsClient import ssl context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) context.verify_mode = ssl.CERT_NONE

client = Client('dl380pg8-141-vm01.3pardata.com','administrator@vsphere.local','Admin!23',sslContext=context) client <infi.pyvmomi_wrapper.client.Client object at 0x7fade3894810>

sms = SmsClient(client, version="version5")

sm = sms.serviceinstance.QueryStorageManager() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 575, in self.f((self.args + (obj,) + args), *_kwargs) File "/usr/local/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 381, in _InvokeMethod return self._stub.InvokeMethod(self, info, args) File "/usr/local/lib/python2.7/site-packages/pyVmomi/SoapAdapter.py", line 1323, in InvokeMethod conn.request('POST', self.path, req, headers) File "/usr/local/lib/python2.7/httplib.py", line 1053, in request self._send_request(method, url, body, headers) File "/usr/local/lib/python2.7/httplib.py", line 1093, in _send_request self.endheaders(body) File "/usr/local/lib/python2.7/httplib.py", line 1049, in endheaders self._send_output(message_body) File "/usr/local/lib/python2.7/httplib.py", line 893, in _send_output self.send(msg) File "/usr/local/lib/python2.7/httplib.py", line 855, in send self.connect() File "/usr/local/lib/python2.7/httplib.py", line 1274, in connect server_hostname=server_hostname) File "/usr/local/lib/python2.7/ssl.py", line 352, in wrap_socket _context=self) File "/usr/local/lib/python2.7/ssl.py", line 579, in init self.do_handshake() File "/usr/local/lib/python2.7/ssl.py", line 808, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

wiggin15 commented 8 years ago

This looks like a problem in the code. The SMS client wasn't using the original client's SSL context. I just pushed a commit to fix this. Can you check out the latest development branch (again) and try again? Thanks.

shyamachilles commented 8 years ago

Many Thanks @wiggin15 - Its working for me now with your fix ! I am able to query the storage containers on the vSphere. -

from pyVmomi import vim from infi.pyvmomi_wrapper import Client from infi.pyvmomi_wrapper.sms import SmsClient import ssl context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) context.verify_mode = ssl.CERT_NONE client = Client('dl380pg8-141-vm01.3pardata.com','administrator@vsphere.local','Admin!23',sslContext=context) sms = SmsClient(client, version="version5") sm = sms.service_instance.QueryStorageManager() sm 'sms.StorageManager:storageManager' container_result = sm.QueryStorageContainer() container_result (sms.storage.StorageContainerResult) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], storageContainer = (sms.storage.StorageContainer) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], uuid = 'vvol:75f3b0f8bf294ab7-921d60e8cedf48c9',

... ... ...

Likewise, Could you please let me know how to register VASA provider on the vSphere, through the API's given that we have the VASA URL, username and password of the host.

shyamachilles commented 8 years ago

@wiggin15 Many thanks again - I am able to create the datastore ! The scid is obtained by the uuid attribute of storage container object, not name -

from pyVmomi import vim from infi.pyvmomi_wrapper import Client from infi.pyvmomi_wrapper.sms import SmsClient import ssl context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) context.verify_mode = ssl.CERT_NONE client = Client('dl380pg8-141-vm01.3pardata.com','administrator@vsphere.local','Admin!23',sslContext=context) sms = SmsClient(client, version="version5") sm = sms.service_instance.QueryStorageManager() container_result = sm.QueryStorageContainer() container1=container_result.storageContainer[0] container2=container_result.storageContainer[1]

container2 (sms.storage.StorageContainer) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], uuid = 'vvol:aeacfdfe2fa84f0d-861b3a5a9b21e14c', name = 'dummy', maxVvolSizeInMB = 16777216L, providerId = (str) [ '8365ab7f-e356-4b1d-bb45-8c6cdf33b560' ], arrayId = (str) [ 'com.hp.3par:216:array:216' ] }

scid = container2.uuid vvol_spec = vim.HostDatastoreSystemVvolDatastoreSpec(name="vvolds", scId=scid) vvol_spec (vim.host.DatastoreSystem.VvolDatastoreSpec) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], name = 'vvolds', scId = 'vvol:aeacfdfe2fa84f0d-861b3a5a9b21e14c' } host = client.get_host_systems()[0] new_datastore = host.configManager.datastoreSystem.CreateVvolDatastore(vvol_spec)

new_datastore.info (vim.host.VvolDatastoreInfo) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], name = 'vvolds', url = 'ds:///vmfs/volumes/vvol:aeacfdfe2fa84f0d-861b3a5a9b21e14c/', freeSpace = 12490838638592L, maxFileSize = 17592186044416L, maxVirtualDiskCapacity = 17592186044416L, maxMemoryFileSize = 9223372036854775807L, timestamp = 2016-06-08T23:17:17.748871Z, containerId = , vvolDS = (vim.host.VvolVolume) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], type = 'VVOL', name = 'vvolds', capacity = 14018773254144L, scId = 'vvol:aeacfdfe2fa84f0d-861b3a5a9b21e14c', hostPE = (vim.host.VvolVolume.HostProtocolEndpoint) [ (vim.host.VvolVolume.HostProtocolEndpoint) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], key = 'vim.HostSystem:host-2603', protocolEndpoint = (vim.host.ProtocolEndpoint) [ (vim.host.ProtocolEndpoint) { dynamicType = , dynamicProperty = (vmodl.DynamicProperty) [], peType = 'block', uuid = 'naa.2ff70002ac0000d8', hostKey = (vim.HostSystem) [], storageArray = 'com.hp.3par:216:array:216', nfsServer = , nfsDir = , deviceId = 'naa.2ff70002ac0000d8' } ] } ], ... ... ...

I rephrase my last request - Could you please let me know how to register storage provider on the vsphere, once the VASA URL , user name and password are available for the Storage Array

Many thanks @wiggin15 !

wiggin15 commented 8 years ago

Hi @shyamachilles. I'm afraid this is not a place for a VMware API / Python tutorial. To register a VASA provider you can read the [SMS StorageManager API] documentation(https://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.wssdk.smssdk.doc%2Fsms.StorageManager.html). The problem with the host is that you called client.get_host_systems() so you got a Python list of host objects and not a single host object to work with. In the future please try to keep the discussion related to issues with infi.pyvmomi_wrapper.

shyamachilles commented 8 years ago

Hi @wiggin15 , the documentation isnt very intuitive. This one step is blocking my automation.. Could you please let me know how to create a VasaProviderSpec/ SmsProviderSpec and subsequently register Storage provider please. Much appreciate it and Thanks.

shyamachilles commented 8 years ago

Many thanks @wiggin15 . I was able to create VasaProviderSpec/ SmsProviderSpec and subsequently register Storage provider. Closing this issue.

udautkarsh commented 2 years ago

Hi @shyamachilles, How did you to that? I have exactly same requirement. Would you please help me out here?