At CenturyLink Cloud, our culture incorporates a DevOps mindset whereby each team owns the services they develop from implementation to production. In order to apply the DevOps mindset, we adhere to these enabling principles: Automate, Self-Service, and Programmable. As an extension of these principles, we also provide public APIs and SDKs for multiple programming languages to enable our customers to also automate, self-serve, and program infrastructure and service interactions.

In this tutorial we'll take a look at the CenturyLink Cloud Java SDK and explore how we can use it to create a server using a CentOS 6 operating system template in a specific server group in a US East data center. For scripting in the Java Runtime Environment, I tend to lean towards using the Groovy programming language and Gradle for build automation. In order to execute the build commands later in this tutorial you must install Gradle so it can be used from your terminal.

Setup Development Environment

To setup our development environment for using the CenturyLink Cloud Java SDK we can create a Gradle build configuration. The name of this file is build.gradle by default. Create a file named build.gradle in a new project directory in your local development environment with the following content:

apply plugin: 'groovy'

repositories {

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.10'
    compile ''

task runScript (dependsOn: 'classes', type: JavaExec) {
    main = 'create-server'
    classpath = sourceSets.main.runtimeClasspath

For those who use Gradle, the above configuration will look familiar. For those who are not familiar with Gradle, we'll describe what this Gradle build configuration is doing. The first line is setting up our project to use the Groovy programming language by applying the 'groovy' plugin. In the 'repositories' section we are telling Gradle where to download project dependencies from during the process. The 'dependencies' we need for this project are the Groovy language ('groovy-all') and the CenturyLink Cloud Java SDK ('clc-java-sdk'). The task named: 'runScript' is a custom task created to run our Groovy script in the JRE (Java Runtime Environment). This task expects a Groovy file named: 'create-server' to be the main class to execute at runtime. So, the next step is to create this Groovy file but Gradle uses a common convention to find source files in the 'src/main/groovy' directory for Groovy. Put the following content into the file src/main/groovy/create-server.groovy:

println "hello world"

To test that we have our local development configured correctly with Gradle, run the following command in your top-level project directory:

$ gradle runScript

You should see the output 'hello world' in the terminal after running this command.

Authenticate Using CenturyLink Cloud Java SDK

The CenturyLink Cloud Java SDK comes with multiple ways to authenticate using your credentials. The SDK configuration section of the documentation describes them in detail. For our purposes, we will use the DefaultCredentialsProvider, which wraps all of the different methods and will try each of the other approaches in the following order:

  1. System variables sent in as JVM variables clc.username and clc.password
  2. Environment variables accessed from your shell as: CLC_USERNAME and CLC_PASSWORD
  3. Properties file named: '' located on your Java runtime classpath

The DefaultCredentialsProvider is the default credentials provider when instantiating the default constructor of Modify the create-server.groovy file to the following contents:

println "not authenticated yet..."
ClcSdk sdk = new ClcSdk()
println "logged in as: ${sdk.credentialsProvider.credentials.username}"

When you run the script again it should say something like:

$ gradle runScript
not authenticated yet...
logged in as: mydemouser

Creating a Server

Servers are created using the, which is available from the instantiated ClcSdk class.

ServerService serverService = sdk.serverService()

The create() method on ServerService, as with of its other methods, is asynchronous. Therefore, the return value is to allow us to wait for the actual resulting created server. The example code below will create a new standard server in the default server group of the CenturyLink US East Sterling, VA data center with:

  • Standard storage
  • 1 CPU
  • 2 GB RAM
  • 14 GB raw disk
  • CentOS version 6 operating system
OperationFuture<ServerMetadata> future = serverService
    .create(new CreateServerConfig()
        .machine(new Machine()
            .disk(new DiskConfig()

Now that we have the OperationFuture, we can wait for the result using the waitUntilComplete() method:

ServerMetadata createdServerInfo = future.waitUntilComplete().getResult();
println "created server: ${} - ${}"

When you run the script again there will be a delay between when the server creation process is kicked off and the OperationFuture returns with a result. During this time, you will see a server under construction in the CenturyLink Control Portal queue:

After the server has been created, you should then see the server in your account's default server group of the US East Sterling, VA data center:


The CenturyLink Cloud Java SDK and the SDKs for other languages provide many more capabilities in addition to the basic creation of servers. Some of the capabilities as of this writing are:

  • Server management
  • Power operations
  • Managing groups
  • Group actions
  • Searching Operating System templates
  • Searching data centers
  • Invoice statistics
  • Configuring remote servers over SSH
  • Billing statistics
  • Get server monitoring statistics
  • And more...

Take one of our SDKs out for a spin or directly use the CenturyLink Cloud public APIs and let us know what you think.