{"id":258,"date":"2010-09-19T22:45:36","date_gmt":"2010-09-20T04:45:36","guid":{"rendered":"http:\/\/benincosa.com\/blog\/?p=258"},"modified":"2014-11-19T11:25:59","modified_gmt":"2014-11-19T17:25:59","slug":"vmware-api-code-to-mount-nfs-datastore-on-esx-host","status":"publish","type":"post","link":"https:\/\/benincosa.com\/?p=258","title":{"rendered":"VMware API code to mount NFS Datastore on ESX host."},"content":{"rendered":"<p>Since I <a href=\"http:\/\/communities.vmware.com\/message\/1613083#1613083\">posted this to the VMware user group<\/a> today I figured I might as well post this to my blog as well:<\/p>\n<p>Lets say you have a datastore 10.3.0.101 that has a mount point \/install\/vm directory.  You want to mount that datastore onto host vhost04 so you can start creating VMs.  Here is how it is done:<\/p>\n<p>[cc lang=&#8217;perl&#8217;]<br \/>\nuse Data::Dumper;<br \/>\nrequire VMware::VIRuntime;<br \/>\nVMware::VIRuntime-&gt;import();<br \/>\nuse strict;<\/p>\n<p>#  log into a node:<br \/>\nmy $conn;<br \/>\nmy $esx = shift || &#8216;vhost04&#8217;;<br \/>\nmy $server = &#8216;10.3.0.101&#8217;;<br \/>\nmy $serverpath = &#8216;\/install\/vm&#8217;;<br \/>\nmy $location = &#8216;nfs_10.3.0.101_install_vm&#8217;;<\/p>\n<p>eval {<br \/>\n$conn = Vim-&gt;new(service_url=&gt;&#8221;https:\/\/$esx\/sdk&#8221;);<br \/>\n$conn-&gt;login(user_name=&gt;&#8217;root&#8217;,password=&gt;&#8217;c1ust3r&#8217;);<br \/>\n};<br \/>\nif($@){<br \/>\nprint Dumper($@);<br \/>\nprint $@-&gt;;fault_string . &#8220;\\n&#8221;;<br \/>\n}<\/p>\n<p>my $hv = $conn-&gt;find_entity_view(view_type =&gt; &#8216;HostSystem&#8217;);<\/p>\n<p>my $nds = HostNasVolumeSpec-&gt;new(accessMode=&gt;&#8217;readWrite&#8217;,<br \/>\nremoteHost=&gt;$server,<br \/>\nlocalPath=&gt;$location,<br \/>\nremotePath=&gt;$serverpath);<br \/>\nmy $dsmv = $hv-&gt;{vim}-&gt;get_view(mo_ref=&gt;$hv-&gt;configManager-&gt;datastoreSystem);<\/p>\n<p>eval {<br \/>\n$dsmv-&gt;CreateNasDatastore(spec=&gt;$nds);<br \/>\n};<\/p>\n<p>if ($@) {<br \/>\nprint $@-&gt;fault_string . &#8220;\\n&#8221;;<br \/>\nprint Dumper($@);<br \/>\n}<\/p>\n<p>$conn-&gt;logout;<br \/>\n[\/cc]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I posted this to the VMware user group today I figured I might as well post this to my blog as well: Lets say you have a datastore 10.3.0.101 that has a mount point \/install\/vm directory. You want to mount that datastore onto host vhost04 so you can start creating VMs. Here is how&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,101,39],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/258"}],"collection":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=258"}],"version-history":[{"count":6,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":2810,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions\/2810"}],"wp:attachment":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}