Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
Copyright (c) 2013, SoftLayer Technologies, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither SoftLayer Technologies, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither SoftLayer Technologies, Inc. nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
SoftLayer API Python Client
===========================
This code provides a simple Python library to use the [SoftLayer API](http://sldn.softlayer.com/reference/softlayerapi).
This code provides a simple Python library to use the
[SoftLayer API](http://sldn.softlayer.com/reference/softlayerapi).

Overview
--------

This library provides a simple interface to interact with SoftLayer's XML-RPC API and provides support for many of SoftLayer API's features like [object masks](http://sldn.softlayer.com/article/Using-Object-Masks-SoftLayerrAPI).
This library provides a simple interface to interact with SoftLayer's XML-RPC
API and provides support for many of SoftLayer API's features like
[object masks](http://sldn.softlayer.com/article/Using-Object-Masks-SoftLayerAPI).

Installation
------------
Expand All @@ -21,14 +24,19 @@ python setup.py install
```


The most up to date version of this library can be found on the SoftLayer github public repositories: http://github.com/softlayer. Please post to the SoftLayer forums http://forums.softlayer.com/ or open a support ticket in the SoftLayer customer portal if you have any questions regarding use of this library.
The most up to date version of this library can be found on the SoftLayer
GitHub public repositories: http://github.com/softlayer. Please post to the
SoftLayer forums http://forums.softlayer.com/ or open a support ticket in the
SoftLayer customer portal if you have any questions regarding use of this
library.

System Requirements
-------------------

* This library has been tested on Python 2.5, 2.6, 2.7, 3.2 and 3.3.
* A valid SoftLayer API username and key are required to call SoftLayer's API
* A connection to SoftLayer's private network is required to connect to SoftLayer’s private network API endpoints.
* A connection to SoftLayer's private network is required to connect to
SoftLayer’s private network API endpoints.

Suggested Reading
-----------------
Expand All @@ -40,4 +48,5 @@ Suggested Reading

Copyright
---------
This software is Copyright (c) 2013 [SoftLayer Technologies, Inc](http://www.softlayer.com/). See the bundled LICENSE file for more information.
This software is Copyright (c) 2013 [SoftLayer Technologies, Inc](http://www.softlayer.com/).
See the bundled LICENSE file for more information.
103 changes: 64 additions & 39 deletions SoftLayer/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@


class Client(object):
"""A SoftLayer API client
""" A SoftLayer API client.

:param service_name: The name of the SoftLayer API service to query.
:param id: An optional object if if you're instantiating a particular
SoftLayer_API object. Setting an id defines this client's
:param service_name: the name of the SoftLayer API service to query
:param integer id: an optional object ID if you're instantiating a
particular SoftLayer_API object. Setting an ID defines this client's
initialization parameter.
:param username: An optional API username if you wish to bypass the
package's built-in username.
:param api_key: An optional API key if you wish to bypass the package's
built in API key.
:param endpoint_url: The API endpoint base URL you wish to connect to.
:param username: an optional API username if you wish to bypass the
package's built-in username
:param api_key: an optional API key if you wish to bypass the package's
built in API key
:param endpoint_url: the API endpoint base URL you wish to connect to.
Set this to API_PRIVATE_ENDPOINT to connect via SoftLayer's private
network.
:param timeout: Timeout for API requests
:param verbose: When true, prints details about every HTTP request.
:param integer timeout: timeout for API requests
:param boolean verbose: prints details about every HTTP request if true

Usage::

Expand Down Expand Up @@ -88,17 +88,22 @@ def __init__(self, service_name=None, id=None, username=None, api_key=None,
self.timeout = timeout

def add_raw_header(self, name, value):
""" Set HTTP headers for API calls
""" Set HTTP headers for API calls.
.. deprecated:: 2.0.0

:param name: the header name
:param value: the header value

"""
self._raw_headers[name] = value

def add_header(self, name, value):
""" Set a SoftLayer API call header
""" Set a SoftLayer API call header.
.. deprecated:: 2.0.0

:param name: The name of the header to add
:param value: The header to add.
:param name: the header name
:param value: the header value

"""
name = name.strip()
if name is None or name == '':
Expand All @@ -107,17 +112,17 @@ def add_header(self, name, value):
self._headers[name] = value

def remove_header(self, name):
""" Remove a SoftLayer API call header
""" Remove a SoftLayer API call header.
.. deprecated:: 2.0.0

:param name: The name of the header to remove.
"""
:param name: the header name

"""
if name in self._headers:
del self._headers[name.strip()]

def set_authentication(self, username, api_key):
""" Set user and key to authenticate a SoftLayer API call
""" Set user and key to authenticate a SoftLayer API call.
.. deprecated:: 2.0.0

Use this method if you wish to bypass the API_USER and API_KEY class
Expand All @@ -126,37 +131,37 @@ def set_authentication(self, username, api_key):
See U{https://manage.softlayer.com/Administrative/apiKeychain} for more
information.

:param username: The username to authenticate an API call.
:param api_key: The user's API key.
"""
:param username: the username to authenticate with
:param api_key: the user's API key

"""
self.add_header('authenticate', {
'username': username.strip(),
'apiKey': api_key.strip(),
})

def set_init_parameter(self, id):
""" Set an initialization parameter header
""" Set an initialization parameter header.
.. deprecated:: 2.0.0

Initialization parameters instantiate a SoftLayer API service object to
act upon during your API method call. For instance, if your account has
a server with id number 1234, then setting an initialization parameter
a server with ID number 1234, then setting an initialization parameter
of 1234 in the SoftLayer_Hardware_Server Service instructs the API to
act on server record 1234 in your method calls.

See U{http://sldn.softlayer.com/article/Using-Initialization-Parameters-SoftLayer-API} # NOQA
for more information.

:param id: The id number of the SoftLayer API object to instantiate
"""
:param id: the ID of the SoftLayer API object to instantiate

"""
self.add_header(self._service_name + 'InitParameters', {
'id': int(id)
})

def set_object_mask(self, mask):
""" Set an object mask to a SoftLayer API call
""" Set an object mask to a SoftLayer API call.
.. deprecated:: 2.0.0

Use an object mask to retrieve data related your API call's result.
Expand All @@ -166,9 +171,9 @@ def set_object_mask(self, mask):
U{http://sldn.softlayer.com/article/Using-Object-Masks-SoftLayer-API}
for more information.

:param mask: The object mask you wish to define
"""
:param mask: the object mask you wish to define

"""
header = 'SoftLayer_ObjectMask'

if isinstance(mask, dict):
Expand All @@ -177,34 +182,42 @@ def set_object_mask(self, mask):
self.add_header(header, {'mask': mask})

def set_result_limit(self, limit, offset=0):
""" Set a result limit on a SoftLayer API call
""" Set a result limit on a SoftLayer API call.
.. deprecated:: 2.0.0

Many SoftLayer API methods return a group of results. These methods
support a way to limit the number of results retrieved from the
SoftLayer API in a way akin to an SQL LIMIT statement.

:param limit: The number of results to limit a SoftLayer API call to.
:param offset: An optional offset to begin a SoftLayer API call's
returned result at.
"""
:param limit: the number of results to limit a SoftLayer API call to
:param offset: An optional offset at which to begin a SoftLayer API
call's returned result

"""
self.add_header('resultLimit', {
'limit': int(limit),
'offset': int(offset)
})

def __getitem__(self, name):
""" Get a SoftLayer Service
""" Get a SoftLayer Service.

:param name: The name of the service. E.G. SoftLayer_Account

"""
if not name.startswith(self._prefix):
name = self._prefix + name
return Service(self, name)

def __call__(self, service, method, *args, **kwargs):
""" Place a SoftLayer API call """
""" Perform a SoftLayer API call.

:param service: the name of the SoftLayer API service
:param method: the method to call on the service
:param dict *args: arguments for the specified method
:param dict **kwargs: response-level arguments (limit, offset, etc.)

"""
objectid = kwargs.get('id')
objectmask = kwargs.get('mask')
objectfilter = kwargs.get('filter')
Expand Down Expand Up @@ -252,7 +265,12 @@ def __call__(self, service, method, *args, **kwargs):
verbose=self.verbose)

def __format_object_mask(self, objectmask, service):
""" Formats new and old style object masks into proper headers. """
""" Format new and old style object masks into proper headers.

:param objectmask: a string- or dict-based object mask
:param service: a SoftLayer API service name

"""
if isinstance(objectmask, dict):
mheader = '%sObjectMask' % service
else:
Expand All @@ -272,7 +290,11 @@ def __format_object_mask(self, objectmask, service):
return {mheader: {'mask': objectmask}}

def __format_filter_dict(self, d):
""" Formats given filters to the SL-API header """
""" Format given filters to the SL-API header.

:param d: a dict of filters

"""
for key, value in d.iteritems():
if isinstance(value, dict):
d[key] = self.__format_filter_dict(value)
Expand All @@ -282,14 +304,17 @@ def __format_filter_dict(self, d):
return d

def __getattr__(self, name):
""" Attempt a SoftLayer API call
""" Attempt a SoftLayer API call.
.. deprecated:: 2.0.0

Use this as a catch-all so users can call SoftLayer API methods
directly against their client object. If the property or method
relating to their client object doesn't exist then assume the user is
attempting a SoftLayer API call and return a simple function that makes
an XML-RPC call.

:param name: method name

"""
if name in ["__name__", "__bases__"]:
raise AttributeError("'Obj' object has no attribute '%s'" % name)
Expand Down
24 changes: 19 additions & 5 deletions SoftLayer/CCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ def __init__(self, *args):


class CCIManager(object):
""" Manage CCI's """
""" Manage CCIs """
def __init__(self, client):
self.client = client
self.account = client['Account']
self.guest = client['Virtual_Guest']

def list_instances(self, hourly=True, monthly=True):
""" Retrieve a list of all CCIs on the account.

:param boolean hourly: include hourly instances
:param boolean monthly: include monthly instances

"""
items = set([
'id',
'globalIdentifier',
Expand Down Expand Up @@ -84,11 +90,19 @@ def get_create_options(self):
return self.guest.getCreateObjectOptions()

def cancel_instance(self, id):
""" Cancel an instance immediately, deleting all its data.

:param integer id: the instance ID to cancel

"""
return self.guest.deleteObject(id=id)

def reload_instance(self, id):
""" Performs an OS reload of an instance with its current
configuration. """
""" Perform an OS reload of an instance with its current configuration.

:param integer id: the instance ID to reload

"""
return self.guest.reloadCurrentOperatingSystemConfiguration(id=id)

def _generate_create_dict(
Expand Down Expand Up @@ -150,11 +164,11 @@ def _generate_create_dict(
return data

def verify_create_instance(self, **kwargs):
""" see _generate_create_dict """
""" see _generate_create_dict """ # TODO: document this
create_options = self._generate_create_dict(**kwargs)
return self.guest.generateOrderTemplate(create_options)

def create_instance(self, **kwargs):
""" see _generate_create_dict """
""" see _generate_create_dict """ # TODO: document this
create_options = self._generate_create_dict(**kwargs)
return self.guest.createObject(create_options)
1 change: 0 additions & 1 deletion SoftLayer/CLI/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class Environment(object):

# {'module_name': {'action': 'actionClass'}}
plugins = {}
aliases = {
Expand Down
Loading