Nutanix AHV: Creating a new VM using PowerShell

3 min read

ThisNutanix AHV week I got a request via Matthijs van den Berg, one of the Nutanix SEs in EMEA. He was working with a Dutch Service Provider that has standardised its complete infrastructure deployment using PowerShell as the glue between components.

This service provider was working with Nutanix AHV and wanted to deploy a new VM based on Powershell. Looking at the current interfaces for Nutanix we can define multiple ways to achieve the same thing.  The following interfaces are available:

  • REST API
  • HTML5 GUI
  • CLI – ACLI & NCLI
  • Scripting interfaces (PowerShell)

The following definitions are from the Nutanix Bible as Steve Poitras already explained this:

REST API

The REST API exposes every capability and data point of the Prism UI and allows for orchestration or automation tools to easily drive Nutanix action.  This enables tools like Saltstack, Puppet, vRealize Operations, System Center Orchestrator, Ansible, etc. to easily create custom workflows for Nutanix. Also, this means that any third-party developer could create their own custom UI and pull in Nutanix data via REST.

HTML5 GUI (Prism UI)

The HTML5 UI is a key part to Prism to provide a simple, easy to use management interface.  However, another core ability are the APIs which are available for automation.  All functionality exposed through the Prism UI is also exposed through a full set of REST APIs to allow for the ability to programmatically interface with the Nutanix platform.  This allow customers and partners to enable automation, 3rd-party tools, or even create their own UI.

CLI – ACLI & NCLI

The Acropolis CLI (ACLI) is the CLI for managing the Acropolis portion of the Nutanix product.  These capabilities were enabled in releases after 4.1.2. The Nutanix CLI is the CLI for managing the Nutanix product and is more heterogeneous across hypervisors.

PowerShell

Windows PowerShell is a powerful shell (hence the name ;P) and scripting language built on the .NET framework.  It is a very simple to use language and is built to be intuitive and interactive.

While most Service Providers pick the Rest API it’s an easy step to use one of the other solutions. Or at least, that’s what you’d expect so I dove into this.. The steps to create a VM on Nutanix AHV using aCLI are straight forward, to create a VM call KBTestVM99 with 2 vCPUs and 2GB of RAM with a NIC in vLAN 100 and a 50GB disk in aCLI you would use:

vm.create KBTestVM99 memory=2G num_vcpus=2

vm.nic_create KBTestVM99 network=vlan.100 

vm.disk_create KBTestVM99 create_size=50G container=default

Doing this in PoSH was a little bit less straightforward but with the AOS 4.6 code (not GA as of now) I was able to achieve the same using the following code:

# kees@nutanix.com
# @kbaggerman on Twitter
# https://blog.myvirtualvision.com
# Created on December 24th, 2015

## VM Creation
# Setting Variables
$Name = "KBTestVM99"
$NumVcpus = "2"
$MemoryMB = "2048"

# Creating the VM
new-ntnxvirtualmachine -Name $Name -NumVcpus $NumVcpus -MemoryMB $MemoryMB

## Network Settings
# Get the VmID of the VM
$vminfo = Get-NTNXVM | where {$_.vmName -eq $Name}
$vmId = ($vminfo.vmid.split(":"))[2]

# Set NIC for VM on default vlan (Get-NTNXNetwork -> NetworkUuid)
$nic = New-NTNXObject -Name VMNicSpecDTO
$nic.networkUuid = "4405198a-8160-49a6-b4ab-ffbde7913f31"

# Adding a Nic
Add-NTNXVMNic -Vmid $vmId -SpecList $nic

## Disk Creation
# Setting the SCSI disk of 50GB on Containner ID 1025 (get-ntnxcontainer -> ContainerId)
$diskCreateSpec = New-NTNXObject -Name VmDiskSpecCreateDTO
$diskcreatespec.containerid = 1025
$diskcreatespec.sizeMb = 51200

# Creating the Disk
$vmDisk =  New-NTNXObject –Name VMDiskDTO
$vmDisk.vmDiskCreate = $diskCreateSpec

# Adding the Disk to the VM
Add-NTNXVMDisk -Vmid $vmId -Disks $vmDisk

 

Of course there’s more to do with this script like accepting vlan IDs and Container names as input and do a cross reference to the networkUuid and the ContainerID but this script was created to show how you can create a VM on Nutanix AHV using PowerShell.

The following two tabs change content below.

Kees Baggerman

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.
Kees Baggerman

Kees Baggerman

Senior Technical Director at Nutanix - Former Citrix CTP - NVIDIA Enterprise Platform Advisor - 15+ years in EUC

Kees Baggerman is Senior Technical Director — Performance & Solutions Engineering R&D at Nutanix, where he leads a global team responsible for defining how enterprise applications are delivered on the Nutanix platform. A former Citrix Technology Professional and NVIDIA Enterprise Platform Advisor, he has spent 15+ years driving EUC strategy and technical direction across architecture, product, and customer success. He has been writing here since 2011 — sharing what he learns at the intersection of platform engineering and enterprise IT.

Similar Posts

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.