- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyone has a sample code on how to use the datastoreNamespaceManager API to create a directory on a datastore?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks you very much, Stumpr!
I did have to use the fileManager call, instead of the datastorenamespacemanager. Thanks for pointing out the different application of those two API calls. Wondering why the datastoreNamespacemanager only supports the creation on datastore that does NOT support top level directory creation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The datastoreNamespaceManager API is specifically built for VSAN (Virtual SAN) based datastores. For regular Datstores, you should use the FileManager for directory creation/deletion and for VSAN Datastores, it is recommend you use the datastoreNamespaceManager.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it. Thanks William.