natxoasenjo's Posts

I have these 2 subroutines: sub _remove_snap {     my ( $vm ) = @_;     # skip if no snapshots on vm     unless ( defined $vm->snapshot ) {         print $vm->name . " has no snapshots, skip... See more...
I have these 2 subroutines: 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 @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 );     }     return \@snaps; } And I cannot seem to return the snapshot information from _find_snapname back to _remove_snap. If I print with Dumper at the end of _find_snapname right before the return \@snaps statement, I see the correct info displayed on screen, but when dumping it on the _remove_snap subroutine, then I get an empty $VAR1 = []; I am obviously missing something obvious, but I do not see it. Any help greatly appreciated.
hi, you will probably want to take a look at reconfigvm_task in the sdk, more specifically, the virtualmachinefileinfo.
quick and dirty: my $vmname = shift; my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vmname}, properties => ['name','runtime.powerState','config']); ... See more...
quick and dirty: my $vmname = shift; my $vm = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {'name' => $vmname}, properties => ['name','runtime.powerState','config']); my $config = $vm->{'config'}; print $vm->{'name'}, "\t",  $config->{'files'}->{'vmPathName'}, "\n";
probably (I have no fc or iscsi initiators on esxi on our environment) poking around config.storageDevice.hostBusAdapter? my $hosts_view; $hosts_view = Vim::find_entity_views(     vie... See more...
probably (I have no fc or iscsi initiators on esxi on our environment) poking around config.storageDevice.hostBusAdapter? my $hosts_view; $hosts_view = Vim::find_entity_views(     view_type => 'HostSystem',     properties    => [ 'name','config.storageDevice.hostBusAdapter', ], ); print Dumper $hosts_view; Edit: I added a iscsi initiator just for testing and it is indeed in there: 'iScsiName' => 'iqn.1998-01.com.vmware:hostname-590171e5', As i do not have any fibre channel, I have no means of getting this info for that, but it should be quite similar.
glad you got it working
try $hosts = exec("/path/to/your/perl /var/www/cgi-bin/gethosts.pl --server  --username  --password ''"); not shell_exec
Could you post the code you tried?
Could you add your hostinfo.pl command? I run it like this and cannot reproduce your issue: perl hostinfo.pl --config ~/.visdk/visdkrc_esx_work --server hostname
As far as I can see this info is available using cim (https://www.vmware.com/support/developer/cim-sdk/) I found this reference in the virtually ghetto blog (http://www.virtuallyghetto.com/2011/0... See more...
As far as I can see this info is available using cim (https://www.vmware.com/support/developer/cim-sdk/) I found this reference in the virtually ghetto blog (http://www.virtuallyghetto.com/2011/05/cim-monitoring-caveat-with-esxi.html) : "there is also a Perl SDK for CIM/WSMAN as part of the vCLI installation and if you are using vMA, you can find some great examples under /usr/share/doc/vmware-vcli/samples/WSMan" You can also take a look at the checksensorhealth.pl script in vmware-vsphere-cli-distrib/doc/samples/WSMan/checksensorhealth.pl If I get some free cycles I will try to get this working, nice to have indeed, but I cannot give you any time path, sorry.
to get the scsi lun info, you probably need https://www.vmware.com/support/developer/converter-sdk/conv61_apireference/vim.host.ScsiLun.html You could probably take a look at https://communities.... See more...
to get the scsi lun info, you probably need https://www.vmware.com/support/developer/converter-sdk/conv61_apireference/vim.host.ScsiLun.html You could probably take a look at https://communities.vmware.com/docs/DOC-11932 to get you started. If you post the code you have tried, then people will be more motivated to give you better answers, I think,  ;-), specially since you just asked this in stackovervlow (http://stackoverflow.com/questions/36424196/vmware-perl-sdk-finding-free-luns-of-esx-hosts-on-cluster)
Yes, indeed, free hypervisor for home lab. Ok, I did not know this limitation, so in order to test my scripts I need to fire up the vpn to work or to keep reinstalling esxi every x days. I do not... See more...
Yes, indeed, free hypervisor for home lab. Ok, I did not know this limitation, so in order to test my scripts I need to fire up the vpn to work or to keep reinstalling esxi every x days. I do not have the resources to justify buying a license. Thanks for answering this question so promptly.
using vicfg-nas I am unable to create/remove a nfs datastore on my home lab running esxi 6. Is this unsupported? Listing them works ok. I can create/remove nfs datastores using the vcenter client... See more...
using vicfg-nas I am unable to create/remove a nfs datastore on my home lab running esxi 6. Is this unsupported? Listing them works ok. I can create/remove nfs datastores using the vcenter client just fine, but this is a bit annoying.
By far the easiest way to install the Perl sdk is to download the tarball, extract it and copy vmware-vsphere-cli-distrib/lib/VMware/share/VMware to a path in your @INC (for a fedora installation... See more...
By far the easiest way to install the Perl sdk is to download the tarball, extract it and copy vmware-vsphere-cli-distrib/lib/VMware/share/VMware to a path in your @INC (for a fedora installation the standard Perl has this for @INC:   @INC:     /usr/local/lib64/perl5     /usr/local/share/perl5     /usr/lib64/perl5/vendor_perl     /usr/share/perl5/vendor_perl     /usr/lib64/perl5     /usr/share/perl5 So pasting the folder vmware-vsphere-cli-distrib/lib/VMware/share/VMware to any of those paths makes it available to any user in that system. You can find your @INC running perl -V (usually at the end of the long output).
sure, in this discussion https://communities.vmware.com/message/1512863#1512863 you can see how it's done
You have a typo on declaring $cv_ref, you spell summary wrong. this works for me: my $vm_view = Vim::find_entity_views(     view_type  => 'VirtualMachine',     filter    => { 'guest.gue... See more...
You have a typo on declaring $cv_ref, you spell summary wrong. this works for me: my $vm_view = Vim::find_entity_views(     view_type  => 'VirtualMachine',     filter    => { 'guest.guestState' => 'running' },     properties => [ 'summary.customValue', 'name', ], ); for my $vm ( sort { $a->name cmp $b->name } @$vm_view ) {     my $cv_ref = $vm->{'summary.customValue'};     next unless defined ( $vm->{'summary.customValue'} ) ;     print $vm->name . "\n";     for ( @$cv_ref ) {         #next unless defined $_->value;         print "key: ", $_->key, "\tvalue: ", $_->value, "\n";     } } $perl /tmp/kk vmname key: 201    value: bladibla key: 203    value: globalbladibla
no, you need to retrieve the 'name' property of the vm, you just retrieved the 'summary.customValue' . So try this: my $vm_view = Vim::find_entity_views(     view_type  => 'VirtualMachine'... See more...
no, you need to retrieve the 'name' property of the vm, you just retrieved the 'summary.customValue' . So try this: my $vm_view = Vim::find_entity_views(     view_type  => 'VirtualMachine',     filter     => { 'guest.guestState' => 'running' },     properties => [ 'summary.customValue', 'name', ], );
ok, I think I understand where you want to get to. If all vm's have the custom field key not not the value, then you need to skip those without a defined value. Then in the @$cv_ref loop use some... See more...
ok, I think I understand where you want to get to. If all vm's have the custom field key not not the value, then you need to skip those without a defined value. Then in the @$cv_ref loop use something like this: for ( @$cv_ref ) {     next unless defined $_->value;   ... } But I just checked and all the vm's here have the key and only one has a test value, and my original code works, so in fact skipping the empty values is in my case indifferent. Apparently adding a customfield to one vm adds it to all vm's, just does not fill the value field. 2nd edit: I tried with a global customfield and same thing, it keeps working.
nearly there. In the for loop you need to skip those vm's without custom fields: for my $vm ( sort { $a->name cmp $b->name } @$vm_view ) {     my $cv_ref = $vm->{'summary.customValue'};... See more...
nearly there. In the for loop you need to skip those vm's without custom fields: for my $vm ( sort { $a->name cmp $b->name } @$vm_view ) {     my $cv_ref = $vm->{'summary.customValue'};     next unless defined ( $vm->{'summary.customValue'} ) ;     print $vm->name . "\n";     for ( @$cv_ref ) {         print "key: ", $_->key, "\tvalue: ", $_->value, "\n";     } } o, and you need to retrieve the 'name' property of the vm as well if you copy paste that
This works for me: my $vm_view = Vim::find_entity_views(     view_type => 'VirtualMachine',     filter    => { 'name' => name of your vm' },     properties => ['summary.customValue', ]... See more...
This works for me: my $vm_view = Vim::find_entity_views(     view_type => 'VirtualMachine',     filter    => { 'name' => name of your vm' },     properties => ['summary.customValue', ], ); for my $value ( @$vm_view ) {     my $cv_ref = $value->{'summary.customValue'};     for ( @$cv_ref ) {         print "key: ", $_->key, "\tvalue: " , $_->value, "\n";     } }
not very pretty, but works: my $ntpservers = $host->{'config.dateTimeInfo'}->ntpConfig->server;     for ( @$ntpservers ) {         print $_ , "\n"; }