#!/usr/bin/perl -w
#
# Mike 'AmP' Liebsch <mike@ampersize.org>
#
# This script searches for a Datastore and dumps the whole object
# Usage:
# vidumper.pl <login> --type <type> --pattern <name> # Searches for the pattern

use strict;
use warnings;

use VMware::VIRuntime;

use constant DEBUG => 0;

my %opts = (
  'type' => {
     type => "=s",
     help => "The type of object you want to dump. Can be
     \tClusterComputeResource, ComputeResource, Datacenter,
     \tFolder, HostSystem, ResourcePool, or VirtualMachine",
     required => 1,
  },
  'pattern' => {
     type => "=s",
     help => "The pattern to search in the name of the object",
     required => 1,
  },
);

# Getting the options
Opts::add_options(%opts);

# read/validate options and connect to the server
Opts::parse();
Opts::validate();
Util::connect();

# supplied name
my $pattern = Opts::get_option('pattern');
my $type = Opts::get_option('type');

# Search for host
my $entity = Vim::find_entity_views(
  view_type => $type,
  filter => { name => qr/$pattern/},
);

my $found=0;
foreach (@$entity) {
   # Dump Object
   print Dumper $_;
   $found = 1;
}
if ( $found == 0 ) { print "Sorry no $type for pattern \"$pattern\" could be found!\n" };

# disconnect from the server
Util::disconnect();

# -EOF-


