SoftLayer API 12032015
-
Author
nacho-daza -
Category
Technology
-
view
230 -
download
3
Embed Size (px)
Transcript of SoftLayer API 12032015

0
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

1
Agenda
• API economy
• Why to use Softlayer API?
• High level overview on SLAPI
• Basic concepts of SLAPI
• Q&A and useful resources to get going

2
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
does.

3
Why to use SoftLayer API?
Pet vs. cattle server management approach
Cost of management vs. cost of automation
Time to market
New business models

4
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.

5
API Scope
260 Services
3183 Methods
15816 Properties
SOAP
REST
XML_RPC
Clients : C#, Python, PHP, Perl, Ruby

6
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

7
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 : https://yourId:yourApiKey@api.softlayer.com/rest/v3.1/SoftLayer_Account/getHardware (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()
print(account)

8
The SoftLayer CLI (Python)https://softlayer-api-python-client.readthedocs.org/en/latest/install/ 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’::::::::::::::::::::::::::

9
Using Chrome Postman for REST
• Install Chrome browser
• Install Postman Chrome plugin
https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en
• 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

10
List of users in my account
We can call other methods of
SoftLayerAccount such as
getVirtualGuests(),
getHardware(),
getTickets(),
getBareMetalInstances()
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.
## getUsers.py
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'])

11
List of bare metal and virtual servers
We can call other methods of
SoftLayerAccount such as
getVirtualGuests(),
getHardware(),
getTickets(),
getBareMetalInstances()
## getAccountInformation.py
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’])

12
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

13
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

14
Creating a Network monitor
Logical Steps:
1.Import SoftLayer module
2.Bind to the
Network_Monitor_Version1_Query_Host
service
3.Create an object of the same type
4.call createObject()
5.More information is provided here

15
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
container
6.Read a file from a storage container
7.Query for files within a storage container
print ("searching....")
s_results = sl_storage.search('sample')
print ("found " + str(len(s_results)) + " hits....")
print ("found " + str(s_results['total']) + " hits....")
rs = s_results['results']

16
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
usage.
• Write cloud-native software applications.
• Implement business workflows (Message Queues).

17
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')-
>create();
Producer
Producer
Producer
Consumer
Consumer
Publish$my_queue->message() ->setBody(‘Hello World!') -
>create();

18
Useful resources
http://www.softlayer.com/about/automation/open-api
http://sldn.softlayer.com/article/SoftLayer-API-Overview
http://sldn.softlayer.com/
https://github.com/softlayer/
https://gist.github.com/softlayer
http://blog.softlayer.com/
https://softlayer-api-python-client.readthedocs.org/en/latest/
https://softlayer-api-python-client.readthedocs.org/en/latest/cli/
Python tutorial
Python in SoftLayer

19