Posts Tagged 'Github'

December 30, 2015

Using Ansible on SoftLayer to Streamline Deployments

Many companies today are leveraging new tools to automate deployments and handle configuration management. Ansible is a great tool that offers flexibility when creating and managing your environments.

SoftLayer has components built within the Ansible codebase, which means continued support for new features as the Ansible project expands. You can conveniently pull your SoftLayer inventory and work with your chosen virtual servers using the Core Ansible Library along with the SoftLayer Inventory Module. Within your inventory list, your virtual servers are grouped by various traits, such as “all virtual servers with 32GB of RAM,” or “all virtual servers with a domain name of” The inventory list provides different categorized groups that can be expanded upon. With the latest updates to the SoftLayer Inventory Module, you can now get a list of virtual servers by tags, as well as work with private virtual servers. You can then use each of the categories provided by the inventory list within your playbooks.

So, how can you work with the new categories (such as tags) if you don’t yet have any inventory or a deployed infrastructure within SoftLayer? You can use the new SoftLayer module that’s been added to the Ansible Extras Project. This module provides the ability to provision virtual servers within a playbook. All you have to do is supply the build detail information for your virtual server(s) within your playbook and go.

Let’s look at an example playbook. You’ll want to specify a hostname along with a domain name when defining the parameters for your virtual server(s). The hostname can have an incremental number appended at the end of it if you’re provisioning more than one virtual server; e.g., Hostname-1, Hostname-2, and so on. You just need to specify a value True for the parameter increment. Incremental naming offers the ability to uniquely name virtual servers within your playbook, but is also optional in the case where you want similar hostnames. Notice that you can also specify tags for your virtual servers, which is handy when working with your inventory in future playbooks.

Following is a sample playbook for building Ubuntu virtual servers on SoftLayer:

- name: Build Tomcat Servers
  hosts: localhost
  gather_facts: False
  - name: Build Servers
      module: softlayer
      quantity: 2
      increment: True
      hostname: www
      datacenter: mex01
      tag: tomcat-test
      hourly: True
      private: False
      dedicated: False
      local_disk: True
      cpus: 1
      memory: 1024
      disks: [25]
      os_code: UBUNTU_LATEST
      ssh_keys: [12345]

By default, your playbook will pause until each of your virtual servers completes provisioning before moving onto the next plays within your playbook. You can specify the wait parameter to False if you choose not to wait for the virtual servers to complete provisioning. The wait parameter is helpful for when you want to build many virtual servers, but some have different characteristics such as RAM or tag naming. You can also set the maximum time you want to wait on the virtual servers by setting the wait_timeout parameter, which takes an integer defining the number of seconds to wait.

Once you’re finished using your virtual servers, canceling them is as easy as creating them. Just specify a new playbook step with a state of absent, as well as specifying the virtual server ID or tags to know which virtual servers to cancel.

The following example will cancel all virtual servers on the account with a tag of tomcat-test:

- name: Cancel Servers
  hosts: localhost
  gather_facts: False
  - name: Cancel by tag
      module: softlayer
      state: absent
      tag: tomcat-test

New features are being developed with the core inventory library to bring additional functionality to Ansible on SoftLayer. These new developments can be found by following the Core Ansible Project hosted on Github. You can also follow the Ansible Extras Project for updates to the SoftLayer module.

As of this blog post, the new SoftLayer module is still pending inclusion into the Ansible Extras Project. Click here to check out the current pull request for the latest code and samples.


December 21, 2015

Introducing API release notes and examples library

The website to find out what new and exciting changes are happening on the SoftLayer platform is now Specifically, this website highlights any changes to the customer portal, the API, and any supporting systems. Please continue to rely on tickets created on your account for information regarding any upcoming maintenances and other service impacting events.

At SoftLayer, we follow agile development principles and release code in small but frequent iterations—usually about two every week. The changes featured in release notes on only cover what is publicly accessible. So while they may seem small, there are usually a greater number of behind-the-scenes changes happening.

Along with the release notes are a growing collection of useful example scripts on how to actually use the API in a variety of popular languages. While the number of examples is currently small, we are constantly adding examples as they come up, so keep checking back. We are generally inspired to add examples by the questions posted on Stack Overflow that have the SoftLayer tag, so keep posting your questions there, too.


March 22, 2013

Social Media for Brands: Monitor Twitter Search via Email

If you're responsible for monitoring Twitter for conversations about your brand, you're faced with a challenge: You need to know what people are saying about your brand at all times AND you don't want to live your entire life in front of Twitter Search.

Over the years, a number of social media applications have been released specifically for brand managers and social media teams, but most of those applications (especially the free/inexpensive ones) differentiate themselves only by the quality of their analytics and how real-time their data is reported. If that's what you need, you have plenty of fantastic options. Those differentiators don't really help you if you want to take a more passive role in monitoring Twitter search ... You still have to log into the application to see your fancy dashboards with all of the information. Why can't the data come to you?

About three weeks ago, Hazzy stopped by my desk and asked if I'd help build a tool that uses the Twitter Search API to collect brand keywords mentions and send an email alert with those mentions in digest form every 30 minutes. The social media team had been using Twilert for these types of alerts since February 2012, but over the last few months, messages have been delayed due to issues connecting to Twitter search ... It seems that the service is so popular that it hits Twitter's limits on API calls. An email digest scheduled to be sent every thirty minutes ends up going out ten hours late, and ten hours is an eternity in social media time. We needed something a little more timely and reliable, so I got to work on a simple "Twitter Monitor" script to find all mentions of our keyword(s) on Twitter, email those results in a simple digest format, and repeat the process every 30 minutes when new mentions are found.

With Bear's Python-Twitter library on GitHub, connecting to the Twitter API is a breeze. Why did we use Bear's library in particular? Just look at his profile picture. Yeah ... 'nuff said. So with that Python wrapper to the Twitter API in place, I just had to figure out how to use the tools Twitter provided to get the job done. For the most part, the process was very clear, and Twitter actually made querying the search service much easier than we expected. The Search API finds all mentions of whatever string of characters you designate, so instead of creating an elaborate Boolean search for "SoftLayer OR #SoftLayer OR @SoftLayer ..." or any number of combinations of arbitrary strings, we could simply search for "SoftLayer" and have all of those results included. If you want to see only @ replies or hashtags, you can limit your search to those alone, but because "SoftLayer" isn't a word that gets thrown around much without referencing us, we wanted to see every instance. This is the code we ended up working with for the search functionality:

def status_by_search(search):
    statuses = api.GetSearch(term=search)
    results = filter(lambda x: > get_log_value(), statuses)
    returns = []
    if len(results) > 0:
        for result in results:
        return returns, len(returns)

If you walk through the script, you'll notice that we want to return only unseen Tweets to our email recipients. Shortly after got the Twitter Monitor up and running, we noticed how easy it would be to get spammed with the same messages every time the script ran, so we had to filter our results accordingly. Twitter's API allows you to request tweets with a Tweet ID greater than one that you specify, however when I tried designating that "oldest" Tweet ID, we had mixed results ... Whether due to my ignorance or a fault in the implementation, we were getting fewer results than we should. Tweet IDs are unique and numerically sequential, so they can be relied upon as much as datetime (and far easier to boot), so I decided to use the highest Tweet ID from each batch of processed messages to filter the next set of results. The script stores that Tweet ID and uses a little bit of logic to determine which Tweets are newer than the last Tweet reported.

def new_tweets(results):
    if get_log_value() < max( for result in results):
        set_log_value(max( for result in results))
        return True
def get_log_value():
    with open('', 'r') as f:
        return int(
def set_log_value(messageId):
    with open('', 'w+') as f:

Once we culled out our new Tweets, we needed our script to email those results to our social media team. Luckily, we didn't have to reinvent the wheel here, and we added a few lines that enabled us to send an HTML-formatted email over any SMTP server. One of the downsides of the script is that login credentials for your SMTP server are stored in plaintext, so if you can come up with another alternative that adds a layer of security to those credentials (or lets you send with different kinds of credentials) we'd love for you to share it.

From that point, we could run the script manually from the server (or a laptop for that matter), and an email digest would be sent with new Tweets. Because we wanted to automate that process, I added a cron job that would run the script at the desired interval. As a bonus, if the script doesn't find any new Tweets since the last time it was run, it doesn't send an email, so you won't get spammed by "0 Results" messages overnight.

The script has been in action for a couple of weeks now, and it has gotten our social media team's seal of approval. We've added a few features here and there (like adding the number of Tweets in an email to the email's subject line), and I've enlisted the help of Kevin Landreth to clean up the code a little. Now, we're ready to share the SoftLayer Twitter Monitor script with the world via GitHub!

SoftLayer Twitter Monitor on GitHub

The script should work well right out of the box in any Python environment with the required libraries after a few simple configuration changes:

  • Get your Twitter Customer Secret, Access Token and Access Secret from
  • Copy/paste that information where noted in the script.
  • Update your search term(s).
  • Enter your mailserver address and port.
  • Enter your email account credentials if you aren't working with an open relay.
  • Set the self.from_ and values to your preference.
  • Ensure all of the Python requirements are met.
  • Configure a cron job to run the script your desired interval. For example, if you want to send emails every 10 minutes: */10 * * * * <path to python> <path to script> 2>&1 /dev/null

As soon as you add your information, you should be in business. You'll have an in-house Twitter Monitor that delivers a simple email digest of your new Twitter mentions at whatever interval you specify!

Like any good open source project, we want the community's feedback on how it can be improved or other features we could incorporate. This script uses the Search API, but we're also starting to play around with the Stream API and SoftLayer Message Queue to make some even cooler tools to automate brand monitoring on Twitter.

If you end up using the script and liking it, send SoftLayer a shout-out via Twitter and share it with your friends!


July 6, 2010

SoftLayer API Updates

Our API has gone through more than a few changes since the middle of 2006 when it was first released in beta to a few of our customers. Since then, it has grown from a handful of available features to your one stop shop for infrastructure automation needs. Providing all the functionality our customer portal has, plus putting automation in your/the customers’ hands that was only dreamed of a few short years ago. We have a few NEW note worthy features we just released concerning the API that numerous people have asked for. So here goes:

1.Opened the API up to the public network

We now have two ways to access the SoftLayer API. The first is the same method you have been using utilizing our private network. Some developers have asked for a way to bypass the VPN and private network. So we have added a publicly accessible entry point for the API in addition to the private network. This should open up your development to new exciting desktop widgets and consumption of our API for external software projects without requiring the VPN overhead. More information is available in the SLDN wiki.

2. RESTful web services

We added a simple Representational State Transfer (REST) interface to the arsenal of already supported SOAP and XML-RPC protocols. REST is great if you want to perform simple requests that do not require the complexity of SOAP and for simple integration into AJAX related operations on web pages.

3.New documentation

We have just revised our documentation located in the SLDN wiki. We added more examples, updated connection information for public access and usage for our new REST protocol support. We have also been busy working on our growing collection of open source projects.

4.New Code Samples

As you may or may not have heard Softlayer has a github account now. We are uploading projects and examples as fast as we can. You might want to check out Stratos a white label portal example, Client libraries for Python, Perl and PHP, as well as our growing gist examples which outline common tasks requested by customers.

We would love to hear any feature requests you are looking for, so let us hear from you.

Subscribe to github