SoftLayer API 12032015

of 20 /20
0 The SoftLayer API Softlayer API time get automated The Softlayer API time to get automated Ignacio Daza - IBM Softlayer Architect @ Nacho_Daza Kimmo Hintikka - IBM Softlayer Architect @ KimmoHintikka

Embed Size (px)

Transcript of SoftLayer API 12032015

Page 1: SoftLayer API  12032015


The SoftLayer API Softlayer API time

get automatedThe Softlayer API time to get automated

Ignacio Daza - IBM Softlayer Architect @Nacho_Daza

Kimmo Hintikka - IBM Softlayer Architect @KimmoHintikka

Page 2: SoftLayer API  12032015



• API economy

• Why to use Softlayer API?

• High level overview on SLAPI

• Basic concepts of SLAPI

• Q&A and useful resources to get going

Page 3: SoftLayer API  12032015


API economy

• The API economy emerges when APIs become part of the business model.

• Public and partner APIs have been strategic enablers for several business models, such as

Twitter’s and Amazon’s.

• The Twitter APIs, for example, easily have ten times more traffic than the Twitter website


Page 4: SoftLayer API  12032015


Why to use SoftLayer API?

Pet vs. cattle server management approach

Cost of management vs. cost of automation

Time to market

New business models

Page 5: SoftLayer API  12032015


High level overview on SLAPI

The Main Core Softlayer API v3 which manages mostly infrastructure plus also things like user accounts, tickets, notifications, access controls

The Object Store API, which sits on top of a powerful multi-tenanted object store hosted and run by Softlayer

The Message Queue API, which helps with intra-application and inter-system communications on a global scale. It also runs on infrastructure controlled by SoftLayer.

Page 7: SoftLayer API  12032015


Basic concepts of SoftLayer APISoftlayer APIs are organized into a hierarchical structure of Services with each service containing various methods

Ability to Limit Results (rows filtering. Generally used for pagination)

Object Masks (properties filtering)

Softlayer Services use data structures and Data types for parameters and return results.

•Data types define the data model of Softlayer cloud.

•Simple data types include : Integer, Boolean, String

•Complex data types can be constructed of various simple types

Page 8: SoftLayer API  12032015


Getting started examples

Command Line Interface

Virtual server list : sl cci list

Bare Metal server list : sl server List

List hardware options : sl hardware list-chassis

Show available command: sl ?

Chrome REST interface

Virtual server list : https://yourId:[email protected]/rest/v3.1/SoftLayer_Account/getVirtualGuests (GET)

Bare Metal Server list : (GET)

List Hardware options: https://yourId:[email protected]/rest/v3.1/SoftLayer_Product_Package_Server/getAllObjects (GET)

Python Client ( more code snippets to follow)

import SoftLayer

usr = “yourId” (make sure to include the quotes )

key = “yourApiKey”

client = SoftLayer.Client(username=usr, api_key=key)

account = client['Account'].getObject()


Page 9: SoftLayer API  12032015


The SoftLayer CLI (Python) INSTRUCTIONS

T420 nacho # sl ?usage: sl <module> [<args>...]

sl help <module>sl help <module> <command>sl [-h | --help]

SoftLayer Command-line Client

The available modules are:

Compute:bmc Bare Metal Cloudcci Cloud Compute Instancesimage Manages compute and flex imagesmetadata Get details about this machine. Also available with 'my' and 'meta'server Hardware serverssshkey Manage SSH keys on your account

Networking:dns Domain Name Systemfirewall Firewall rule and security managementglobalip Global IP address managementrwhois RWhoIs operationsssl Manages SSLsubnet Subnet ordering and managementvlan Manage VLANs on your account

Storage:iscsi View iSCSI detailsnas View NAS details

General:config View and edit configuration for this toolsummary Display an overall summary of your accounthelp Show help

See 'sl help <module>' for more information on a specific module.

To use most commands your SoftLayer username and api_key need to be configured.The easiest way to do that is to use: 'sl config setup'

Invalid module: "#"

(To test, once you have the python-softlayer libraries)# sl config show::::::::::::::::::::::::::# sl config setupUsername []: ‘YOUR USERNAME’API Key or Password []: ‘YOUR API KEY’::::::::::::::::::::::::::

Page 10: SoftLayer API  12032015


Using Chrome Postman for REST

• Install Chrome browser

• Install Postman Chrome plugin

• Create collection for your API calls

JSON calls can be exported / imported from Postman

• Add a new entry to the collection

✓ Click on Collections in upper left and select “Add new Collection”

✓ Enter a url: https://yourId:[email protected]/rest/v3.1/SoftLayer_Account

✓ Where yourId and yourApiKey are the credentials you were provided

✓ Select type of Get. Add to Collection and save. Send the call and view the JSON results at the bottom

Page 11: SoftLayer API  12032015


List of users in my account

We can call other methods of

SoftLayerAccount such as





The Client object takes four parameters: the name of the service to call

(SoftLayerAccount is the default), the id of a specific object to work with, api username

and key.


import SoftLayer.API

username = "your username"

apyt_key = "your API key"

# Create a client to the Softlayer_Account API service

client = SoftLayer.Client(username = username, api_key=api_key)

# Now we can call the methods of the SoftLayer Account

users = client['Account'].getusers(mask="firstName,lastName,username")

for user in users:

print("username is: "+ user['username'])

Page 12: SoftLayer API  12032015


List of bare metal and virtual servers

We can call other methods of

SoftLayerAccount such as






import SoftLayer.APIfrom pprint import pprint as pp

api_username = 'xxx'api_key = 'xxx'

client = SoftLayer.Client(username=api_username,api_key=api_key,


## Get list of VirtualServersserver_list = client[‘Account’].getVirtualGuests()

For server in server_list:print (“id: ”+str(server[‘id’]) + “hostname: ”+ server[‘hostanme’] + “.” + server[‘domain’])

## Get list of BareMetalInstancesserver_list = client[‘Account’].getBareMetalInstances()

For server in server_list:print (“id: ”+str(server[‘id’]) + “hostname: ”+ server[‘hostanme’] + “.” + server[‘domain’])

## Get list the Hardware on the accounthardware = client['Account'].getHardware()pp(hardware)

## Get list of TicketsTicketlist = client[‘Account’].getTickets()

for ticket in Ticketlist:print (“Tickect id: ”+str(ticket[‘id’]) + “Title: ”+ server[‘title’])

Page 13: SoftLayer API  12032015


Managing the amount of information

The limit and offset variables limit the number of

return objects and the starting object

Object Masks specify the relational properties that

need to be returned along with the target objects

Page 14: SoftLayer API  12032015


Create / Delete a virtual Instance

Logical Steps:

1.Import SoftLayer module

2.Get a authenticate client object connected to

the VirtualGuest service

3.Pass it to the createObject method of the

VirtualGuest service.

4.Call deleteObject with the id of the instance

to remove it

Page 15: SoftLayer API  12032015


Creating a Network monitor

Logical Steps:

1.Import SoftLayer module

2.Bind to the



3.Create an object of the same type createObject()

5.More information is provided here

Page 16: SoftLayer API  12032015


Object Storage – Create, store, search

Logical Steps

1.pip install softlayer-object-storage

2.Import Object Storage module

3.Set authentication

4.Create a storage container

5.Create and populate a file within a storage


6.Read a file from a storage container

7.Query for files within a storage container

print ("searching....")

s_results ='sample')

print ("found " + str(len(s_results)) + " hits....")

print ("found " + str(s_results['total']) + " hits....")

rs = s_results['results']

Page 17: SoftLayer API  12032015


Typical Scenarios for using APIs

The following scenarios are examples of how to use SoftLayer APIs:

• Invoke selected services for white label service providers in order to implement their own rebranded portals.

• Programmatic upscaling and downscaling in a public or private cloud.

• Handle cloud monitoring events, such as re-instantiating servers, rebooting, and OS loads.

• Programmatic cloud management, including upgrading and downgrading, adding storage, backup and restore, and Object Store


• Write cloud-native software applications.

• Implement business workflows (Message Queues).

Page 18: SoftLayer API  12032015


Creating message queues

The Client object takes four parameters: the name of the service to call

(SoftLayerAccount is the default), the id of a specific object to work with, api username

and key.

Message Queue

$my_queue = $messaging_client->queue('my_queue')-







Publish$my_queue->message() ->setBody(‘Hello World!') -


Page 19: SoftLayer API  12032015


Useful resources

Python tutorial

Python in SoftLayer

Page 20: SoftLayer API  12032015