Using the sdk for perl I can retrieve info about, among other things, snapshots of the virtual machines hosted on the vmware platform.

I am having trouble returning the right thing from one subroutine to the other.

sub _remove_snap { my ( $vm ) = @_; # skip if no snapshots on vm unless ( defined $vm->snapshot ) { print $vm->name . " has no snapshots, skipping\n"; return; } my $snaps = _find_snapname( $vm->snapshot->currentSnapshot, $vm->snapshot->rootSnapshotList ); print Dumper $snaps; } sub _find_snapname { my ( $ref, $tree ) = @_; my $counter = 0; my @snaps; foreach my $node (@$tree) { # print $node->name, "\t" . $node->createTime . "\n"; if ( $node->name eq $snapname ) { push @snaps, $node } _find_snapname( $ref, $node->childSnapshotList ); } print Dumper @snaps; return \@snaps; }
This code returns this:
$VAR1 = bless( { 'createTime' => '2017-12-07T21:10:30.643627Z', 'name' => '2', 'state' => bless( { 'val' => 'poweredOff' }, 'VirtualMachinePowerState' ), 'description' => '', 'id' => '42', 'snapshot' => bless( { 'type' => 'VirtualMachineSnaps +hot', 'value' => '38-snapshot-42' }, 'ManagedObjectReference' ), 'vm' => bless( { 'value' => '38', 'type' => 'VirtualMachine' }, 'ManagedObjectReference' ), 'childSnapshotList' => [ bless( { 'snapshot' => bless +( { + 'type' => 'VirtualMachineSnapshot', + 'value' => '38-snapshot-43' + }, 'ManagedObjectReference' ), 'vm' => bless( { 'v +alue' => '38', 't +ype' => 'VirtualMachine' }, ' +ManagedObjectReference' ), 'replaySupported' = +> '0', 'quiesced' => '0', 'state' => bless( { + 'val' => 'poweredOff' } +, 'VirtualMachinePowerState' ), 'name' => '3', 'createTime' => '20 +17-12-07T21:11:45.892562Z', 'id' => '43', 'description' => '' }, 'VirtualMachineSna +pshotTree' ) ], 'quiesced' => '0', 'replaySupported' => '0' }, 'VirtualMachineSnapshotTree' ); $VAR1 = [];
The first $VAR1 is from _find_snapname() and the second (empty array ref) from _remove_snap(). I don't understand why the second one is empty, I must be missing something very obvious ...

In reply to trouble matching snapshot info vmware sdk by natxo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.