[libvirt-users] virsh and bash scripts

Erik Skultety eskultet at redhat.com
Mon Jan 8 15:07:12 UTC 2018


On Sat, Jan 06, 2018 at 05:27:52PM +0200, Hetz Ben Hamo wrote:
> Hi,
>
> I'm looking for a way to use virsh to connect to vCenter/VCSA and do some
> simple management of the VM's in case of power loss (I'm planning to run
> the script upon UPS/apcd event of power failure).
>
> Looking through the virsh documentation, I didn't find 2 things:

I'm not familiar with the VCSA solution topology, but virsh is just cli
frontend to libvirt APIs, the documentation you're looking for is here [1].

>
> 1. Login through a script (I don't see any user/password, specially since
> VCSA for example requires to use username at vsphere.local [or your AD domaino

Unless you use the C/Python/Other APIs directly where you can actually specify
a callback that is called during the authentication phase, you're stuck with
the default callback which provides you with a prompt which reads from stdin.

> insteadd of vsphere.local if you connected it to your AD domain])
> 2. Get all the VMs running on the vCenter, not just specific hosts.

you're connecting via the ESX driver (using the type 'vpx' in the URI schema),
which from libvirt's point of view is client-side only which means that we use
the driver to talk to the vCenter. When querying the list of machines, I would
expect the vCenter/ESX server to return the list of all VMs on all vCenter
nodes, if not so, then either our driver needs to be updated to reflect the
changes or the backend API (the ESX server/vCenter) doesn't support this
feature and you'll need to query all the nodes manually.

I never tried using the esx driver, so that's just my understanding of how I
think things are supposed to work, i.e. it's fairly out of libvirt's reach,
since we just call the corresponding remote APIs the ESX provides, there's no
daemon we can control.

Erik




More information about the libvirt-users mailing list