To get started, first we will create a simple directory structure to store our projects.
Note
You are welcome to use your own structure or location for projects. Please be aware that you’ll need to modify the paths as they are encountered in each lab.
Use Finder for this step - a suggested directory structure is shown below. Please note this structure has been created in the current user’s home directory. After creating the directory structure please continue to the next step - Languages.
With this section complete you now have a simple but usable directory structure to hold your projects.
The next step will be to install specific language versions that are both recommended for overall development and required for the Developer Marketing labs.
Install Python 3.7 from the downloaded package; accept all defaults as the OS X installer does not include any customisation options
Open the Terminal application and verify Python 3.7 is installed by running the following commands:
which python3.7
python3.7
The screenshot below shows the verification process for Python 3.7, after installing from the downloaded binary package.
Note
When you have finished using the Python REPL (read-eval-print loop), the exit() statement can be used to exit to the terminal.
It is recommended to install command line packages on OS X by installing and using Homebrew. Homebrew is a popular package manager for OS X and streamlines what can sometimes be quite convoluted processes.
Install the Homebrew prerequisites by running the following command (note this process can take some time):
Install PHP 7.2 by running the following command and following the instructions. It’s worth noting that this command will look like it is doing a lot of stuff - and it is - but please be patient and let the command complete.
brew install php@7.2
Verify PHP 7.2 is installed by running the following command:
php --version
A screenshot of the PHP verification process is shown below:
For those new to development, it is strongly recommended that you first read the Editors - Additional Information section. It includes important information about editor choice and built-in editors that should be understood, but is optional for the completion of this lab.
Before getting started, consider that having all the language frameworks installed is great, but at some point you’re going to want to write code.
The steps in this section cover the installation of three of the most common and popular editors. A later section in this lab will cover some optional but recommended language-specific customisations.
Please be aware that this section isn’t a how-to guide for installing the applications themselves; it is assumed that readers will be familiar with how to install applications.
With this section complete and depending on your operating system, you can now use one of the below editors or IDEs to start writing code:
Sublime Text 3
Microsoft Visual Studio Code
Microsoft Visual Studio Community (if using Windows 10)
The next step will be to look at some optional but recommended tools that can make efficiency and best-practice improvements to your development workflow.
Here’s a quick summary of what we’ve accomplished so far.
Created a simple but usable directory structure to hold our projects i.e. projects directory within our user’s home directory
Ensured Python >= 3.6 and PHP >= 7.2 are installed
(Windows 10 only) Ensured PowerShell and C# are installed
Installed a suitable editor that is designed to write code, not “just” text (please remember to go through the Editors - Additional Information section, if you are new to development)
Note
Source control, while strongly recommended, is NOT required to complete Nutanix Developer labs.
One of the key parts of software development is making sure changes are tracked, version history is maintained and, as a bonus of sorts, backups are kept. However, please be aware that pushing source code to GitHub should not be considered a primary backup.
There are a number of software packages and services that provide these capabilities; in this lab we will concentrate on Git SVN and the related cloud service, GitHub.
Note
For those new to software development, the two points below can help understand the basic differences between Git and GitHub.
Git is a version control system that provides the management of software version history. For example, project1 could have two versions, each of which is tagged with a commit ID. This commit ID identifies the software that has been committed to the version control system (Git) and allows authorised people to clone from and update a specific version, while leaving other versions untouched. The commit history for a project is stored in a Git repository.
GitHub is a cloud-based SaaS (Software as a Service) product that allows software developers to store and manage their Git repositories. For example, a GitHub account named jane_doe could be the owner of the project1 repository; this repository is “pushed” to the GitHub cloud service at various intervals.
Mac OS X has a graphical GitHub tool provided by the GitHub team. This is what we’ll use in this section.
Open the GitHub Desktop website and download the latest version for Mac OS X
Extract the downloaded .zip file and install the GitHub Desktop application by moving the .app file to the Applications folder
Run GitHub Desktop and, if you don’t have an existing GitHub account, create one using the Create your free account option. This step isn’t 100% mandatory but is strongly recommended.
Continue below if you would like to create your first repository now
Select Create a New Repository on your hard drive…
Enter a name for the repository e.g. project1, select a path and check the options as required.
Note
These screenshots assume you are using the directory structure created in the earlier “Project Structure” section of this lab.
For this example, our project is named “project1”. By checking the option for “Initialize this repository with a README”, selecting a “Git ignore” and License option we’ll see in moment that GitHub Desktop has created various files in our project directory.
The “MIT License” shown in this example is a very commonly-used license as it puts very limited restriction on code reuse. Please see the Wikipedia MIT License page for more info. Additional information on other license types can be viewed on the Wikipedia Software Licenses page.
Note the Open in Sublime Text option? If you have completed the Editors section of this lab, you can simply click the Open in Sublime Text button and have your project immediately opened and ready for editing in Sublime Text! If you installed Visual Studio Code instead of Sublime Text, this button will be worded accordingly.
Likewise, the Show in Finder option is a quick way of jumping straight into the directory structure for your project, ready to manage the files as necessary.
At this point, as indicated by the GitHub Desktop application, the new repository is only available on your local system. It is not available on GitHub.com and cannot be cloned from GitHub onto another development machine.
Note
The Publish repository button, shown below, allows us to publish the repository. However, this will attempt to create a new repository in your GitHub account and, if you have followed this lab to this point, will return an error saying the project1 repository exists. This can be “fixed” by changing the project1 repository name in the GitHub Desktop application, although that means the local and remote repositories will have different names. Please be aware of this when creating local repositories with the same name as existing GitHub repositories.
Before getting started, go to GitHub and, if you don’t already have one, create a username for yourself. This will be used in upcoming steps.
Login to GitHub, go to https://github.com/<your_username> and, under the Repositories tab, use the New button to create a repository called project1; this is temporary so you are welcome to delete it later
Whether or not the repository is private is up to you but please note that public repositories can be viewed by ANYONE - don’t store anything secret in them!
Leave the Initialize this repository with a README, .gitignore and Add a license options as default for now
After creating the repository, leave the following page open; you will be copying commands from it in a moment
On your PC/laptop, open the Terminal application
Install Git by entering the following command. Please note this section assumes you have completed the Languages section of this lab.
brew install git
That’s it! The following two commands will ensure Git is installed, while also telling us which version of Git we have installed:
which git
git --version
On OS X systems where the user has opted to use the terminal, the following example steps should be followed to carry out GitHub operations.
Telling Git your name and email address is important; they are used to identify who makes changes to Git repositories. Set your name and email address by running the following commands, making sure to change “FIRST_NAME LAST_NAME” and “your_name@your_domain.com” to your own name and email address.
In some instances these commands can only be run once. If you receive an error about multiple values during any of the commands above, the –replace-all parameter can be added to override the existing settings. For example:
Now that you have a number of key tools and applications installed, it’s time to look at how API requests can be tested. As with most topics in development, there are many ways to do this. For our setup lab, we will concentrate on what is probably the most popular tool for API testing - Postman.
From the Postman site, please download the installer for your chosen operating system. At the time of writing this lab, the current version is 7.5.0 for Linux, OS X and Windows.
Please now start Postman for the first time. If this is the first time you have started Postman, you’ll be presented with a screen suggesting you create a Postman account. While this is not mandatory for the Nutanix Developer Marketing labs or even for Postman use in general, it can be a useful addition for using Postman on multiple machines.
If you already have a Postman account, please feel free to sign in using the Sign In link provided.
If you prefer to skip signing up and want to use Postman without an account, please click the Skip signing up and take me straight to the app link.
Note
The screenshot actions shown through this lab section will function the same way, logged in or not. Also, the screenshots shown were taken with Postman set to the ‘Dark’ theme. The theme can be changed by clicking the settings “spanner” icon and choosing dark from the Themes tab.
Although we could create an API request immediately, this lab is aimed at getting ready for upcoming labs and articles. For now, take note of the highlighted Request link, but please don’t click it, yet.
Instead, click the X button to close the currently open window.
The screenshot below highlights key areas that we’ll use in upcoming labs. These are the most important areas to be familiar with, although Postman has an enormous amount of functionality outside of “just” API requests.
From 1 to 8, the highlighted sections are as follows.
Each tab is contained within a request tab. This makes it easy to organise each request and its properties for later use.
The + button is how we’ll create new requests. The … ellipsis button can be used duplicate the current tab, re-open recently closed tabs (and more).
Showing GET right now, this is where we can change the request type. For example, common requests types are GET, POST, PUT and DELETE
The URL for the request. For example, Nutanix REST API requests typically start with something like this: https://<ip_address_or_fqdn>:9440/api/nutanix/<api_version_or_name>/<entity>
The Authorization tab is where we can enter the username and password for our requests. When working with the Nutanix RESTS APIs, all requests are sent with Basic Authentication i.e. a username and password combination.
The Body is where we can setup request “payload”. A request payload will typically contain parameters or additional information that a specific API request requires. An example could be the same of the new VM you are creating via API.
The Send button does exactly what the name suggests. It takes all previously-configured settings and sends the request to the desired IP address or DNS name.
Lastly, the large response field is where the JSON-formatted API response will be shown. Using the response field, we can see if the response was successful, if it failed, why it failed or, if everything went well, what the response itself contains.
With this section complete you now have Postman installed and ready to use! The next section will cover some extra tools and utilities that can be useful when working with APIs.
In addition to what we have covered so far, there are many other tools that are useful for different types of development and scripting.
These tools can aid in the inspection and management of code-related activities, although the usefulness of each will very much depend on the size of your environment and your own specific requirements.
For the Nutanix Developer labs, these are all considered optional, but are still recommended nonetheless.
The Optional Tools section, covering multiple operating systems, can be found in the Extras - Optional section.
Thanks for taking the time to complete this lab - we hoped it was fun and educational.
An important consideration is there’s no correct way setup every development environment, especially in terms of directory structures, editor and customisations.
However, if you have come this far, you now have a usable environment to get started with the Nutanix Developer labs.
We also have a growing collection of labs that demonstrate other helpful developer-centric concepts. Please see the Nutanix Developer Portal Labs page for more info.
For further information on this and other technologies interesting to developers, please see Nutanix Developer Portal. There will you find code samples, documentation and a regularly updated blog covering differnt Nutanix technologies.