Permalink
Browse files

Support for SoftLayer's public network endpoints.

The SoftLayer.API.Client class now defaults to use the public network
endpoints. Pass an optional fourth parameter to the constructor
specifying the API endpoint you wish to use. The API_PUBLIC_ENDPOINT and
API_PRIVATE_ENDPOINT constants define the public and private network
endpoints for the SoftLayer API.
  • Loading branch information...
1 parent 42f80d7 commit 4ad879ebb24237e2110ff1e19dcf164ac00e0c46 SoftLayer committed Jul 6, 2010
Showing with 35 additions and 8 deletions.
  1. +2 −4 README.textile
  2. +32 −3 SoftLayer/API.py
  3. +1 −1 setup.py
View
@@ -4,11 +4,9 @@ h2. Overview
SoftLayer.API.Client provides a simple method for connecting to and making calls from the SoftLayer XML-RPC API and provides support for many of the SoftLayer API's features. XML-RPC method calls and client management are handled by Python's built-in xmlrpc client class.
-Currently the SoftLayer API only allows connections from within the SoftLayer private network. The system using this class must be either directly connected to the SoftLayer private network (eg. purchased from SoftLayer) or has access to the SoftLayer private network via a VPN connection.
-
Making API calls using the SoftLayer.API.Client class is done in the following steps:
-# Instantiate a new SoftLayer.API.Client object. Provide the name of the service that you wish to query, an optional id number of the object that you wish to instantiate, your SoftLayer API username, and your SoftLayer API key.
+# Instantiate a new @SoftLayer.API.Client@ object. Provide the name of the service that you wish to query, an optional id number of the object that you wish to instantiate, your SoftLayer API username, and your SoftLayer API key. The client class defaults to connect over the public Internet. Enter @API_PRIVATE_ENDPOINT@ or @API_PRIVATE_ENDPOINT@ to connect to the API over SoftLayer’s private network. The system making API calls must be connected to SoftLayer’s private network (eg. purchased from SoftLayer or connected via VPN) in order to use the private network API endpoints.
# Define and add optional headers to the client, such as object masks and result limits.
# Call the API method you wish to call as if it were local to your client object. This class throws exceptions if it's unable to execute a query, so it's best to place API method calls in try / except statements for proper error handling.
@@ -20,7 +18,7 @@ h2. System Requirements
This library has been tested to work in Python 2.4 - 3.1 on POSIX compliant and Windows operating systems.
-A network connection is required for installation, and a connection to the SoftLayer private network and a valid SoftLayer API username and key are required to call the SoftLayer API.
+A network connection is required for installation, and a valid SoftLayer API username and key are required to call the SoftLayer API. A connection to the SoftLayer private network is required to connect to SoftLayer’s private network API endpopints.
h2. Installation
View
@@ -35,13 +35,23 @@
@var API_KEY: Your API key, if you wish to hardcode all API calls to a single
user.
+@type API_PUBLIC_ENDPOINT: C{str}
+@var API_PUBLIC_ENDPOINT: The base URL of the SoftLayer API's XML-RPC
+endpoints over the public Internet.
+
+@type API_PRIVATE_ENDPOINT: C{str}
+@var API_PRIVATE_ENDPOINT: The base URL of the SoftLayer API's XML-RPC
+endpoints over SoftLayer's private network.
+
@type API_BASE_URL: C{str}
@var API_BASE_URL: The base URL for the SoftLayer API's XML-RPC endpoints.
"""
API_USERNAME = None
API_KEY = None
-API_BASE_URL = 'http://api.service.softlayer.com/xmlrpc/v3/'
+API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'
+API_PRIVATE_ENDPOINT = 'http://api.service.softlayer.com/xmlrpc/v3/'
+API_BASE_URL = API_PUBLIC_ENDPOINT
class Client:
@@ -52,15 +62,18 @@ class Client:
made to that service.
@ivar _service_name: The name of the SoftLayer API service to query
+ @ivar _endpoint_url: The base URL to the SoftLayer API's endpoints being
+ used by this client.
@ivar _headers: The headers to send to an API call
@ivar _client: The xmlrpc client used to make calls
"""
_service_name = None
+ _endpoint_url = None
_headers = {}
_xmlrpc_client = None
- def __init__(self, service_name, id=None, username=None, api_key=None):
+ def __init__(self, service_name, id=None, username=None, api_key=None, endpoint_url=None):
"""
Create a SoftLayer API client
@@ -79,6 +92,11 @@ def __init__(self, service_name, id=None, username=None, api_key=None):
@type api_key: C{str}
@param api_key: An optional API key if you wish to bypass the package's
built in API key.
+
+ @type endpoint_url: C{str}
+ @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.
"""
service_name = service_name.strip()
@@ -108,13 +126,24 @@ def __init__(self, service_name, id=None, username=None, api_key=None):
self.set_authentication(user,key)
+ # Default to use the public network API endpoint, otherwise use the
+ # endpoint defined in API_PUBLIC_ENDPOINT, otherwise use the one
+ # provided by the user.
+ if endpoint_url is not None and endpoint_url is not '':
+ endpoint_url = endpoint_url.strip()
+ self._endpoint_url = endpoint_url
+ elif API_BASE_URL is not None and API_BASE_URL is not '':
+ self._endpoint_url = API_BASE_URL
+ else:
+ self._endpoint_url = API_PUBLIC_ENDPOINT
+
# Set a call initialization parameter if we need to.
if id is not None:
self.set_init_parameter(int(id))
# Finally, make an xmlrpc client. We'll use this for all API calls made
# against this client instance.
- self._xmlrpc_client = xmlrpclib.ServerProxy(API_BASE_URL
+ self._xmlrpc_client = xmlrpclib.ServerProxy(self._endpoint_url
+ self._service_name)
def add_header(self, name, value):
"""
View
@@ -11,7 +11,7 @@
setup(
name = 'SoftLayer',
- version = '1.0',
+ version = '1.1',
description = "A library to contact SoftLayer's backend services",
author = 'SoftLayer Technologies, Inc.',
author_email = 'sldn@softlayer.com',

0 comments on commit 4ad879e

Please sign in to comment.