Passwordless sudo

 

The Nutanix Calm product is great for automating the deployment of applications stacks. So I’ve been learning Calm by attempting to deploy some LEMP stacks and other application on Ubuntu Images. However I was stuck at trying to issue scripts which needed sudo elevation, being prompted for a secondary password is a pig when trying to script anything.

The quick answer to this is to make sudo passwordless.

You do this by creating a file in /etc/sudoers.d/ (I called mine passwordless) and adding a line …

Replacing <username> with the user you wish to apply the passwordless sudo to.

That’s it, no more being prompted for sudo passwords.

Clone and connect Nutanix Volume Group using PowerShell

Hardev Sangera and I held a breakout session at Nutanix .Next on Tour in London. The session was predominately to demo’s of some of the new features released with AOS5.0. During the session we demonstrated how to present iSCSI storage to a physical workload and then subsequently take a clone of that data and so it could be used to perform development activities on.

Enabling a DBA or developer ‘live like’ data to work with, which  can take hours with traditional methods.

Rather than using the Prism interface to clone the volume group and the iScsi initiator in windows to connect to it, I wrote a PowerShell Script demonstrating the use of  API and the Nutanix PowerShell CMDlets.

Disclaimer : I’m not a professional coder so don’t rip it to shreds when you read it, as there are significant improvements that could be made and it is only to serve as an example of leveraging the Nutanix API.

 

The script to disconnect and remove the Volume Group…

 

Nutanix PowerShell Cmdlets

I’ve just been preparing for a Demo at the Nutanix .Next event in London which is on the 30th March 2017 – Link to register here http://events.nutanix.com/event/?id=1470024841-579ecc89d9db5-579f887683408.

One of the things I’m doing is cloning a Volume Group Presented by Acropolis Block Services. Im doing this by PowerShell so wanted a list of the commands. Just thought I’d share the command I used to obtain it.

 

Look out for the VG Clone Script once it is complete.

Using the Nutanix Rest API v2 with Python to list cluster VM names

Nutanix Rest API has always interested me as it is a very powerful tool. I have only really used it via the explorer, which allows you to test various queries and outcomes.

Rest_explorer

I wanted to see how easy it would be to obtain information from the Nutanix cluster to use in other applications and ‘Real {Men/Women} don’t click’ so I fancied trying my hand at utilising the API via Python.

To kick things off I’ll obtain a list of the VM’s in the cluster this should be as easy as calling the GET VM’s API.

I’ll be using the Python 3.6 interpreter, so the syntax may differ slightly on earlier versions (ie 2.x)

First I need the request module to perform the REST actions, I’m using pip to install this…

I start by creating the base url, in this example I will utilise v2.0 of the Nutanix Rest API

where 192.168.0.157 is the cluster IP address. The base URL can differ between CE and retail versions of Acropolis so check your’s using the Explorer.

I can then construct the Request with authentication and header details :

now I can request the data as JSON from the path I wish to use which are listed using the explorer :

these are appended to the base url and stored in the data variable as JSON.

Using the rest api explorer we can see what the JSON will return by clicking the ‘Try it out’ button.

My test has returned 3 items labeled ‘entities’ which have different sub attributes.

I want to return a list of all the VM’s running on my cluster so I can use the following to loop through each entity and print the attribute of ‘name’

So in the above e becomes each entity and name references the sub value within each entity and returns

which are the 3 VM’s I have running in my test cluster.

Full source code below…

Summary

The above exercise is just to demonstrate basic REST API usage and should get you started. In later posts I’ll be looking at using the API to perform actions. Stay Tuned.