CloudSigma API v2.0 is now supported in jclouds

This is a guest post by Ignasi Barrera, a PMC member on the Apache jclouds® project and active contributor to jclouds.

What is jclouds?

Apache jclouds® is a cloud agnostic library for the JVM that enables developers to access over 30 cloud providers using one API. It provides common interfaces to access different services in the cloud, allowing users can easily write portable code:

  • Compute: Users can provision their infrastructure in any cloud provider and have control of the entire process: deployment configuration, provisioning and bootstrap
  • BlobStore: Easily store objects in a wide range of blob store providers, regardless of how big the objects to manage are, or how many files are there.
  • Load Balancer: The Load Balancer abstraction provides a common interface to configure the load balancers in any cloud that supports them. Just define the load balancer and the nodes that should join it, and it will be ready for the action.

Apart from the common interfaces, jclouds also provides provider specific APIs, allowing users to use specific features of each cloud provider and leveraging full control over the cloud resources.

jclouds and CloudSigma

CloudSigma is one of the providers that has been supported in jclouds for a long time. Early releases of jclouds include support for the v1 API, and starting from jclouds 1.7.0, the version 2 of the API is supported too.

CloudSigma is not only supporting jclouds by contributing code and keeping the provider up to date, but is also helping the project by providing testing accounts so live tests can be executed in every release to make sure everything works as expected. This has significantly helped identifying issues during development and improving the quality of the provider.

In this blog post we are going to show an overview of jclouds, and how the CloudSigma v2 API can be used directly to effectively manage the cloud.

Using the CloudSigma API

Using the CloudSigma API is easy. In the following examples we’re going to see how to use the ClousSigma v2 API with jclouds. First of all, the CloudSigma v2 dependency has to be added to the project:


<dependency>
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>cloudsigma2-lvs</artifactId>
<version>1.7.1</version>
</dependency>

We’ll be using Las Vegas region, but jclouds also supports Zürich and Washington D.C for the version 2 of the API. To use them, just change the artifactId to cloudsigma-zrh or cloudsigma-wdc.

Creating the API

The first thing that needs to be done is to create the API using the ContextBuilder:


// Note that you can directly create the API classes instead of building
// an abstraction view (such as the Compute one). This approach can be
// used when you are just going to use the provider specific APIs
CloudSigma2Api api = ContextBuilder.newBuilder("cloudsigma2-lvs")
.credentials("identity", "credential")
.buildApi(CloudSigma2Api.class);

Creating a server from a pre-installed library drive

In this example we’ll show how to use the v2 API to:

  • Search the library for a pre-installed drive
  • Clone the drive so we can attach it to a server
  • Select an available Public IP
  • Create and start a server with the selected drive and IP address

// First of all we're going to select the desired drive from the library
String driveName = "Ubuntu 13.10 Server";
FluentIterable<LibraryDrive> drives = api.listLibraryDrives().concat();
Optional<LibraryDrive> libraryDrive =
drives.firstMatch(and(name(driveName), media(MediaType.DISK)));

// Next step is to clone the drive and identify it in our drive list
api.cloneLibraryDrive(libraryDrive.get().getUuid(), null);
Optional<DriveInfo> cloned = api.listDrivesInfo().concat()
.firstMatch(and(name(driveName), status(UNAVAILABLE)));

// Once identified, we'll wait until the clone operation has finned and the
// drive is available, and then configure how it will be attached to the
// server
Predicates2.retry(status(UNMOUNTED), 60000).apply(cloned.get());
ServerDrive drive = cloned.get().toServerDrive(1, "0:1", VIRTIO);

// We are also going to assign a public IP to our server
Optional<IPInfo> ip = api.listIPInfo().concat().firstMatch(available());
NIC nic = ip.get().toNIC();

// Finally, we can create the server with the cloned drive and the selected
// public IP
ServerInfo serverToCreate = new ServerInfo.Builder()
.name("New Server with VLAN")
.memory(new BigInteger("5368709120"))
.cpu(3000)
.vncPassword("new_password")
.nics(ImmutableList.of(nic))
.drives(ImmutableList.of(drive))
.build();

ServerInfo createdServer = api.createServer(serverToCreate);
api.startServer(createdServer.getUuid());

Create a VLAN to assign private IPs to the servers

In this example we’ll show how you can create a private VLAN so we can use private networking in the servers we create:


// Create the VLAN
CreateSubscriptionRequest request = new CreateSubscriptionRequest.Builder()
.amount("1")
.period("1 month")
.resource(SubscriptionResource.VLAN)
.build();

Subscription subscription = api.createSubscription(request);

// Get the created VLAN info and convert it to a NIC so it can be attached
// to a server
String vlanUuid = subscription.getSubscribedObject();
NIC nic = api.getVLANInfo(vlanUuid).toNIC();

Now the NIC can be attached to a server just as shown in the previous example:

1zpgExY

Next steps

This blog post is just an introduction to Apache jclouds® and the CloudSigma API. There are many features that can be explored, such as the compute extensions, automatic pagination, integration with Chef, etc. I strongly encourage you to try the examples in this post and start playing with jclouds and CloudSigma.

To learn more, you just have to check the links below:

You will also find help in the jclouds mailing lists and the #jclouds IRC channel at Freenode.

Share this Post

E7a98077869aa0d2d42e3691ae620c81?s=80&r=g

About Ignasi Barrera

Ignasi is a PMC member on the Apache jclouds® project. He is an active open-source contributor who enjoys writing code, playing the piano, and having fun as an amateur magician.