Home > Blogs > VMware {code} > Monthly Archives: March 2018

Monthly Archives: March 2018

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.