Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Why does this not work? - Can't call method on an undefined value!!!

by Batistuta_g_2000 (Initiate)
on May 06, 2013 at 16:01 UTC ( #1032342=perlquestion: print w/ replies, xml ) Need Help??
Batistuta_g_2000 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Am relatively new to perl scripting and am tring to write a script to get the vm names for certain ipaddresses on an ESXi host:
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; use VMware::VIRuntime; my %opts = ( vm => { type => "=s", help => "Name for the VM", required => 1, }, ip => { type => "=s", help => "Name for the IP", required => 1, }, ); Opts::add_options(%opts); Opts::parse(); Opts::validate(); Util::connect(); my $ip_address = Opts::get_option('ip'); my $vmname = Opts::get_option('vm'); my %filter=(name=>$vmname); my $vm = Vim::find_entity_view(view_type => 'VirtualMachine',filter=>\ +%filter); foreach my $ip (@{$vm->guest->net->ipConfig->ipAddress}) { my $ip_address = Opts::get_option('ip'); my $ipadd = ref $ip; if ($ipadd eq $ip_address) { print "Found $ip for $vmname \n"; } # } } Util::disconnect();
Getting error: Can't call method ipConfig on and undefined value? Is referencing an MOB reference but I cant see a problem, are there any obvious "Perl" problems with it? Thanks

Comment on Why does this not work? - Can't call method on an undefined value!!!
Download Code
Re: Why does this not work? - Can't call method on an undefined value!!!
by LanX (Canon) on May 06, 2013 at 16:08 UTC
    its <code> not [code] done! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: Why does this not work? - Can't call method on an undefined value!!!
by moritz (Cardinal) on May 06, 2013 at 17:16 UTC
Re: Why does this not work? - Can't call method on an undefined value!!!
by graff (Chancellor) on May 07, 2013 at 02:31 UTC
    VMware is a topic about which I know virtually nothing. But apart from that...

    Your code is using modules that don't currently exist on CPAN. Are you using home-grown modules? If so, then you'll have to look more closely at your own local code base for "VMware::VIRuntime" (assuming it's documented), to see whether that helps to figure out what the problem is.

    If you're using modules that used to exist on CPAN, then you should probably look for more recent modules that are currently supported (and might do a better job in terms of what you want to get done).

    Having just browsed CPAN for "VMware" and related things, I noticed that the "See Also" sections of some modules make reference to other modules (like "VMware::VmPerl") that seem to have gone missing, so this is probably a somewhat volatile domain in terms of CPAN module life-spans.

    But maybe the CPAN results for "VmWareESX" might be relevant? (I wouldn't have a clue whether they are or not.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032342]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-07-11 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls