2

Before we had the VCSA (Vcenter Server Appliance) we had a Windows Vcenter Server.

We had the PowerCLI installed locally.

There, we could say

Get-VM -Name * | Sort-Object | %{
....

to get a list of all VMs registered in Vcenter.


Now we have the Appliance.

I installed the vMA (management assistant) too.

I registered the vcenter appliance, I am successfully connected to it, but I am unable to simply retrieve a list of VMs like above.

It always wants me to connect to a single ESXi host to perform a listing.

Now to me that seems like a step backward.

How would you do this?

Would you use vMA at all? Maybe use vCLI? Or stick with PowerCLI, but then I would need again to install a Windows machine just to run my scripts.....

3 Answers 3

2

I have no experience with the vma, but I suppose it has the vmware Perl SDK installed for you (according to this post virtually ghetto it should). In it you have lots of utils and I think this one is the one you are looking for:

vidiscovery.pl

If you do not wish to enter the credentials every time, then you need to setup the credendial store first.

[edit] Actually, I just tried it and while it kind of works, it is very slow because it gets all the info about every entity. Not very efficient. So I just wrote a very small script and this is all it takes:

#!/usr/bin/perl

use strict;
use warnings;

use VMware::VIRuntime;

# read/validate options and connect to the server
Opts::parse();
Opts::validate();
Util::connect();

my $vm_views =
  Vim::find_entity_views(view_type => 'VirtualMachine',
                       properties => ['name'], );

foreach  my $view ( sort @$vm_views) {      
  print $view->{'name'}, "\n";
}

# disconnect from the server
Util::disconnect();                                  

This presupposes that you have a $HOME/.visdkrc file in place with the correct info:

VI_PROTOCOL=https
VI_SERVER=fqdn
VI_SERVICEPATH=/sdk
VI_USERNAME=username
VI_PASSWORD=pwd

And as you said you have the vma, all the libraries should already be there for you. This script gets me all the vm's (just their names in under 1 second). If you do not have a CA in place and your virtual center has a self signed certificate you should set this envvar first or the Perl lwp library will bomb out when running the script:

export PERL_LWP_SSL_VERIFY_HOSTNAME=0
1
  • Hey, I'll accept your answer because it is an actual answer to the question. Info to everyone: I am looking at the VCenter DB directly for this info (see my own answer). No need to have a VMA lying around just for this.
    – Marki
    Oct 29, 2014 at 9:06
3

I'd use a Windows PC or Server with PowerCLI installed... PowerCLI is where the momentum is with VMware, so the expectation is that you'll have a Windows system available to interface with it.

So while it's possible to install VMware without a Windows dependency, it turns out that Windows is actually a dependency :)

You could also use the vCenter API, depending on what you're planning to do with the list of virtual machines...

Also see: Is it possible to deploy VMware vSphere 5.5 without Windows?

3
  • I guess I will then use a "quick" solution like vcsa:~ # /opt/vmware/vpostgres/1.0/bin/psql --pset pager=off --pset footer=off --command 'SELECT file_name FROM vpx_vm;' -U vc VCDB | tail -n +3 | head -n -1 | awk -F/ '{print $(NF-1)}' 2>/dev/null| sort | uniq
    – Marki
    Sep 10, 2014 at 13:00
  • What exactly is the goal? What will you be doing with the list of VMs? Is it input for another process?
    – ewwhite
    Sep 10, 2014 at 13:01
  • 1
    I have a script that checks if the VMs are present in the tape backup, disk backup, etc. It's for consistency checks. Just reading the vcenter db will do fine here I guess.
    – Marki
    Sep 10, 2014 at 13:23
0

There is another solution: you can simply access the vCenter DB directly for this kind of stuff.

For reference, here is a one-liner that can be executed directly on the VCSA using the postgres client:

/opt/vmware/vpostgres/1.0/bin/psql --pset pager=off --pset footer=off --command 'SELECT name FROM vpx_vm_config_info ORDER BY name;' -U vc VCDB | tail -n +3 | head -n -1 | sed 's/^[ ]*//g'

I'm using head, tail and sed to filter out nasty headers, empty lines and spaces at the beginning of the line respectively. Maybe there is a more elegant and shorter way to do that, but I don't care.

Pros:

  • No extra VM (vMA) necessary to obtain a list of VMs.
  • Fast.

Cons:

  • Somewhat hacky.
  • And probably very unsupported.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .