stumpr
Virtuoso
Virtuoso

use strict;

use warnings;

use VMware::VIRuntime;

Opts::parse();

Opts::validate();

Util::connect();

my ($sc, $datastoreNS, $ds, $path, $supported);

$sc = Vim::get_service_content();

$ds = Vim::find_entity_view(view_type => "Datastore", filter => { 'name' => 'ds-nfs-01' });

$datastoreNS = Vim::get_view(mo_ref => $sc->datastoreNamespaceManager);

$supported = $ds->{'capability'}->{'topLevelDirectoryCreateSupported'};

die "datastoreNamespaceManager is not supported on this datastore (topLevelDirectoryCreateSupported=1)" if $supported;

$path = $datastoreNS->CreateDirectory(datastore => $ds, displayName => "TestDir/");

print "New directory created: $path\n";

But bear in mind this call is only for datastores that DO NOT support topLevelDirectoryCreateSupported capabilities (vSphere 5.5 Documentation Center )

You'll need to use FileManager otherwise:

use strict;

use warnings;

use VMware::VIRuntime;

Opts::parse();

Opts::validate();

Util::connect();

my ($sc, $fm, $dc, $path);

$sc = Vim::get_service_content();

$fm = Vim::get_view(mo_ref => $sc->fileManager);

$dc = Vim::find_entity_view(view_type => "Datacenter", filter => { 'name' => 'DC01' });

$path = "[ds-nfs-01] TestDir";

$fm->MakeDirectory(name => $path, datacenter => $dc, createParentDirectories => 1);

print "Directory successfully created\n";

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

Reply
0 Kudos