This post was authored by Mike Wronski, Solutions and Systems Engineering at Nutanix
Recently I was allowed to participate in the Nutanix Hackathon 4.0. Each year Nutanix sets aside as least one week where engineers are encouraged to form teams and work on ANY cool idea surrounding our technology that they might like. In many cases, these sessions lead to new products or feature enhancements. This year they added customer facing systems engineers to bring the voice of our customers closer to these projects.
My team was working on some network security functions and as part of that work, we wanted to leverage the APIs and automation capabilities built into our AHV to create, deploy, and configure virtual security appliances.
As you may already know, Nutanix has an extensive set of RESTfull APIs for managing our software. What you may not know is that when using our native virtualization, we also provide a full set of APIs for managing the virtual configuration of things like storage, networking, and VM provisioning. Others have covered the basics of these APIs in detail and the documentation can be found via the Prism UI or on my.nutanix.com
As of our 4.7 release, we added the ability to customize Linux and Windows VMs via the Prism GUI and via our APIs and Cloud-init. In this article, I will be explaining the use of Cloud-Init to customize Linux VMs.
What is Cloud-Init?
[img]https://d1qy7qyune0vt1.cloudfront.net/nutanix-us/attachment/1845i76FBAD3B70F95EB3.png[/img]Cloud-init is a set of scripts and utilities that provide powerful techniques for carrying out actions on a cloud instance at boot time. Originally designed for Ubuntu Linux running in Amazon EC2 it is now widely available and supported by many popular Linux distributions and major public and private cloud providers.
For cloud-init to work, your Linux distro must have the cloud-init packages installed. For this example and this blog post I used CentOS 7.
The configuration consists of a metadata and userdata section. Both sections are a combination of YAML markup and raw text or text encoded binary files. The metadata section contains host specific information like instance ID, hostname, and interface configuration. Userdata is all other configurations. This series of posts will cover the Config Drive V2 datasource using a mounted ISO9660 CD-ROM drive that is implemented by automation in Nutanix AHV.
Configuration files can be made of many different sections or modules. There are modules for package management (apt, yum), SSH key exchange, automation tools (puppet, chef), and catch alls that allow creation of arbitrary files. For complete module documentation see the documentation at http://cloudinit.readthedocs.io/en/latest/topics/modules.html.
In my example we will complete two basic tasks:
- Set the host and domain name
- Configure the network by creating the required configuration files
- Bring up the newly configured network interface
The userdata section is delimited by #cloud-config which is then followed by module commands.
hostname: cloud_init_test fqdn: cloud_init_test.nutanix.com write_files: - path: /etc/sysconfig/network-scripts/ifcfg-eth0 content: | DEVICE=eth0 BOOTPROTO="none" NETMASK="255.255.254.0" IPADDR="10.0.0.10" GATEWAY="10.0.0.1" ONBOOT="yes" runcmd: - [ifdown, eth0]
- [ifup, eth0]
Cloud-Init Via Prism UI
In part 1, I will be showing how to use cloud-init using the Prism UI. This method is best for mostly static configurations where basic customization is desired. I will cover use of the Nutanix REST API in part 2. The API is better suited for programmatic construction of the cloud-init userdata configuration as part of automated cloning operations.
To keep things simple, I’m starting with a clean minimal install of Centos 7 on a VM. The image has the cloud-init package installed. This is done with a simple “yum install cloud-init” after the minimal install completed. I will use this as a “template” and then use cloud-init to customize any clones.
Start by cloning the template VM called “Cloudinit”
From the clone VM dialog, scroll down in the options and check “Custom Script”. Which will reveal additional options that are used for customizing the VM.
Within the Custom Script section we can see multiple options:
- ADSF Path - Point directly to a file on the Nutanix filesystem that contains the metadata
- Upload A File - Allows uploading the metadata file from the Prism user’s desktop
- Type or paste script - directly type the metadata required.
- Files to Copy - Add a set of files to copy from the Nutanix file system into the VM.
A couple of console commands verify that the hostname is set and the file was created.
This completes part one on using cloud-init to customize VMs in Nutanix AHV. There are many examples and lots of documentation available that cover the wide array of configuration and customization that can be accomplished. In the next post, I will cover a similar exercise using the REST APIs and a Python script.
Nutanix Web Console Guide: https://portal.nutanix.com/#/page/docs/details?targetId=Web_Console_Guide-Prism_v4_7:wc_linux_vm_customize_with_cloudinit_wc_t.html
Cloud init Documentation: http://cloudinit.readthedocs.io/
Ubuntu Documentation: https://help.ubuntu.com/community/CloudInit
Disclaimer: This blog may contain links to external websites that are not part of Nutanix.com. Nutanix does not control these sites, and disclaims all responsibility for the content or accuracy of any external site. Our decision to link to an external site should not be considered an endorsement of any content on such site.