VMware API code to mount NFS Datastore on ESX host.

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 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:

[cc lang=’perl’]
use Data::Dumper;
require VMware::VIRuntime;
use strict;

# log into a node:
my $conn;
my $esx = shift || ‘vhost04’;
my $server = ‘’;
my $serverpath = ‘/install/vm’;
my $location = ‘nfs_10.3.0.101_install_vm’;

eval {
$conn = Vim->new(service_url=>”https://$esx/sdk”);
print Dumper($@);
print $@->;fault_string . “\n”;

my $hv = $conn->find_entity_view(view_type => ‘HostSystem’);

my $nds = HostNasVolumeSpec->new(accessMode=>’readWrite’,
my $dsmv = $hv->{vim}->get_view(mo_ref=>$hv->configManager->datastoreSystem);

eval {

if ($@) {
print $@->fault_string . “\n”;
print Dumper($@);


Comments are closed.