VMware Cloud Community
mcescalante
Contributor
Contributor
Jump to solution

createTime not returning?

I am trying to return createTime (the time a snapshot was taken) for each virtual machine.

I've tried traversing the tree just like every other metric, but it won't return it.

Currently, I have this loop.

foreach my $vm_view (@$vm_views) {

        my $snapshot = $vm_view->snapshot;
        print Dumper($snapshot);
        if (defined $snapshot) {
                my $snap_time = $snapshot->rootSnapshotList;
                print @$snap_time;
        print Dumper($snap_time);
        }
}

The Dumper for $snapshot returns me rootSnapshotList, which has createTime inside it.

The Dumper for $snap_time returns me the same thing, but without 'rootSnapshotList'.

If I add ->createTime to the line my $snap_time... it just says cannot call method on unblessed reference... the dumper says bless.

Not really sure what other info is relevant, PLEASE HELP!

Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

Hi,

rootSnapshotList is an array as noted in the vSphere API Ref http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fvim.vm.Snapsho..., you will need to iterate through it to return createTime property.

You can take a look at the snapshotmanager.pl http://www.vmware.com/support/developer/viperltoolkit/viperl41/doc/snapshotmanager.html which is part of the vSphere SDK for Perl and there is a "list" operation which has the code to list all snapshots for a given VM.

View solution in original post

Reply
0 Kudos
2 Replies
lamw
Community Manager
Community Manager
Jump to solution

Hi,

rootSnapshotList is an array as noted in the vSphere API Ref http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc_50%2Fvim.vm.Snapsho..., you will need to iterate through it to return createTime property.

You can take a look at the snapshotmanager.pl http://www.vmware.com/support/developer/viperltoolkit/viperl41/doc/snapshotmanager.html which is part of the vSphere SDK for Perl and there is a "list" operation which has the code to list all snapshots for a given VM.

Reply
0 Kudos
mcescalante
Contributor
Contributor
Jump to solution

Thanks, had JUST figured this out as you responded.

Silly of me not to do a 0 .. $#

For anyone in the future who sees this thread and is having a similar issue, you've got to have the line as

my $i     #iterator

foreach $i (0 .. $#{$vm_view->snapshot->rootSnapshotList}) {

     my $your_var = $vm_view->snapshot->rootSnapshotList->[$i]->createTime #or any other property

}

Wrote that code real quick - it may not compile.

Reply
0 Kudos