Skip to main content

PART 1: How to use SoftLayer Python library.

Install the SoftLayer's Python library. 

pip install softlayer

or clone the source code from the github and install from source code.

git clone https://github.com/softlayer/softlayer-python.git
python setup.py install

Once we have installed the SoftLayer Python library we are ready to use it as shown in the following example.

You need your username and api key to run the below example.
One can get both user name and api key at the following link once you login successfully.

https://control.softlayer.com/account/user/profile

Accounts username and API key








E.g. showing how to use SoftLayer Python library.

import SoftLayer
from SoftLayer.managers.image import ImageManager

client = SoftLayer.Client(username='', api_key='')
image_manager = ImageManager(client)

mask = "mask[id,name,note]"
imageTemplates = image_manager.list_private_images(mask='id,name,note')
print("ID - Name - Note")
for template in imageTemplates:
    try:
        print("%s - %s - %s" % (template['id'], template['name'], template['note']))
    except KeyError:
        print("%s - %s - %s" % (template['id'], template['name'], 'None'))


In the above example we are creating a SoftLayer client by giving the username and API key. Mask is used to get the exact information we want instead of getting a whole lot of information. In this example we are just interested in getting the id, name and note of any image template users have in their account.

Comments

Popular posts from this blog

Enable stats GUI on haproxy.

Add bottom snippet to the haproxy.conf below the defaults section. listen  stats         bind 19.41.259.10:1234         mode            http         log             global         maxconn 10         clitimeout      100s         srvtimeout      100s         contimeout      100s         timeout queue   100s         stats enable         stats hide-version         stats refresh 30s         stats show-node         stats auth admin:password         stats uri  /haproxy?stats Make sure you are updating the IP address on the bind to your VIP and if you want, you can change th...

Sending a SIGHUP signal to some external process from Python script

Code : import psutil import os import signal pids = psutil.get_pid_list() for pid in pids: if psutil.Process(pid).name == "process_name": os.kill(pid,signal.SIGHUP) break Steps to follow. 1.Get the PID of the process, in this case  "process_name"   to which you want to send out a SIGHUP signal. 2.Use os.kill(pid,sig) command to send out the SIGHUP signal to that process. 1.Get the PID of the process to which you want to send out a SIGHUP signal. One has to install a package called psutil by the following command. easy_install psutil Check out the following links for more details https://code.google.com/p/psutil/ https://pypi.python.org/pypi/psutil use psutil.get_pid_list() to get all of the PIDs. psutil.get_pid_list() works in the following manner.  pids = [ int ( x ) for x in os . listdir ( '/proc' ) if x . isdigit ()] return pids once you get all the PIDs get the PID you are i...

Adding a table to the openstack databases using migration scripts

So I had a task of adding a new table to the neutron database and at the same time not to use the neutron's migration script, as we wanted to keep the neutron code pure. I tried to google for the alembic data migration but could not find anything useful. So I started to reverse engineer the migration scripts of the other Openstack projects. I used the db code base from the following link. https://github.com/stackforge/group-based-policy/tree/stable/juno/gbpservice/neutron/db So I ll just mention the modifications we need to do to make it work. Please note that I am doing these changes in the Devstack environment. 1. Create folders for new project. Lets say we are building a new project called test_db. Add a folder named test_db as shown in the below location /opt/stack/test_db/test_db/ (Yes 2 folders just to keep in sync with Devstack Arch) 2. Copy migration folder from the below link to  /opt/stack/test_db/test_db/ https://github.com/stackforge/group-based-pol...