Home > Blogs > VMware {code} > Tag Archives: vSphere

Tag Archives: vSphere

Talking Code: DCLI Interactive Mode

VMware Code is kicking off a brand new series of informational videos that are going to be called ‘Talking Code’. This series is going to take an in-depth look at some of the tools, documentation, example scripts, and more that is available for developers and automation specialists from VMware!

This first video is going to take a look at the interactive mode of Datacenter CLI (DCLI). This is especially important as DCLI recently received a huge update in the form of version 2.9.1!

Talking Code – DCLI Interactive Mode

For more information on DCLI, please see the following page: VMware Code – DCLI

Let us know in the comments what other videos you’d like to see in the future!

Getting Started with the vSphere Automation SDK for Java

There has been another exciting open-sourced release in the vSphere Automation SDK lineup. This time, it is the vSphere Automation SDK for Java!

That means it’s time for another blog post in our series on ‘Getting Started with the vSphere Automation SDKs’. The posts available in the series so far are as follows:

We’ll be taking a look at how to easily get started with this SDK on a Mac. Before diving in, there are a couple prerequisites we’ll need to download and install.

Prerequisites

The first thing we’ll want to do before getting started with this SDK is to clone the repository to the local system. We can do that with the following command:

Example: cloning repo local

Next, we’ll want to make sure we have the appropriate Java Development Kit (JDK) installed and available. The vSphere Automation SDK for Java has been developed to work with JDK 1.8. We can verify which version of Java is available by the following command:

Example: java version output

In this situation, my system doesn’t have Java installed at all. I’ll need to head out to the JDK8 download page to download and install the appropriate version. Once complete, repeat the last command to ensure JDK 1.8 is installed. Verifying and/or updating the JAVA_HOME and PATH variables is the last step to the install process. We’ll start by finding the current value for the JAVA_HOME variable, then updating it, if necessary, to the Home directory of the newly installed JDK. We’ll then repeat that process for the PATH variable as well. This can be done with the following commands:

Example of updating system variables

We will also need to ensure Maven, a build automation tool, is installed. We will use Maven to build out the SDK and the samples from source so we can start using it. My system doesn’t have Maven installed yet, so we’ll go to the download page and install it according to the instructions on Maven’s site. Alternatively, we can do it with the following commands:

Example of installing Maven

The last prerequisite, before starting to user the SDK, is instructing Maven to build out all the samples with Maven. We’ll first use the initialize command, within the cloned repository directory, to pre-stage any dependencies that are not available publicly. We’ll then follow that with install command. This can be done with the following commands:

Example of downloading SDK prereqs and building out SDK from source

We are now all setup to start using the vSphere Automation SDK for Java!

Running Samples

There are quite a few samples which are included with the SDK. Each sample can be run by using its fully qualified class name.

The first example we’ll take a look at is the ListVMs sample. In terminal, from the root of the SDK directory, we’ll call java, enabling assertions with the ‘ea’ parameter, using the ‘cp’ parameter to call the class path of ‘target/vsphere-samples-6.5.0.jar’, then the fully qualified class name. An example of this command is as follows:

Example parameters available for use with the ListVMs sample in the vSphere Automation SDK for Java

Based on the output, we see quite a few parameters that still need to be referenced in order to authenticate and run the sample. The required parameters are server, username, and password. However, there are also some considerations needed around the handling of the vCenter’s certificate. I’m using a lab environment that still has the vCenter’s self-signed certificate in use, so I’ll be using the ‘skip-server-verification’ parameter. Lastly, there are the optional paramaters, most of which are straight forward, but the config-file parameter is a convenient one. For now, we’ll keep it simple and call each parameter as part of the command. I’ll discuss using a configuration file later in this post.

Performing the ListVMs sample in my environment, with all of the required parameters, looks like the following:

Example output when listing VMs

There’s another sample which takes a VM through the lifecycle of power states. This sample can be discovered in the ‘../vmware/samples/vcenter/vm/power’ directory. The public class we’ll be using is ‘PowerLifeCyle’. If we run that without any parameters, we can see that we’ll need to add the ‘vmname’ parameter and call a specific VM by name. Running this sample can be done with the following command:

Example of taking a VM through the lifecycle of power states

The last example we’ll look at is the modifying the memory configured for a VM. This sample can be found in the ‘../vmware/samples/vcenter/vm/hardware/memory’ directory. The public class we’ll be using is ‘MemoryConfiguration’. If we run that without any parameters, we can see that we will again need to add the ‘vmname’ parameter and call a specific VM by name.

This sample will set the RAM to 8GB then enables hot-add. We can go execute this sample with the following command:

Example of memory configuration options

One last thing before wrapping this up, let’s walk through using the configuration file. The configuration file can be any text-based file which contains lines that begin with the parameter names. In the following example, we create a new file and modify the file to include the following lines:

We can now reference this config file in any of the examples to authenticate against a vCenter server. Reusing the ‘ListVMs’ sample, the command to run that again but instead using a configuration file will look like the following:

Example of using the configuration file

Summary

This post shows you how to easily get started with the vSphere Automation SDK for Java. It takes you through the setup of your local development environment, as well as running some of the individual samples. You can then take whichever is most relevant to you and apply to your environment or, pull parts of this code out and use it to automate or integrate as needed.

With our SDKs now being open sourced, we are intent on making sure these samples are of a high quality. If you notice areas of improvement, or come up with some new samples, please feel free to raise issues or pull requests on our GitHub repository.

An Overview of VMware Cloud on AWS APIs

As part of vSphere 6.5 we revolutionized the programmatic interaction of the product by enabling new REST based APIs and Open Sourced SDKs to provide a developer and automation experience which delighted users. Continuing this work and moving into the cloud we are looking to provide an equal if not better experience with VMware Cloud on AWS.

The new vSphere 6.5 REST APIs which are used to manage both new features of the 6.5 release and some existing features were modernized to provide a superior experience, continuing with this experience, the VMware Cloud on AWS APIs are RESTful, making use of CRUD (Create, Retrieve, Update, Delete) based actions and utilizing JSON formatted inputs and outputs for the data structure. The documentation for these APIs will also be available in numerous ways both online and inline.

There are three main APIs, among several others, which users should be aware of that allow you to programmatically access the VMware Cloud on AWS features and surrounding areas to work with the environment and automate or develop to succeed in your use cases:
VMware Cloud Service API Tree

We will be taking a bit deeper look at the first three in the following sections.

Cloud Services Platform API

The Cloud Services Platform (CSP) APIs are available for all cloud services which are offered by VMware. They contain the core features that customers will use when working with multiple cloud services from VMware.

In the context of VMware Cloud on AWS, the main use of the CSP APIs will be to serve as the authentication point. Once authenticated, the authorization token will be valid against this API as well as the VMware Cloud on AWS API. The CSP API also serves as the main point for Organization (Org) and VMware Cloud on AWS console user management. Some of the methods include displaying all the users within an Org, adding users to an Org, and removing users from an Org.

VMware Cloud on AWS API

The VMware Cloud on AWS (VMC) API will be the endpoint for most actions available within the VMware Cloud on AWS console. This API, which is currently in Technical Preview, allows for SDDC management actions like creating or removing SDDCs with a single API call, adding or removing the elastic hardware provided by the VMC service and adding the ESXi hosts to our SDDC, and handling network operations for the SDDC. We can also gather task based information on items which take place in the VMC environment.

Access to the VMC API is also be available in multiple ways. First off, since this API is RESTful, it can be consumed with your preferred programming language or client which can talk REST. The open-sourced vSphere Automation SDKs can be used as well and are available in programming languages like Python, Java, Ruby, and more. This API can then be explored through a built in API Explorer. The features of VMC can also be accessed through the command line with PowerCLI 6.5.4 and a technical preview of the new version of Datacenter CLI (DCLI). DCLI, which is available as a separate download, can be installed on Windows, MacOS, and Linux. More posts are planned to explain these areas in depth in the future so stay tuned!

Deployed SDDC APIs – vSphere API

The last of the APIs are the vSphere APIs. These are the same APIs you already know and love! You will be able to consume these APIs in the exact same way you already do with our on-premises offerings of vSphere. With VMware Cloud on AWS being a managed environment you will of course have limited permissions and certain key differences on areas which you should deploy to but we will dig into these in a future blog post.

Summary

We just reviewed the three API endpoints you will want to become familiar with when accessing VMware Cloud on AWS. The CSP API, which serves as the main authentication point and management point for Orgs and console users. There is the VMC API that is the SDDC management point. Lastly, there are the deployed SDDC APIs themselves which will be the vSphere APIs which hopefully you are already familiar with.

In the next blog, we will cover how to get started using each of these APIs!

Getting Started with the vSphere Automation SDK for Ruby

There has been another exciting open-sourced release in the vSphere Automation SDK lineup. This time, it is the vSphere Automation SDK for Ruby!

That means it’s time for another blog post in our series on ‘Getting Started with the vSphere Automation SDKs’. The posts already available in the series so far are as follows:

We’ll be taking a look at how to easily get started with this SDK on Mac OS. Before diving in, there are a couple prerequisites we’ll need to download and install.

Note: If you’re using this SDK on any other OS, check out the ‘Quick Start Guide‘ section of the GitHub repository for guidance.

Prerequisites

The first thing we’ll want to do before getting started with this SDK is to clone the repo to the local system. We can do that with the following command:
git clone https://github.com/vmware/vsphere-automation-sdk-ruby.git

Cloning the SDK for Ruby Repository

We will then need Ruby to be at version 2.3.1 or better. On this particular system, which is currently running Mac OS Sierra (10.12), we see that it’s currently running Ruby 2.0.0.

Checking the version of Ruby currently installed

In order to obtain the newer version of Ruby, we will need to install the package manager, Homebrew. If you don’t have it already, it can be easily downloaded and installed with the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing Homebrew

Next, we will install the latest version of Ruby available. We will do this, through Homebrew, with the following command:
brew install ruby

Installing the latest version of Ruby via HomeBrew

This SDK also has a couple dependencies which will also need to be installed. These dependencies are called out in the Gem specification file which is located in the root of our cloned repo directory. The Gem spec file is named: vsphere-automation-sdk-ruby.gemspec

In order to easily install all of these dependencies, we will use Bundler. Bundler is used to manage the required gems and which versions of those gems are required. We can install bundler with the following command:
gem install bundler

Installing the Ruby Gem for Bundler

Lastly, we will need to build and then install our Gem. To perform the build, switch to the directory where the vsphere-automation-sdk-ruby.gemspec file is located and run the following command:
gem build vsphere-automation-sdk-ruby.gemspec

Building the Ruby Gem for the SDK

Once complete, we will have the Gem that we’ll need to then install. We can take the Gem filename and run the following command:
gem install vsphere-automation-sdk-2.5.0.gem

Installing the Gem for the SDK

We are now all setup to start using the vSphere Automation SDK for Ruby!

One quick item to note, the SDK’s documentation is available locally as part of the cloned repository.
The API docs are available in the following location: /docs/apidocs/vsphereautomation-bindings
The Samples docs are available in the following location: /docs/apidocs/vsphereautomation-samples

Running Samples

There are a couple samples which are included with the SDK, they are:

  • Connection: Sample framework to successfully connect to the vSphere Automation API endpoint and retrieve the SAML token
  • Tagging: Create vSphere Tag Category and associated tags
  • List_VMs: Create a list of available VMs containing the VM Name, Power State, Number of CPUs, and Memory Size in Megabytes

These are made available through the launcher.rb file in the following directory within the repo: /client/samples/bin/launcher.rb

Included Samples

As additional samples are created and/or contributed from the community (such as the ‘list_vms’ sample was), this will be the place to look for them.

To call each of these samples, we’ll need to call the following file: /client/samples/bin/run_sample

If we run that command alone, it will show an example populated command and the available samples matched to their configuration files within the repo.

Example output from the run_sample command

Each of these samples also offer a help functionality using either the ‘–help’ or ‘-h’ parameter which will display additional parameters for the given sample.

Taking a look at the connection sample, we can run the following command to understand what the sample is looking for in terms of parameters: bin/run_sample connection –help

Displaying the help output for one of the sample workflows

Now, we can create the full command in order to obtain a SAML token and login to the vSphere Automation API endpoint. The example we’ll use is as follows:
bin/run_sample connection -l vcsa01.corp.local -u 'administrator@vsphere.local' -p 'VMware1!' –k

Example of connecting to a vSphere API Endpoint

Moving to the tagging sample, we have the ability to create tag categories and their associated tags. Running an example will look like the following:
bin/run_sample tagging -l vcsa01.corp.local -u 'administrator@vsphere.local' -p 'VMware1!' -k --category-name 'SDKTagCategory' --tag-name 'SDKTag'

Example of creating a Tag Category and associated Tag

Lastly, we’ll use the ‘list_vms’ sample to create a list of the VMs available in our environment. We can do this with the following command:
bin/run_sample list_vms -l vcsa01.corp.local -u 'administrator@vsphere.local' -p 'VMware1!' –k

Example of listing the VMs available in an environment

Summary

This post shows you how to easily get started with the vSphere Automation SDK for Ruby. It takes you through the setup of an entire environment, as well as running some of the individual samples. You can then take whichever is most relevant to you and apply to your environment or, pull parts of this code out and use it to automate or integrate as needed.

With our SDK now being open sourced, we are intent on making sure these samples are of a high quality. If you notice areas of improvement, or come up with some new samples, please feel free to raise issues or pull requests on our GitHub repository.

vSphere Automation SDKs – Open Sourced!

It’s an exciting time! We have started the process of open sourcing our vSphere Automation SDKs! The first ones to be released are the Software Development Kits (SDKs) for REST and Python: https://vmware.github.io/vsphere-automation-sdk

Alan Renouf, the Product Line Manager for the vSphere Automation SDKs (among other things), has a great post detailing the significance of it over on the VMware Open Source blog: https://blogs.vmware.com/opensource/2017/03/09/integration-vmware-vsphere-using-new-open-sourced-software-development-kits

vSphere Automation SDK Open Source Logo

What to Expect

Open sourcing these SDKs are going to have a considerable impact on how they’re consumed, so what should you be expecting with these changes?

The biggest impact: these SDKs are available on GitHub, with no authentication required. Users can clone or download the repository locally or even fork it to their own GitHub account. The use of modern Github integrated tools can ensure these SDKs fit well into your development tooling and procedures.

The first part leads to the next big impact: the frequency of updates. These SDKs being on GitHub allow us to release updates, bug fixes, and other corrections on a much quicker basis!

One of the other big impacts this change is going to have is on contributions. We are actively seeking contributions! Regardless of whether it’s a new sample, an update, or even a request, we want to hear from you! We are dedicated in making these samples relevant to you and making your development experience easier and better than ever before. Please, let us know how we can help you do this.

Getting Started

There are a lot of ways to get started with this new method of access. The easiest way is to check each repo’s README and follow the instructions there.

However, let’s walk through an example. One of the simplest ways, downloading it directly from the SDK’s repo.

Using the vSphere Automation SDK for Python:
Repository Link: https://github.com/vmware/vsphere-automation-sdk-python

Click the “Clone or Download” button, selecting the “Download ZIP” option.
Find the downloaded zip file and expand it.

Downloading the vSphere Automation SDK for Python

Contributions

If you happen to hit an issue when using one of the SDKs in your environment, or if you’re doing something that doesn’t already exist as a sample, there’s a good chance someone else could benefit from that input. Therefore, we highly encourage contributions to these SDKs.

Each SDK will have the contribution and/or issue process documented in the README. However, I’ll provide an overview of both the sample and issue submission process.

Sample Submission:

  • Include information as part of the resource or folder’s README:
    • Author Name (basic contact info)
    • Date
    • Description (high level description)
    • Known Limitations or Dependencies
    • vSphere Version/s Developed and/or Tested (suggested, but not mandatory)
    • SDK Version/s Developed and/or Tested (suggested, but not mandatory)
    • Language Version/s Developed and/or Tested (suggested, but not mandatory)

Contribution Process:

  1. Follow the GitHub process
  2. Use one branch per sample or change-set
  3. Use one commit and pull request per sample
  4. Post the sample output along with the pull request
  5. If including a license with the sample, use the project license

Issue Submission: Each repo has their own “Issues” tab and should be used to submit any issues or requests

  1. Once on the “Issues” tab, click the green “New issue” button
  2. Provide a title and as much detail as possible in the comment section

vSphere Automation Issue Submission

If you’re submitting a sample, we also recommend adding them to the VMware Code Sample Exchange!

Wrap-Up

This transition to open source is a big step for us at VMware. This is also just one of the first steps of many which are focused on helping to enable developers and automation focused admins!

Keep an eye on this blog, the Open Source blog, and especially the vSphere Automation SDK page for all the exciting updates and additional news.

March 16 VMware {code} Town Hall: Your Direct Line to the VMware Product Team Behind the vSphere Automation REST APIs, PowerCLI, ESXCLI and vCLI

Do you wish you could have a direct line back to the product teams at VMware?

Something annoyed you about the product and maybe you never knew where to send your feedback?

Perhaps you just love the product and want to give a “virtual” thanks to the wizards behind the curtains?

Following the vSphere Automation team’s big announcement yesterday, we thought it might be a good idea to give everyone an opportunity to check in with them directly and get your questions answered and feelings heard on this and also the other products worked on by this team.

We’re excited to announce our first-ever VMware {code} town hall! For one full hour next week, the team – including Alan Renouf (@alanrenouf), Kyle Ruddy (@kmruddy) and members of the development teams – will be available to answer your questions and discuss the road ahead:

VMware {code} Town Hall
Thursday, March 16
9-10am Pacific Time
Online on VMware {code} Slack
Channel #vsphere-sdks

How to join:

Hope to see you there. Should be fun!