-
Notifications
You must be signed in to change notification settings - Fork 8
/
find_thick.pl
executable file
·129 lines (98 loc) · 2.23 KB
/
find_thick.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env perl
=head1 NAME
find_thick.pl - Find VMware hosts that don't have thin provisioned disks (or RDMs)
=head1 SYNOPSIS
./find_thick.pl --username admin --password foo --host virtualcenter
=head1 ARGUMENTS
=over
=item --help
Show the arguments for this program.
=back
=head1 DESCRIPTION
Enumerate all VMs without thin provisioned disks or RDM disks.
=head1 SEE ALSO
L<VMware Perl SDK|http://www.vmware.com/support/developer>
=head1 AUTHOR
Jonathan Barber - <[email protected]>
=cut
use strict;
use warnings;
use Data::Dumper;
use VMware::VIRuntime;
$Util::script_version = "1.0";
{
my %mo_cache;
sub cache_mo {
my ($sub) = @_;
if (exists $mo_cache{ $sub->{type} }{ $sub->{value} }) {
return $mo_cache{ $sub->{type} }{ $sub->{value} };
}
else {
return $mo_cache{ $sub->{type} }{ $sub->{value} } = Vim::get_view(mo_ref => $sub);
}
}
}
sub get_folder {
my ($folder, @names) = @_;
my $name = $folder->name;
if ($folder->parent) {
return get_folder(
cache_mo( $folder->parent ),
($name, @names),
);
}
else {
return ($name, @names);
}
}
sub has_thick {
my (@devices) = @_;
my @thick;
for my $device (@devices) {
if ($device->isa("VirtualDisk")) {
if ($device->backing->can("thinProvisioned")) {
if (!$device->backing->thinProvisioned()) {
push @thick, $device;
}
}
else {
push @thick, $device;
}
}
}
return @thick;
}
Opts::parse();
Opts::validate();
Util::connect();
# Get all VMs
my $vms = Vim::find_entity_views(
view_type => 'VirtualMachine',
#filter => { name => 'ies-dev-evl-rhev-m' }
);
my @guests;
# Iterate over the VMs, getting their IPs and OS
foreach my $vm (@{ $vms }) {
unless ($vm->config) {
warn $vm->name, " missing config!\n";
next;
}
unless ($vm->config->hardware) {
warn $vm->name, " missing hardware!\n";
next;
}
my @thick = has_thick( @{$vm->config->hardware->device} );
my $raw = 'VirtualDiskRawDiskMappingVer1BackingInfo';
if (grep { ref $_->backing eq $raw } @thick) {
warn $vm->name, " has RDM - ignoring VM\n";
next;
}
if (@thick) {
print join("/", get_folder($vm)), ": ", $vm->name, "\n";
# Print the types of disks attached
# for (@thick) {
# print " ", ref($_->backing), "\n";
# }
}
}
Util::disconnect();