Score:0

Using VMware ovftool to check existence of virtual machine (VM)?

er flag

What is the canonical way to use VMware's ovftool to query to see if a VM exists or not?

If I run this command:

ovftool vi://username@password@myvsphere/mydatacenter/vm/myvm

I might get this response:

Error: Got fault from server: The attempted operation cannot be
performed in the current state (Powered on).
Error: Fault cause: vim.fault.InvalidState

I know I can do the following and then look for "Locator does not refer to an object" but is there a different command or (set of) option(s) I can run that will return a simple true or false or something else concise that does not indicate an error?

ovftool vi://username@password@myvsphere/mydatacenter/vm/avmthatisnothere

Just FYI the above returns this:

Error: Locator does not refer to an object:
vi://username@password@myvsphere/mydatacenter/vm/avmthatisnothere
er flag
A follow up: I ended up using `govc`. It requires vCenter's API, but fortunately for my use-case we were using vCenter: https://github.com/mikeschinkel/govmomi/blob/master/govc/USAGE.md
Score:0
ru flag

You're using the wrong tool. You cannot serve beer with a fork.

VMware OVF Tool is a command-line utility that allows you to import and export OVF packages to and from many VMware products.

To check whether a VM with the name myVM exists you should try PowerCLI:

Get-VM -Name myVM

https://developer.vmware.com/docs/powercli/latest/vmware.vimautomation.core/commands/get-vm/#Default

er flag
Seems strange that a tool that can power-on and power-off a VM is not the right tool to determine if a VMs actually exist to power on or off. That said, it seems like [a huge amount of effort](https://virtualizationreview.com/articles/2017/06/01/how-to-install-and-use-powershell-and-powercli-on-linux.aspx) to use the _"right"_ tool just to test for existence when by side-effect I can use `ovftool` in a much lighter weight manner to check the same thing.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.