VMware Cloud Community
MRCrispin
Contributor
Contributor

Is PowerCLI the right tool for this task?

Hi everybody.  I've been tasked to "research VMware APIs for provisioning virtual machines".  The general idea is that we will have "stateless" VMs that can be downloaded from our site into a customer's virtual infrastructure, either as new nodes or as replacements for existing nodes (that is, shut down a VM, replace its hard disk with an updated one, and restart it).  From our customer's point of view, they just push a button in our web-based GUI to update a node in a cluster running our product.

I've identified that we need to be able to authenticate to the virtual infrastructure, (possibly) enumerate the VMs that can be manipulated, start a VM, shut down a VM, download a replacement VM.

This all seems to be pretty basic.  If I were building a text-based Internet protocol to do all this, the protocol description would probably be only about 5 pages of text.

The problem is that I know very little about VMware other than the most basic use of it to run a single VM on a workstation.  Most of the documentation that I have read assumes much greater knowledge about using VMware, and the nomenclature used by VMware, than I currently possess. I'm narrowly focused on addressing my task and moving on; I doubt that I will be doing substantial VMware API work in the future.

In going through the documentation (there is SO MUCH documentation, but very little "VMware 101" type documentation), I ran into the description of PowerCLI and skimmed through the PowerCLI Administration guide.  It seems that the solution to my task is to tell the GUI developers "call the PowerCLI cmdlets from your scripts; my task is done."

I doubt very much that it's that simple.

So my first question is, "am I barking up the wrong tree?"  Is PowerCLI the right tool for this task?

My second question is that I'm almost certainly missing something very important.  So, "what am I missing here?"

Thanks in advance for any guidance you can give.  I hope that all I need is to be pointed in the right direction.

0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership

I think that PowerCLI is a good choice for this task. All you want to do can be easily done with PowerCLI cmdlets, like Get-VM, Start-VM, Stop-VM and Set-HardDisk. From PowerCLI you can use the entire vSphere SDK, so anything you can do with the vSphere SDK can be done from PowerCLI.

What you are missing is a way to use PowerShell/PowerCLI as an ASP.NET language. There are some solutions available. One of them is PowerShell ASP.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
bulletprooffool
Champion
Champion

I totally agree with Robert here - PowerCli is the way to go.

For the add-on code that you're battling with, look into using VMware's 'Onyx' to help with code generation.

This should fill all the gaps.

PowerCli is pretty simple to learn - especially if you have some scripting experience - and the guys on the community (like Robert above and LucD) are extremely helpful.

If you need help, as long as you run a search on the community first and actually show an attempt at trying to write the code you need, the guys on the community will help - just don't post expecting people to write your code for you if you haven't made an effort to try at all.

Good luck - enjoy the journey.

One day I will virtualise myself . . .
MRCrispin
Contributor
Contributor

OK, so the good news for me is that I just have to produce a prototype and someone else with much more Windows scripting experience will do the real work.  The bad news for me is that I have to do the prototype.  What's more, it has to be a program or script that runs with just command line arguments and otherwise takes no input; it will be started by code that invokes the [program|script] and then reads output until the [program|script] exits.

So, minimal seems best here.  I'll let the Windows gurus worry about error handling, and even enumerating the VMs.

I can't help but think that Install-VMHostPatch is really the right thing, rather than using Import-VApp.  But my task clearly says to replace an existing VM image with a new image.  Can Install-VMHostPatch do that?

If it isn't, am I correct that the sequence is: Connect-VIServer, Import-VApp with a new name (perhaps the version is in the name), Stop-VApp (old name), Start-VApp (new name), Remove-VApp (old name)?

Do I have to use New-VApp, e.g., to copy the state of the old one, before doing an Import-VApp?

And what is the difference between a VApp and a VM?  Since this is supposed to be a "stateless VM", the term VApp sounds like what I want(?).  Anyway, I didn't see a way to import a VM.

0 Kudos
MRCrispin
Contributor
Contributor

Now this is getting more bizarre.  I'm told that Install-VMHostPatch is to update the ESX server itself.  Why would the administrator of a VM on the ESX server want to do that (much less be allowed to do that)?

Yet I've found no other operation which seems to offer the ability to retrieve an update from outside.

Remember, the whole idea is for a VM to have an operation that will get the ESX server to download the latest version of the VM from the VM's vendor, shut down the VM, replace the VM with the new image, and restart the VM.  VMHostPatch sounded like the right direction.

There is also vagueness at my end for whether this is a VM or a VApp.  Apparently, I am supposed to say whether we package as a VM or a VApp.  I haven't a clue.

0 Kudos