The code samples provided here are intended as standalone examples. They can be downloaded, copied and/or modified in any way you see fit.
Please be aware that all code samples provided here are unofficial in nature, are provided as examples only, are unsupported and will need to be heavily modified before they can be used in a production environment.
Most code samples can be directly accessed from the NutanixDev GitHub code samples repo. Larger samples will be published via dedicated repos when required.
Please see the License section of this page for information on how these code samples may be used.
These samples require Python 3.7 or later and demonstrate complete, standalone scripts for carrying out common API operations.
For easy sharing of parameters between scripts, most scripts accept their JSON payloads via an on-disk JSON-formatted text file.
Most scripts utilise requests, urllib3, getpass, argparse and json modules.
Repo directory: python
Note: Please follow the usage instructions in this directory’s README.md. This will ensure the required script dependencies are downloaded with this demonstration script. Nutanix Prism
Note: Please follow the usage instructions in this directory’s README.md. This will ensure the associated Cloud-Init userdata and dependencies are downloaded with this code sample.
Note: Please follow the usage instructions in this directory’s README.md. Related Resources
Related Resources
These samples require PHP 7.2 or later and demonstrate complete, standalone scripts for carrying out common API operations.
For easy sharing of parameters between scripts, most scripts accept their JSON payloads via an on-disk JSON-formatted text file.
Repo directory: php
PHP demo to show the creation of Prism Central categories via the v3 Prism Central REST APIs. Utilises “dotenv”, Guzzle and PHP Composer.
These samples are written specifically for use with Bash Shell; please note that modification will be required before use with the sh shell. All scripts are standalone and can be run without any other script dependencies.
All scripts utilise jq, a free sed-like JSON processor. JQ can be downloaded from here.
Repo directory: shell
Note: This code sample is intended for use within a Nutanix CVM (Controller Virtual Machine) SSH session.
These playbooks are provided as examples of how common tasks can be automated using Ansible. Some modification may be required before these playbooks are used
Ansible installation instructions can be found here.
Repo directory: ansible
Note: Please follow the usage instructions in this directory’s README.md. This will ensure the required script dependencies are downloaded with this demonstration script. Nutanix Prism
Note: Please follow the usage instructions in this directory’s README.md. This will ensure the associated Cloud-Init userdata and dependencies are downloaded with this code sample.
Note: Please follow the usage instructions in this directory’s README.md. Related Resources
Related Resources
These code samples and blueprints are provided for use with Nutanix Calm. Please ensure Nutanix Calm is enabled and available before using these code samples.
Repo directory: calm and blueprints
These samples are intended for use with Visual Studio. Visual Studio Community can be downloaded from here.
All C# code samples utilise Newtonsoft.Json, a popular high-performance JSON framework for .NET. Please see here for instructions on installing Newtonsoft.Json into your Visual Studio environment.
Repo directory: csharp
A default installation of PowerShell, e.g. on Windows 10 or Windows 2016 (or later) should have all required packages available.
To run these scripts the PowerShell ExecutionPolicy will need to be set to RemoteSigned. To do this, run the following command in an administrative PowerShell session:
SetExecutionPolicy RemoteSigned
Repo directory: powershell
PowerShell script for use with Nutanix Era. Provisions Linux-based database engines, to call X-Play playbook that set VM categories in Prism Central. To use update
Creates a complete inventory of a Nutanix Cluster configuration using CSV and PowerShell. For usage and disclaimer info, please see the .disclaimer file distributed with
Use the Nutanix Prism Central v3 APIs to batch and launch multiple requests via a single “parent” request.
Use Microsoft PowerShell and the Nutanix Prism Central v3 APIs to list cluster VMs. This basic sample lists the first 20 VMs only i.e. the
A collection of Go code samples, provided by Nutanix Community and staff members.
To run these scripts please download and install Go from the Go website.
Repo directory: go
Automate sending Batch API calls to Prism Central, using GoLang. The script can be executed to send multiple tasks in one call to Prism Central.
Use Go and the Nutanix Prism Element v2.0 APIs to create multiple clones of the same VM. Please make sure to change the script’s variables
A collection of JS code samples, provided by Nutanix Community and staff members.
Repo directory: js
A collection of JSON Payload samples, intended for use with Nutanix API requests.
To use these samples it is suggested than an application such as Postman be used.
Repo directory: json
JSON payload to create a VM using the Nutanix Prism Element v2.0 APIs. Please make sure you replace all {{variable}} instances with values appropriate for
JSON payload to create a Nutanix Flow Network Security Rule a.k.a Security Policy. To use this code sample, please make sure all variable placeholders are
JSON payload to create a CentOS 7 disk image from the publicly available CentOS 7 Cloud Image. Request Parameters The below parameters should be used
JSON payload to send multiple API requests as a single batch. This sample creates 4 virtual machines – 3 simple/shell VMs, and 1 detailed/advanced VM.
JSON payload to create a detailed AHV VM that is then configured with Cloud-Init. All important VM parameters are specified, including base64-encoded Cloud-Init YAML spec.
JSON payload to update an existing AHV VM. “spec” and “metadata” for the existing VM must be obtained first, using a GET request to https://[prism_central_ip_address]:9440/api/nutanix/v3/vms/[vm_uuid].
JSON payload to create a VM that includes details for vCPU, cores per vCPU, RAM and storage. It also specifies the VM should have a
JSON payload to create a basic shell VM. Only the required parameters are included, indicating that the Nutanix APIs should apply system defaults to parameters
A collection of Terraform configurations aimed at demonstrating use of the Nutanix Terraform provider.
To use these configurations it is recommended to reference the Nutanix.dev articled titled “Using the Nutanix Terraform Provider”. Please note this article will available after April 19th 2021.
Repo directory: terraform
All code samples are covered under the Open Source MIT license, as follows:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.