Solved

Execute Script Inside AHV VM?

  • 19 March 2020
  • 8 replies
  • 2334 views

Badge

Is there a way to execute a script (or PowerShell script/command) inside a newly created AHV VM which does not have an IP address yet?  The VM has Nutanix Guest Tools installed.

I’m looking for automating the creation of a new VM.

In VMware, I use the Invoke-VMScript command.  I didn’t know if Nutanix had something similar? Thanks!

-TimG

icon

Best answer by JeremyJ 23 March 2020, 16:13

Hi @TimothyGaray ,

You can include execution of a cloud-init script during VM creation or VM cloning. You said you are looking to automate VM creation so this should suit your purpose. Look for the guest-customization portion of the VM POST API body, here: 
nutanix.dev/reference/prism_central/v3/api/vms/postvms/ 

This API method is functionally the same as the “Custom Script” option in the Create VM UI from Prism Central, described in the Prism Central Guide or the Prism Web Console Guide

There is not currently a direct parallel to VMware’s Invoke-VMScript cmdlet. I don’t know the inner workings of that cmdlet but if it functions without network connectivity it must either use console access via API or the VM backdoor built into VMware Tools.

Nutanix Guest Tools relies on TCP/IP network connectivity as it does not utilize or create a backdoor access to VMs in the way that VMware Tools does. There currently is no API method to run commands on an AHV VM. Still like you said you’re looking at VM creation so cloud-init is the standard method of running a script to customize a Linux VM, like sysprep for windows (also supported) and should suit your purpose. 

View original

This topic has been closed for comments

8 replies

Userlevel 4
Badge +5

Hey @TimothyGaray 

Maybe for VM creation automation, you can use our product CALM 

The following guide will help you get an overview of CALM

https://portal.nutanix.com/page/documents/solutions/details/?targetId=RA-2093-Nutanix-Calm:RA-2093-Nutanix-Calm

Go through this blog to get a brief overview of calm 

https://next.nutanix.com/blog-40/nutanix-calm-the-what-and-how-of-calm-blueprints-31480

Hi

You could check if the following article helps

https://portal.nutanix.com/page/documents/details/?targetId=Web-Console-Guide-Prism-v58:wc-vm-create-acropolis-wc-t.html

Userlevel 3
Badge +4

Hi @TimothyGaray ,

You can include execution of a cloud-init script during VM creation or VM cloning. You said you are looking to automate VM creation so this should suit your purpose. Look for the guest-customization portion of the VM POST API body, here: 
nutanix.dev/reference/prism_central/v3/api/vms/postvms/ 

This API method is functionally the same as the “Custom Script” option in the Create VM UI from Prism Central, described in the Prism Central Guide or the Prism Web Console Guide

There is not currently a direct parallel to VMware’s Invoke-VMScript cmdlet. I don’t know the inner workings of that cmdlet but if it functions without network connectivity it must either use console access via API or the VM backdoor built into VMware Tools.

Nutanix Guest Tools relies on TCP/IP network connectivity as it does not utilize or create a backdoor access to VMs in the way that VMware Tools does. There currently is no API method to run commands on an AHV VM. Still like you said you’re looking at VM creation so cloud-init is the standard method of running a script to customize a Linux VM, like sysprep for windows (also supported) and should suit your purpose. 

Userlevel 1
Badge +1

Is the guest-customization available in the PowerShell cmdlet New-NTNXVirtualMachine?

I am primarily looking at creating Windows VMs.  I’ve based my efforts from this script:  Create-NTNXVM.ps1

Thanks for the info, I will look into this as an option.

Userlevel 3
Badge +4

Tim,

You can find the documentation for the PowerShell cmdlets here. I linked directly to the relevant section.

I believe this will be the optional argument “VmCustomizationConfig”. I’m not sure of the syntax but hopefully this gets you a step closer.

Userlevel 1
Badge +1

To start, I’m just trying to deploy a VM from the gui using my unattend.xml file.  Once I get that to work then I will try to get it working from PowerShell.

When I choose to upload a file and click save, it gives me an error.  I’ve tried several different xml files but it is not letting me save.

 

 

Userlevel 1
Badge +1

It must have something to do with the content of the file itself.  I tried copying and pasting into the box and got the same error.  I typed just a simple command in the box and then it saved just fine.

Userlevel 1
Badge +1

Picky, picky!

I used this:  http://www.windowsafg.com

It puts some comment text at the beginning with some notes.  When I took that out then it went fine.

<!--*************************************************
Windows Server 2016 Answer File Generator
Created using Windows AFG found at:
;http://www.windowsafg.com

Installation Notes
Location: Test
Notes: Notes Section
**************************************************-->