Home > Blogs > VMware {code}

New APIs and SDKs for vSphere 6.7

The time has come! vSphere 6.7 has been released, and with it comes a host of new APIs and SDKs for automating, extending, and integrating the vSphere platform. Continue reading

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!

Netherlands VMUG Hackathon 2018

On March 19th, 2018, at the Galloway in the 1931 Conference Centre in the Netherlands, VMware {code} and NLVMUG held their first Hackathon with the theme “Fun, Beers and Gyros.” Sixteen participants in three teams worked diligently from 1:30 in the afternoon for six hours until 8:30 at nightonly taking a break to eat some delicious gyros, reenergize with some sugar and caffeine, or grab stickers and souvenirs from the giveaway table.

A gyro learning, coding, and connecting

Hard at work coding before breaking into the soda

The giveaway table, moments before becoming completely empty

Each of the three teams had their own unique visions for their projects. At the end of the night, three judges, Boudewijn Aelbers, Joep Piscaer, and Wouter Kursten awarded the teams a retro gaming console for their hard work.

Vintage game console

Taking home the prize for Best in IOT, the team from PQR created a way to integrate vRealize Automation with the Homey home automation controller to initiate a deployment using voice commands. They used a Philips Hue lightbulb to indicate the status of the deployment based on its color and a moving Lego Mindstorms robot that would move an object to a different zone on the table to represent the stage of deployment. And, as an added bonus, if would throw the object off the table if the VM request was requested.

Lego Mindstorm robot built by the PQR team

The team from ITQ won Best in Cloud Native for their project that created a way to deploy a Minecraft server using BOSH through voice commands via an Amazon Echo. Taking it one step further, they then deployed a Kubernetes cluster using BOSH and initiated it using more voice commands. The Minecraft character Steve guides the user through the deployment process on a custom interface created by the team.

Steve from Minecraft guiding deployment

The third and final team came from DICTU and won the prize for Most Innovative. They created a way to fully automate deployment of a secure tenant and infrastructure (IaaS) in which everything was secured, error-free, and auditable. The deployed virtual machines were encrypted using VM Encryption with HyTrust as the key management and were micro-segmented using NSX. Intra-VM and vMotion traffic were encrypted using SSL to further increase security. Finally, the team used vRealize Network Insight and vRealize Operations to monitor the security on that infrastructure.

Every team impressed the judges with their projects, and with the help of food, drink, and innovation, the energy brought back the strong community feeling of the early days of the NLVMUG UserCon. Overall, the team behind the Hackathon thought it turned out to be a resounding success, and they are looking forward outdoing themselves next year.

The Hackathon was a huge success, we set out to create a fun and relaxed time and going back to the core of the VMUG community, which worked out exceptionally! Next year is going to be even more awesome.

Martijn Smit, NLVMUG Hackathon Organizer & NSX Specialist, VMware

 

 

The participants were very enthusiastic; the comradery was great to see. If it’s up to me there will be an even greater, bigger hackathon in 2019!

Erik Scholten, Cloud Management Specialist, VMware

 

Interested in running your own Hackathon in your region? Contact us at code@vmware.com or @vmwarecode for more information about our VMware {code} Experiences.

 

Photo credits: Alex Muetstege, TAM

 

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

VMware {code} Experience On Thursday Dec 14th | Containerized Storage, High Performance Networking with EC2, and MultiCluster Ingress Demo

On Thursday we’re hosting the Kubernetes Meetup group at VMware HQ for our final VMware {code} Experience of 2017! We’ll be hearing from speakers Murat Karslioglu, a VP at CloudByte, Chris Marino, CEO at New Networking Co, and Nikhil Jindal, a Software Engineer at Google on the topics of containerized storage, high performance networking with EC2, and setting up a multicluster ingress. Sound intriguing? Wait until we tell you that we ordered extra BBQ chicken pizza!

The event will kickoff with an opportunity to grab some beer & pizza, and a chance to get to know your neighbor. Please see the complete schedule below. If you’re planning to attend in person make sure to register on Meetup. Can’t make it in person? Not a problem! You can join us and thousands of your others virtually for the livestream on the VMTN Facebook page. See you Thursday!

EVENT DETAILS:

Thursday, December 14th, 2017
6:00 – 9:00 pm
Prom C Cafeteria, VMware HQ
Watch the livestream on the VMTN Facebook page
Register to Attend on Meetup

SCHEDULE:

6:00 – 6:15 – Networking
6:15 – 6:25 – Introductions
6:25 – 7:20 – 1st talk: Containerized Storage for Containers
10 minute break
7:30 – 8:00- 2nd talk: High Performance Networking in EC2
8:00-8:10 – Demo: Multi-Cluster Ingress Demo

VMware {code} is a free developer program that provides access to a growing community of developers and experts. If you are an existing Developer Center user or partner program member, you can join the new VMware {code} program using your MyVMware account. If you do not have one, register below to access SDKs and participate in developer forums.

Join VMware {code}