Mac OS X Guide

The steps in this section are specific to Mac OS X.

Please use the links in the sidebar to skip to a specific section.

Project Structure

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.

Option 1 - Graphical/Simple

  • 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.

    ../_images/osx_gui_filesystem.png

Option 2 - Terminal/Advanced

  • Use the terminal to create the directory structure. For this option, please continue below.

  • Open the Terminal application, located under the Utilities folder within Applications in Finder

  • Ensure your current path is your user account’s home directory:

    cd ~
    
  • Create a directory for our projects:

    mkdir projects
    
  • Change to our new directory, create a demo folder for the first project and list the contents:

    cd ~/projects
    mkdir project1
    cd project1
    ls -la
    

    For now, the project1 directory is empty.

    The screenshot below shows this process being run on Mac OS X as a user called nutanix.

    ../_images/osx_filesystem.png

Summary

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.

Languages

The Python website has packaged OS X binary installation media for Python 3.7. For this reason, the steps are very simple.

  • Download the 64-bit installer from the Python website

  • Install Python 3.7 from the downloaded package; accept all defaults as the OS X installer does not include any customisation options

    ../_images/osx_python_install.png
  • 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.

    ../_images/osx_verify_python37.png

    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):

    xcode-select --install
    
  • Install Homebrew with the following command:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  • 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:

    ../_images/osx_install_php72.png

Summary

With this section complete and depending on your operating system, you now have various languages installed:

  • Python >= 3.6

  • PHP >= 7.2

  • C# (for Windows 10)

The next step will be to look at code editors.

Editors

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.

The editors will be:

Assumptions

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.

Linux, OS X and Windows 10

Microsoft Visual Studio Code

Sublime Text 3

  • As a first step, download Sublime Text 3 for your operating system

  • Install from the downloaded package (.bz2 for Linux, .dmg for OS X, .exe for Windows 10)

Summary

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.

Source Control - Optional

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.

Option 1 - Graphical/Simple

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.

    ../_images/github_desktop_first_run.png
  • Continue below if you would like to create your first repository now

  • Select Create a New Repository on your hard drive…

    ../_images/github_desktop_create_repo.png
  • 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.

    ../_images/github_desktop_create_repo_2.png
    ../_images/osx_github_readme.png
    ../_images/osx_github_desktop_ready.png
  • 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.

Pushing to GitHub

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.

../_images/github_desktop_publish_ready.png

Option 2 - Terminal/Advanced

  • 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

    ../_images/create_github_repo.png
  • 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
    
    ../_images/osx_brew_git.png
  • 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
    
    ../_images/osx_verify_git.png

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.

    git config --global user.name "FIRST_NAME LAST_NAME"
    git config --global user.email "your_name@your_domain.com"
    

    Note

    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:

    git config --global --replace-all user.name "FIRST_NAME LAST_NAME"
    
  • Change to the projects directory on your Mac; this assumes you have completed the steps in the Structure section of this lab:

    cd ~/projects
    
  • If you created the project1 folder at the start of this lab, change to it now:

    cd project1
    
  • If you have not yet created the project1 directory, create it now, then enter it:

    mkdir -p ~/projects/project1
    cd ~/projects/project1
    

Right now the project1 folder will be empty and is not yet recognised as a Git project directory. Continue below to fix that now.

  • In the page you still have open after creating the project1 repository, note you have been given a number of commands.

  • Enter the commands exactly as shown in your browser - make sure to change <your_github_username> and enter your credentials when required!

    echo "# project1" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/<your_github_username>/project1.git
    git push -u origin master
    

    A screenshot of the entire process is shown below; note that your name, email address (etc) will be different.

    ../_images/osx_git_entire_process.png
  • Now, on the GitHub site, checking the contents of your new project1 repository will show a single file - README.md as created earlier:

    ../_images/browser_git_project1.png
  • In future, after making changes to your project code, the following commands can be used to commit your changes and push them to GitHub.

    git add --all .
    git commit -m 'Meaningful commit message here, e.g. a description of what changed'
    git push -u origin master
    

Summary

With this section complete you now have Git and/or the GitHub Desktop application installed. This has enabled you to:

  • Manage different versions of your software

  • Keep those versions offsite in the cloud-based SaaS GitHub, if required

API Testing

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.

Step 1 - Download and Install 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.

Step 2 - First Postman Run

  • 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.

    ../_images/postman_first_run.png
  • 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.

Step 3 - Using Postman

  • 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.

    ../_images/postman_first_run_welcome_highlights.png
  • From 1 to 8, the highlighted sections are as follows.

    1. Each tab is contained within a request tab. This makes it easy to organise each request and its properties for later use.

    2. 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).

    3. Showing GET right now, this is where we can change the request type. For example, common requests types are GET, POST, PUT and DELETE

    4. 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>

    5. 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.

    6. 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.

    7. 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.

    8. 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.

Summary

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.

Extras - Optional

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.

Wrapping Up

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.

Lab Resources

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.