- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Trying to return the naa.XXX value for the datatores of a VM
I have been unable to return the Device number for the datastores associated with VMs. Our admins poorly named the datastores so the only way to see what array the VMDKs are being housed on is by looking at the device name.
Is a formate like naa.XXXXX etc.
thanks
my $vm_view = Vim::find_entity_views(view_type=>'VirtualMachine',properties=>['name','config'],begin_entity=>$each_host);
print "\n\tVirtual Machines on this Host:\n";
foreach my $each_vm(@$vm_view){
print "\t\t".$each_vm->name."\n";
my $datastore = $each_vm->datastore->name;
print "Datastore:".$datastore;
my $hardware = $each_vm->config->hardware->device;
foreach my $hw(@$hardware){
if(ref $hw eq 'VirtualDisk'){
print "\t\t\tVirtualDisk:".$hw->backing->fileName."\t".length($hw->backing->fileName)."\t\t".$hw->capacityInKB."\n";
if(length($hw->backing->fileName)>$strlen){ $strlen = length($hw->backing->fileName);}
# $query1->execute($each_vm->name,$hw->backing->fileName,($hw->capacityInKB/1024)) or die(storelater());
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm a bit closer to where I want to be however I'm no
my $datastore = $each_vm->datastore;
print "Datastore:".@$datastore[0]."\n";
which returns....t
Datastore:ManagedObjectReference=HASH(0x3ea2580)
Thnking I'm a bit close...not sure where to go from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Assuming your VM has multiple vmdks and they could come from different datastore...Loop through your vmdks and the naa ID can be extracted like this:
# gather all your vmdks
my $devices = $vm->config->hardware->device;
foreach (@$devices) {
if($_->isa('VirtualDisk')) {push (@vmdks, $_);
}
foreach (@vmdks) {
my $ds = Vim::get_view(mo_ref=>$_->backing->datastore, properties => ['info','summary']);
if ($ds->summary->type eq 'VMFS') {
$naa = ${$ds->info->vmfs->extent}[0]->diskName;
# try to get the real naa if there is rdm involved here. lunUuid is a sure sign
($naa = $_->backing->lunUuid) =~ s/[0-9a-z]{10}(.*)[0-9a-z]{12}/naa.$1/ if defined $_->backing->{'lunUuid'};
}
}