VMware Cloud Community
abuzzi_cisco
Contributor
Contributor

adding NFS datastore using pyvmomi

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>

   <!-- optional -->

   <type>nfs</type>

   <!-- optional -->

   <userName></userName>

   <!-- optional -->

   <password></password>

   <!-- optional -->

   <!-- array start -->

   <!-- optional -->

   <remoteHostNames>string</remoteHostNames>

   <!-- array end -->

   <!-- optional -->

   <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

0 Kudos
2 Replies
abuzzi_cisco
Contributor
Contributor

Hello,

as pointed out by Mike in following forum:

http://pyvmomi.2338814.n4.nabble.com/adding-NFS-datastore-using-pyvmomi-td34.html

the issue was caused because I left the () off sending in an actual type instead of an instance of it.

So using:

        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'

>>>

I got the NFS datastore correctly created.

Thx!

0 Kudos
obanna
Contributor
Contributor

Hi Andrea,

Could you please let me know how to get the remotepath and localpath attribute values.

Thanks,

Obanna

0 Kudos