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

Tag Archives: REST

VMware Cloud on AWS Developer Center Updates

VMware Cloud on AWS does a tremendous job at enabling our automation experts, developers, and DevOps teams. With a robust set of RESTful APIs, open-sourced SDKs, then capping it all off with the Developer Center located directly in the Cloud Console, access has never been easier. One of the key features of VMware Cloud on AWS is the more frequent update cadence. This allows us to release enhancements on a more regular basis, of which the Developer Center is also included.

With that said, I am happy to announce some of the latest updates to the Developer Center!

API Explorer Redesign

The API Explorer is one of the easiest ways to start learning, modeling, and even using the VMware Cloud on AWS RESTful APIs. It has received several extremely nice updates! After clicking on the “API Explorer” tab, you’ll notice immediately how the layout has been changed. The new side bar allows us to easily switch between the API namespaces as well as auto-populate parameter fields. These may seem like minor updates, but they really help to streamline its usage.

Let’s take an example: we need to list out the logical networks within a particular SDDC, in this case the “CPBU-TMM” SDDC.

If you’re consuming the REST calls directly through an SDK, REST API client, or a programming language, you will need to perform the following calls to retrieve that information:

  1. Obtain the Org ID: GET /orgs
  2. Obtain the SDDC ID, using the Org ID: GET /orgs/{orgID}/sddcs
  3. Obtain the logical networks, using both the Org and SDDC IDs: GET /orgs/{orgID}/sddcs/{sddcID}/networks/4.0/sddc/networks

If you’re using the API Explorer, thanks to the new side menu, we can consolidate that down to a single call!

VMware Cloud on AWS Developer Center Updates - API Explorer

From the above example, you can also see the other new addition in the form of a yellow warning bar. This is just a friendly reminder that the API Explorer is running against your live environment. If you make an API call in the API Explorer, that call will actually run. If you delete something, it really will get deleted! Just keep that in mind as you’re exploring these APIs.

Code Sample Updates

The Code Samples section has also received some updates! This section has been updated to reference the VMware Code Sample Exchange. Therefore, as samples are added to the VMware Code Sample Exchange, those samples will start being populated within the Code Samples tab. We can see several examples which have been created in the example below.

VMware Cloud on AWS Developer Center Updates - Code Samples

SDK Updates

The last of the updates is to the SDKs section. The layout has been updated to match the look and feel of the other tabs. It’s the same great information, just with a consistent look and feel!

VMware Cloud on AWS Developer Center Updates - SDKs

Summary

The VMware Cloud on AWS Developer Center is a great resource which provides a central location to access all kinds of automation and developer based information. The Developer Center is also receiving updates on a regular basis to provide optimized access to all of those resources. The latest update adds a redesigned API Explorer, integrated Code Samples with the VMware Code Sample Exchange, and a consistent theme through all of the available sections.

Let us know in the comments what your favorite feature of the Developer Center is and what functionality you’re most looking forward to us adding!

VMware Cloud on AWS Integrations with CloudFormation

The latest update to VMware Cloud on AWS has some real gems in it for developers and automation engineers. As well as the introduction of the Developer Center (which is amazing). It’s such a terrific resource, I’m finding myself using it all the time! The other big news was the addition of an Open Sourced Github repository to showcase VMware Cloud on AWS integrations written by both VMware and the community at large.

The first of these integrations is the support for CloudFormation and Terraform integrations.

In this blog post we’re going to walk through how easy it is to create a software defined data center (SDDC) using the CloudFormation template available in the VMware Cloud on AWS Integration Examples repository. Please note, this will require an AWS account and may incur AWS charges.

First things first, we need to get access to the template. We can clone the repository locally with the following command:

CloudFormation Stack Creation

In order to deploy our SDDC with CloudFormation, we’ll need to start by logging into the AWS Console and checking to make sure we’re in the Oregon region. If you’re not in that region, there is a drop-down box towards the top right-hand side with a site name that’s located between your user account and the “Support” drop-down. Click on the drop-down and select “US West (Oregon)”.

Example: Selecting the Oregon Region

We’ll now want to go to the CloudFormation service. We can find the service by clicking on the “Services” drop-down and locating it in the “Management Tools” section. Alternatively, just type “CloudFormation” in the AWS services search box on the main screen of the console.

Once in the CloudFormation service, we will want to create a new stack by clicking on the “Create New Stack” button. This stack will be used to deploy our SDDC that will be based on the template we’ll import on the next screen.

Example: Creating a new CloudFormation Stack

As part of the stack creation process, we’ll need to either create a new template or select an existing template. We can upload the template we retrieved from the GitHub repo by choosing “Upload a template to Amazon S3” then clicking on “Choose File”. Browse to the location the repo was cloned to, select the “vmc-aws-cloud-cf-template.txt”, and click “Next”.

Example: Choosing the repository sourced template

On the next screen we will need to specify a stack name. In this case, I used “VMWonAWS-CF” as the stack name.

Example: Assigning the new stack a name

For the “Options” screen, there is nothing to update, so we can click “Next”. On the last screen, review the details and check the box that you “acknowledge that AWS CloudFormation might create IAM resources”. We’re now ready to create our stack by clicking the “Create” button!

After few moments, we should see a screen like the following indicating that the stack creation has been successfully completed.

Example: stack creation process

SDDC Creation

We’ve now laid out the groundwork to deploy our new SDDC. One piece of which is the result of the stack creation, in the form of a new Lambda function. We’ll use this function to input our SDDC criteria and then ultimately deploy our new SDDC.

While we’re still in the CloudFormation service, we’ll want to click on our newly created stack to retrieve the details. Once on the “Stack Detail” page, expand the “Resources” section. There we see the IAM Role and Lambda function. Click on the physical ID of the Lambda function, which will take us to the function’s page.

Example: Examining the newly created stack resources

Once on the newly created Lamda function page, scroll down to the “Environmental variables” section. This section is where we need to input the criteria for the SDDC variables:

  • connected_account_id: Enter the AWS account this SDDC should be connected to.
    Note: This is the ID for the account which can be pulled from the API with the following:
    Method: GET /orgs/{org}/account-link/connected-accounts
    Property: ID
  • email: Enter an email address which you would like notified when the process has completed.
  • name: Enter the desired name of the SDDC
  • numOfHosts: Enter the number of desired hosts. (Minimum is 4)
  • orgId: Enter the Org ID for which the SDDC will be assigned. (This is available in the VMware Cloud Console in the “Support Info” tab)
  • region: Enter the desired region. (Case sensitive format: US_WEST_2)
  • customer_subnet_ids: Enter the desired subnet ID for VPC traffic.
    Note: This is the ID for the VPC subnet which can be pulled from the API with the following:

    Method: GET /orgs/{org}/account-link/compatible-subnets
    Property: subnet_id
  • user_refresh_token: Enter the creating user’s OAuth Refresh Token.
    Note: This is available in the VMware Cloud Console by clicking your username then “OAuth Refresh Token”.
  • vpc_cidr: Enter the desired subnet to use that corresponds with preferred management subnet. (Default is 10.2.0.0/16)

Example: Filling in the SDDC variables for the lambda resource

With all of our variables now input, we’re ready to save and run our function. First, click “Save” then click “Test”. On the “Configure test event” pop out, give the test event a name and click “Create”.

Example: Creating a lambda test event

Next to the “Test” button is a drop-down list of events. Make sure that list is set to our previously created test event and then click “Test” again. If everything was set properly, we should see a response like the following:

Example: lambda test event results

We can note from the above image that the response is a task. If we source out the ID, we can then follow along using the tasks API until the creation is complete. Alternatively, we can also watch the deployment process on the SDDCs tab of our Cloud Console.

Example: VMware Cloud on AWS Cloud Console results

Summary

The latest update to VMware Cloud on AWS introduced a couple great features for developers and automation specialists as well as a way for you to share your integrations. This blog covered the newly released integrations with CloudFormation. We showed how to access the CloudFormation template in the VMware Cloud on AWS Integration Examples repository. We then walked through how to easily get started deploying SDDCs in VMware Cloud on AWS using the CloudFormation template.

Get started with it today and let us know how you’re planning on integrating this into your existing workflows in the comments below!

Getting Started Using the vSphere Automation SDK for Python with VMware Cloud on AWS

The vSphere Automation SDK for Python has recently received some exciting updates. These updates add the ability to easily develop against and automate VMware Cloud on AWS! There are even samples to list organization information, manage SDDCs, and lots of networking functionality!

Let’s take a look at how to easily get started with this SDK on a MacOS system. Before diving in though, 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 the SDK Repository Locally

Next, we’ll need to install the package manager, Homebrew. Using Homebrew will allow us to easily download and update additional programs. It can be easily downloaded and installed with the following command:

Example: Installing Homebrew

Now, we’ll install Python in the recommended version of 3.6. It’s worth noting that MacOS comes with a version of Python already installed. However, it is generally an older version (normally, Python 2.7) and is used for some system related tasks. Due to that, it is best not to modify that version or the defaults.

Utilizing our package manager, we’ll install Python 3.6 with the following command:

Example: Installing Python 3.6 Using Homebrew

It’s also recommended to isolate your development environments from each other so, we’ll setup a virtual environment and jump into it. We can do that with the following commands:

Example: Create and Enter a Virtual Environment

Then, we’ll install the SDK requirements. They’re listed within the root of the SDK folder in the file labeled: requirements.txt. After checking out which requirements are necessary, we’ll install those requirements by way of the following command while in the root of the SDK folder:

Lastly, we need to update the PYTHONPATH variable. This allows Python to be able to use the SDK helper methods. We can do this with the following command:

One other item worth mentioning is an IDE. This will make editing, running and debugging the code a lot easier to deal with. I generally use Visual Studio Code, which is available here.

Let’s get started using some of the samples that have been included with this SDK.

Obtaining Refresh Token

The VMware Cloud on AWS APIs use an OAuth refresh token for authentication. These have to be created through the Cloud Console. Once logged into the Cloud Console, click the drop-down on the top right-hand corner that’s by your name. From there, click on the ‘OAuth Refresh Token’ button. If you don’t already have a refresh token available, there will be a blue link to create a new token. Afterwards, you’ll have a refresh token and be ready to authenticate into the VMware Cloud on AWS APIs.

Example: Obtaining the VMware Cloud on AWS OAuth Token

Obtaining Organization Information

The most important thing you can do when getting started is making your Organization (Org) ID easily accessible. This ID is referenced in almost every API method VMware Cloud on AWS has. If we browse through the SDK folder structure, we’ll see there’s an example we can use to retrieve information about the Orgs. There is a Python package named ‘organization_operations.py’ in the ‘samples/vmc/orgs’ directory.

Example:

Example: Obtaining Org listings and detailed information about an Org

We can see in the results above this example performs a couple tasks. First, we receive a list of all the Orgs this refresh token is associated with. Second, we get some additional information about the first Org that was returned.

Obtaining SDDC Information

The next most important thing we can obtain is information about the SDDC/s this Org has. However, at the time of this blog release, that functionality wasn’t explicitly available. Let’s see how to do this in the REPL, or Python’s interactive interpreter:

Example: Using the REPL to obtain SDDC Information

I think this ability is something that will be quite helpful as part of the example SDDC package. Adding it is as easy as adding the following to the ‘create_delete_sddc.py’ file:

Example: Obtaining a list of SDDCs in an Org

However, you won’t need to do that. This SDK is open-sourced and I was able to submit a pull request to get it added in already! As part of the PR, we updated the file name to be ‘sddc_crud.py’ and it is available in the ‘samples/vmc/sddc’ directory.

Logical Network Tasks

Last example, let’s run through some tasks for logical network administration. There’s a sample for this as well. The ‘logical_network_crud.py’ package will create a new logical network, list all of the logical networks, list only the newly created logical network, and then delete the newly created logical network. This file is available in the ‘samples/vmc/networks/’ directory.

Example:

Example: Logical Network Workflow to create, list, and delete an object

Summary

This post shows you how to easily get started with the vSphere Automation SDK for Python with VMware Cloud on AWS. 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.

If you’ve missed any of the prior posts, here are the others in this ‘Getting Started’ series with our open-sourced SDKs:

Enabling Developers in VMware Cloud on AWS

The latest release of VMware Cloud on AWS is here and it has something quite exciting built in for the automation experts, developers and DevOps teams. As part of this release, we are introducing a brand-new Developer Center. This area is a great resource allowing developers to get up and running quickly with VMware Cloud on AWS.

Developers can gain access to this information front and center as a new tab in the VMware Cloud on AWS console!

VMware Cloud on AWS Developer Center

The VMware Cloud on AWS Developer Center consists of several sections, each with the goal of helping to make the development and automation experience and learning easier.

API Explorer

The API Explorer section brings easy access to interact directly with the RESTful APIs available from the Cloud Services API and the VMware Cloud on AWS (VMC) API. These APIs are presented by way of an interactive API browser with some very nice integrations making it easy to work with VMC. The API Explorer being internal to the Cloud console allows us to use the existing refresh token to authenticate. We can also automatically populate certain fields, such as the Organization ID, to help improve the experience of learning and using these APIs. Learning the API and seeing the responses from within the API Explorer could not be easier with the ability to “Execute” these APIs and see the live responses.

Developer Center - API Explorer

Code Samples

The next section is focused on code samples. These are curated directly from the samples written by both VMware and the community in a variety of formats. These samples could be written in Python, PowerShell, be a Postman collection or other integration code samples provided on the VMware Code Samples Exchange.

Developer Center - Code Samples

SDKs

There is a wide variety of software development kits (SDKs) available to interact with the VMware Cloud on AWS APIs and the deployed SDDC products. The SDK section provides easy access to each of these open-sourced SDKs that are available on GitHub. There are also links to the documentation, samples, and even the ‘Getting Started’ blog post for each SDK!

Developer Center - SDKs

Downloads

The last section is called Downloads. This section is where there will be a wide variety of resources available. There will be command line resources like Datacenter CLI (DCLI) and PowerCLI. Also, there will be links to provisioning tool resources from Terraform and CloudFormation.

Developer Center - Downloads

Summary

The VMware Cloud on AWS Developer Center is a fantastic new resource that’s presented front and center in the Cloud console! Whether you’re an automation expert, developer, on a DevOps team, or a mix of all the above, this is going to be the best place to get up and running with the VMware Cloud on AWS APIs. You will be able to use the integrated API Explorer for discovery, access the open-sourced SDKs that can be used against this endpoint, have links to VMware and community contributed code samples, and direct links to download other related resources like PowerCLI and CloudFormation templates.

Getting Started with the vSphere Automation SDK for Perl

We are going to keep the ‘Getting Started’ series going on using the vSphere Automation SDKs. This time, we will be taking a look at the SDK for Perl.

If you’ve missed any of the prior posts, here are the others in the series:

Let’s take a look at how to easily get started with this SDK on a Windows 10 system. Before diving in though, 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: Clone vSphere Automation SDK for Perl Repo Locally

We also want to make sure Perl is available on the local system. The supported versions are Active Perl 5.14+ or Stawberry Perl 5.24.1.1+. For these examples, I’ll be using Active Perl which can be downloaded directly from their site: Active Perl

Example: Installing Active Perl

We will then need to make sure a couple Perl packages are installed and available. These can be installed with the following commands:

Example: Installing Additional Packages as Prerequisites

Next, this SDK also depends on some capabilities from the vSphere Perl SDK. We will need to login to the My VMware portal, download the executable, then install it from the following link: vSphere Perl SDK

We have one more step concerning the vSphere Perl SDK install. We also need to make sure the ‘python27.dll’ file is available in the vSphere Perl SDK’s folder as follows: ..\Perl\lib\VMware

The following code can be used to easily copy that file to the proper location:

Example: Copy Python27.dll to Appropriate Place for Perl Usage

Last part of the prerequisites is to configure the environmental variable PERL5LIB to look for modules in the newly cloned SDK directory. The following directories need to be specified:

  • ..\lib\runtime
  • ..\lib\sdk
  • ..\samples

The following code was used to configure the PERL5LIB environmental variable for my lab:

Example: Configuring the PERL5LIB Variable

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

Running Samples

There are a handful of samples that are already included with this SDK. The samples are separated by the API namespaces into different directories and then presented as scripts. We’ll be looking at running some of the samples from the vCenter directory.

The first example we’ll run is the List VMs sample. This sample can be found in the ‘..\samples\Vcenter\Vm’ directory. There are a couple sample scripts here, which also include deleting a VM and performing some power actions.

Example: Displaying Example Perl Scripts

If we run the ‘list_vms.pl’ sample as is, we will receive back the appropriate parameters to successfully complete the call. Those parameters would be username, password, and server name.

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

Example: Running the ListVMs Sample Script

There’s another example in the VM folder which allows us to modify the power state for a given VM. However, this sample will take a given VM through all of the available power states. Again, running the sample without any parameters will give us the required parameters. We can see that we’ll need to also add parameters for the VM name and cleanup. The cleanup parameter is used to return the VM to the last state it was in.

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

Example: Running the VM Power Lifecycle Script

The last example we’ll take a look at is the creation of a new VM. We’ll take advantage of one of this new API’s features and create a new VM using defaults. This means the API fills in any parameters we do not specify with values based on what Guest OS has been specified. It’s also import to note that the Guest OS has been hardcoded in the sample to be ‘Windows_9_64’. This can be found on line 71 of the ‘default_vm.pl’ script. Additional Guest OS types can be found in the API documentation: Guest_OS Types

We’ll start by moving to the following directory: ..\samples\Vcenter\Vm\Create\DefaultVM Running the ‘default_vm.pl’ script will show us a number of parameters we’ll need to specify. These parameters include names for the following: VM, Datacenter, Cluster, VM folder, datastore. There’s also the authentication and cleanup parameters. In this case, giving the cleanup parameter a ‘True’ value will remove the newly created VM.

Performing the Create New Default VM sample in my environment, with all of the required parameters, looks like the following:

Example: Usage of the CreateDefaultVm Sample

Summary

This post shows you how to easily get started with the vSphere Automation SDK for Perl. 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.

Getting Started with the vSphere Automation SDK for .NET

We are going to keep the ‘Getting Started’ series going on using the vSphere Automation SDKs. This time, we will be taking a look at this SDK for .NET.

If you’ve missed any of the prior posts, here are the others in the series:

Let’s take a look at how to easily get started with this SDK on a Windows 10 system. Before diving in though, 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: Clone vSphere Automation SDK for .NET Repo Locally

The other things we’ll need is .NET Framework 4.5 and Visual Studio 2015 or newer. I’ll be using Visual Studio 2017. On Windows 10, .NET Framework 4.5 should already be available. If it’s not, you can download it directly from Microsoft at the following link: Microsoft .NET Framework 4.5. If you don’t already have Visual Studio, it can be downloaded through the following link: Visual Studio

The next thing we need to do is build out the samples in Visual Studio. We start this process by opening Visual Studio. Now we can click on “File”, “Open”, then click “Project/Solution”. From the new Explorer window, browse to the root directory of where the SDK repo was cloned, then select and open the ‘vSphere-Samples.sln’ file.

Example: Adding SDK Samples to Visual Studio

Note: This process may take some time and if there are any missing dependencies found in the Visual Studio install, it will prompt to install those items.

We will be ready to finish building out the samples once the vSphere-Samples solution has been presented in the Solution Explorer. We’ll then right click on “Solution ‘vSphere-Samples’ (17 projects)” and select “Build Solution”. After a few moments there should be a message on the bottom information bar indicating “Build succeeded”.

Example: Build Solution for the included samples

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

Running Samples

There are a handful of samples already included with this SDK. The samples are separated by the API namespace into different directories and presented as projects. We’ll be looking at running some of the samples from the vCenter directory.

The first example we’ll take a look at is the ‘ListVMs’ sample. We start in the Solution Explorer, expanding ‘vcenter’, ‘vm’, and finally the ‘list’ directory. We can now see a ‘ListVMs’ project. We will want to right click the project and click ‘Set as StartUp Project’.

Example: Configuring the 'Set as Startup Project' Option

Prior to running the sample, we need to populate the sample with some properties such as which vCenter Server to connect to and with what credentials. We can find what the available properties are by clicking on the ‘Debug’ menu and then selecting ‘Start Without Debugging’.

Example: Retrieving Parameter Options through Start command

We should receive a command prompt window that gives us the available properties.

Example: Output from ListVMs Sample

In order to pass those parameters, we’ll need to open up the properties of the project. Once open, select the ‘Debug’ tab and look for the ‘Start options’ section. The ‘Command line arguments’ text box is where we’ll be specifying the parameter values. The parameters for my environment end up looking like the following:

Example: Populating Sample with Parameters for Start command

With the parameters now laid out, we’re ready to actually run the sample!

Example results after hitting the ‘Start’ button:
Example: Output from the ListVMs Sample

Alternatively, we can also run the built executable for the ListVMs sample. It is located in the following directory: ..\vmware\samples\vcenter\vm\list\ListVMs\bin\Debug

Example code:

We can also make modifications to an existing VM’s configuration. One example would be to update a VM’s CPU configuration, so let’s take a look at the CpuConfiguration sample. This project is under ‘vm’ then ‘hardware’. This sample is already configured to increase the CPU count to 2 and to enable CPU Hot Add. These options can be modified in the source code (CpuConfiguration.cs) at line 71 and 81, respectively.

This time we’ll run the sample directly from the executable. The first time we run it, without adding any parameters, we can see that we need our standard authentication parameters but we also need to specify the VM name. Running this sample in my environment looks like the following:

Example: Modify CPU Configuration of a VM with the CpuConfiguration Sample

The last example we’ll take a look at is the creation of a new VM. We’ll take advantage of one of this new API’s features and create a new VM using defaults by using the CreateDefaultVM project. This means the API fills in any parameters we do not specify with values based on what Guest OS has been specified. It’s also import to note that the Guest OS has been hardcoded in the sample to be ‘Windows_9_64’ on line 38 of the source code (CreateDefaultVm.cs). Additional Guest OS types can be found in the API documentation: Guest_OS Types

The project for this sample is located under ‘vm’ then ‘create’. However, we will again be running this sample directly from the executable. Running the executable without any parameters shows that we will need some additional parameters specified. These parameters include names for the following items: datacenter, cluster, vmfolder, and datastore.

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

Example: Usage of the CreateDefaultVm Sample

Summary

This post shows you how to easily get started with the vSphere Automation SDK for .NET. 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.

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.

vSphere Automation SDKs Updated for VMware Cloud on AWS

The vSphere Automation SDKs have recently received an exciting update! These open-sourced SDKs can now also interact with the VMware Cloud on AWS service. The first two SDK languages updated to include this feature set is Python and Java. The remaining SDK languages will follow soon.

The VMware Cloud on AWS service offers a couple different RESTful APIs to interact with. The updated SDKs will focus on the VMware Cloud on AWS (VMC) API, as well as provide the authentication method through the Cloud Services Platform (CSP) API. To find out more about the APIs available as part of the VMware Cloud on AWS service, see this blog post: An Overview of VMware Cloud on AWS APIs

On this initial release, both the Python and Java SDKs include a handful of sample frameworks. These include the following functions:

  • Listing all Organizations associated with a user
  • Creation and removal of an SDDC
  • Managing the host count for a deployed SDDC

Let’s take a look at a couple of these in action.

vSphere Automation SDK for Python

One of the vSphere Automation SDK for Python samples has the functionality to perform two methods. The first will list all of the organizations the user’s refresh token is associated with. These orgs will be displayed by ID and display name. The second will list more detailed information for the first organization, such as ID, display name, name, create and updated dates, and SLA. This sample can be executed with the following command:

Python SDK Sample to list Org information

This SDK also has a new way to interact with the API and that is through the interactive interpreter! This can be done by creating the service object using the ‘create_vmc_client’ function while passing our refresh token. At this point, we can start accessing the available collections. The collections can by discovered in two main ways. First, by referring to the documentation that’s located in the ‘vmc.zip’ file that’s located in the ‘doc’ folder. Second, by using tab-complete. Some example code to obtain similar output to our prior example while in the interactive shell:

Interactive Shell Python Example Usage

vSphere Automation SDK for Java

The vSphere Automation SDK for Java offers a similar sample to the first Python example from above. However, this particular sample operates a little differently. The output from this sample will be the complete details of each org the user is associated with. This sample can be executed with the following command:

Java SDK Sample to list Org information

Summary

The open-sourced vSphere Automation SDKs have recently received an update. This update allows these SDKs to work with the RESTful API service of VMware Cloud on AWS. There are also a number of samples available within each SDK to list information about organizations, add and/or remove SDDCs, and manage the host count within an SDDC. These samples are easy to have operational within a few minutes of updating your local repo and are quite simple to integrate into your existing code!

Stay tuned for a more detailed look at getting started with each of these SDKs with the VMware Cloud on AWS service in the future.

For more information about the VMware Cloud on AWS service, see the following blog post: VMware Cloud on AWS Technical Overview
For more information about the VMware Cloud on AWS APIs, see the following blog post: An Overview of VMware Cloud on AWS APIs

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.