adding NFS datastore using pyvmomi

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

adding NFS datastore using pyvmomi

abuzzi.cisco
Hello,

if I try to use vcenter's MOB portal (ie: http://x.x.x.x/mob ) I can browse under "host -> configManager -> datastoreSystem-3271” and utilize “CreateNasDatastore” method to add new NFS datastore, ie:

<spec>
   <remoteHost>192.168.x.x</remoteHost>
   <remotePath>/NFS/vcenter-nfs</remotePath>
   <localPath>vcenter-nfs</localPath>
   <accessMode>readWrite</accessMode>
   
   <type>nfs</type>
   
   <userName></userName>
   
   <password></password>
   
   
   
   <remoteHostNames>string</remoteHostNames>
   

   

   <securityType></securityType>

</spec>

If I try the same using pyvmomi:

        spec=vim.host.NasVolume.Specification
        spec.remoteHost="192.168.x.x"
        spec.remotePath="/NFS/vcenter-nfs"
        spec.localPath="vcenter-nfs"
        spec.accessMode="readWrite"
        host.configManager.datastoreSystem.CreateNasDatastore(spec)

I got following error:

Traceback (most recent call last):
  File "./add_nfs_datastore.py", line 159, in <module>
    main(sys.argv)
  File "./add_nfs_datastore.py", line 154, in main
    host.configManager.datastoreSystem.CreateNasDatastore(spec)
  File "/Library/Python/2.7/site-packages/pyvmomi-5.5.0.2014.1.1-py2.7.egg/pyVmomi/VmomiSupport.py", line 566, in <lambda>
  File "/Library/Python/2.7/site-packages/pyvmomi-5.5.0.2014.1.1-py2.7.egg/pyVmomi/VmomiSupport.py", line 374, in _InvokeMethod
  File "/Library/Python/2.7/site-packages/pyvmomi-5.5.0.2014.1.1-py2.7.egg/pyVmomi/VmomiSupport.py", line 949, in CheckField
TypeError: For "spec" expected type vim.host.NasVolume.Specification, but got LazyType

If I stop the script execution before the error then I'm able to inspect host and host.configManager.datastoreSystem variables obtaining:

>>> host
'vim.HostSystem:host-311'
>>> host.configManager.datastoreSystem
'vim.host.DatastoreSystem:datastoreSystem-311'
>>>

So path with that is equivalent to what I get through /MOB...
But why I end up getting LazyType error ??

Thx,
Andrea
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding NFS datastore using pyvmomi

errr
I think its because you left the () off sending in an actual type instead of an instance of it.

For example:

 spec=vim.host.NasVolume.Specification()


-mike
Let me be useful today, and should I need to make a decision today that will forever change my life, let me make it with a clear head.

Twitter: @virtdevninja
Freenode IRC: errr
Blog: http://www.errr-online.com/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding NFS datastore using pyvmomi

Andrea
Hello Mike,

you are absolutely right !!

        spec=vim.host.NasVolume.Specification()
        spec.remoteHost="192.168.17.8"
        spec.remotePath="/test/test"
        spec.localPath="test"
        spec.accessMode="readWrite"

        host.configManager.datastoreSystem.CreateNasDatastore(spec)

And when I force the CreateNasDatastore() I get:

>>> host.configManager.datastoreSystem.CreateNasDatastore(spec)
'vim.Datastore:datastore-622'
>>>

Thank you so much!!
Andrea
Loading...