Skip to content

Commit f8c09f2

Browse files
author
Nathan Beittenmiller
committed
Merge pull request softlayer#141 from sudorandom/v3
Consistency Updates/Puts CLI more on par with API in docs
2 parents 23c2744 + 2923ac3 commit f8c09f2

13 files changed

Lines changed: 203 additions & 200 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
SoftLayer API Python Client
22
===========================
33
SoftLayer API bindings for Python. For use with
4-
[SoftLayer's API](http://sldn.softlayer.com/reference/softlayerapi). For more
5-
documentation, [go here](http://softlayer.github.com/softlayer-api-python-client/).
4+
[SoftLayer's API](http://sldn.softlayer.com/reference/softlayerapi).
5+
6+
* [Module Documentation](http://softlayer.github.com/softlayer-api-python-client)
7+
* [API Documentation](http://softlayer.github.com/softlayer-api-python-client/client.html)
8+
* [CLI Documentation](http://softlayer.github.com/softlayer-api-python-client/cli.html)
69

710
This library provides a simple interface to interact with SoftLayer's XML-RPC
811
API and provides support for many of SoftLayer API's features like

SoftLayer/API.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
:copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved.
77
:license: BSD, see LICENSE for more details.
88
"""
9-
from SoftLayer.consts import API_PUBLIC_ENDPOINT, API_PRIVATE_ENDPOINT, \
10-
USER_AGENT
11-
from SoftLayer.transport import make_xml_rpc_api_call
12-
from SoftLayer.exceptions import SoftLayerError
9+
from consts import API_PUBLIC_ENDPOINT, API_PRIVATE_ENDPOINT, USER_AGENT
10+
from transport import make_xml_rpc_api_call
11+
from exceptions import SoftLayerError
12+
from auth import BasicAuthentication, TokenAuthentication
1313
import os
1414

1515

16-
__all__ = ['Client', 'BasicAuthentication', 'TokenAuthentication',
17-
'API_PUBLIC_ENDPOINT', 'API_PRIVATE_ENDPOINT']
16+
__all__ = ['Client', 'API_PUBLIC_ENDPOINT', 'API_PRIVATE_ENDPOINT']
1817

1918
API_USERNAME = None
2019
API_KEY = None
@@ -30,46 +29,6 @@
3029
])
3130

3231

33-
class AuthenticationBase(object):
34-
def get_headers(self):
35-
raise NotImplementedError
36-
37-
38-
class TokenAuthentication(AuthenticationBase):
39-
def __init__(self, user_id, auth_token):
40-
self.user_id = user_id
41-
self.auth_token = auth_token
42-
43-
def get_headers(self):
44-
return {
45-
'authenticate': {
46-
'complexType': 'PortalLoginToken',
47-
'userId': self.user_id,
48-
'authToken': self.auth_token,
49-
}
50-
}
51-
52-
def __repr__(self):
53-
return "<TokenAuthentication: %s %s>" % (self.user_id, self.auth_token)
54-
55-
56-
class BasicAuthentication(AuthenticationBase):
57-
def __init__(self, username, api_key):
58-
self.username = username
59-
self.api_key = api_key
60-
61-
def get_headers(self):
62-
return {
63-
'authenticate': {
64-
'username': self.username,
65-
'apiKey': self.api_key,
66-
}
67-
}
68-
69-
def __repr__(self):
70-
return "<BasicAuthentication: %s>" % (self.username)
71-
72-
7332
class Client(object):
7433
""" A SoftLayer API client.
7534

SoftLayer/CLI/modules/bmetal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class CancelInstance(CLIRunnable):
473473
474474
Options:
475475
--immediate Cancels the instance immediately (instead of on the billing
476-
anniversary).
476+
anniversary).
477477
"""
478478

479479
action = 'cancel'

SoftLayer/CLI/modules/dns.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
44
Manage DNS
55
6-
The available commands are:
7-
edit Update resource records (bulk/single)
6+
The available zone commands are:
87
create Create zone
8+
delete Delete zone
99
list List zones or a zone's records
10-
remove Remove resource records
11-
add Add resource record
1210
print Print zone in BIND format
13-
delete Delete zone
11+
12+
The available record commands are:
13+
add Add resource record
14+
edit Update resource records (bulk/single)
15+
remove Remove resource records
1416
"""
1517
# :copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved.
1618
# :license: BSD, see LICENSE for more details.

SoftLayer/CLI/modules/hardware.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
Manage hardware
66
77
The available commands are:
8-
list List hardware devices
9-
detail Retrieve hardware details
10-
reload Perform an OS reload
11-
cancel Cancel a dedicated server.
8+
list List hardware devices
9+
detail Retrieve hardware details
10+
reload Perform an OS reload
11+
cancel Cancel a dedicated server.
1212
cancel-reasons Provides the list of possible cancellation reasons
13-
network Manage network settings
13+
network Manage network settings
1414
list-chassis Provide a list of all chassis available for ordering
1515
create-options Display a list of creation options for a specific chassis
16-
create Create a new dedicated server
16+
create Create a new dedicated server
1717
1818
For several commands, <identifier> will be asked for. This can be the id,
1919
hostname or the ip address for a piece of hardware.
@@ -35,9 +35,9 @@ class ListHardware(CLIRunnable):
3535
List hardware servers on the acount
3636
3737
Examples:
38-
sl hardware list --datacenter=dal05
39-
sl hardware list --network=100 --domain=example.com
40-
sl hardware list --tags=production,db
38+
sl hardware list --datacenter=dal05
39+
sl hardware list --network=100 --domain=example.com
40+
sl hardware list --tags=production,db
4141
4242
Options:
4343
--sortby=ARG Column to sort by. options: id, datacenter, host, cores,
@@ -180,8 +180,8 @@ class HardwareReload(CLIRunnable):
180180
Reload the OS on a hardware server based on its current configuration
181181
182182
Optional:
183-
-i, --postinstall=URI Post-install script to download
184-
(Only HTTPS executes, HTTP leaves file in /root)
183+
-i, --postinstall=URI Post-install script to download
184+
(Only HTTPS executes, HTTP leaves file in /root)
185185
"""
186186

187187
action = 'reload'
@@ -261,7 +261,7 @@ class NetworkHardware(CLIRunnable):
261261
262262
Options:
263263
--speed=SPEED Port speed. 0 disables the port.
264-
[Options: 0, 10, 100, 1000, 10000]
264+
[Options: 0, 10, 100, 1000, 10000]
265265
--public Public network
266266
--private Private network
267267
"""

SoftLayer/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
from API import * # NOQA
2020
from managers import * # NOQA
21-
from SoftLayer.exceptions import * # NOQA
21+
from exceptions import * # NOQA
22+
from auth import * # NOQA
2223

2324
__title__ = 'SoftLayer'
2425
__version__ = VERSION

SoftLayer/auth.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
SoftLayer.auth
3+
~~~~~~~~~~~~~~
4+
Module with the supported auth mechanisms for the SoftLayer API
5+
6+
:copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved.
7+
:license: BSD, see LICENSE for more details.
8+
"""
9+
__all__ = ['BasicAuthentication', 'TokenAuthentication', 'AuthenticationBase']
10+
11+
12+
class AuthenticationBase(object):
13+
def get_headers(self):
14+
raise NotImplementedError
15+
16+
17+
class TokenAuthentication(AuthenticationBase):
18+
def __init__(self, user_id, auth_token):
19+
self.user_id = user_id
20+
self.auth_token = auth_token
21+
22+
def get_headers(self):
23+
return {
24+
'authenticate': {
25+
'complexType': 'PortalLoginToken',
26+
'userId': self.user_id,
27+
'authToken': self.auth_token,
28+
}
29+
}
30+
31+
def __repr__(self):
32+
return "<TokenAuthentication: %s %s>" % (self.user_id, self.auth_token)
33+
34+
35+
class BasicAuthentication(AuthenticationBase):
36+
def __init__(self, username, api_key):
37+
self.username = username
38+
self.api_key = api_key
39+
40+
def get_headers(self):
41+
return {
42+
'authenticate': {
43+
'username': self.username,
44+
'apiKey': self.api_key,
45+
}
46+
}
47+
48+
def __repr__(self):
49+
return "<BasicAuthentication: %s>" % (self.username)

SoftLayer/tests/api_tests.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -261,55 +261,3 @@ def test_authenticate_with_password(self, _call):
261261
self.assertIsNotNone(self.client.auth)
262262
self.assertEquals(self.client.auth.user_id, 12345)
263263
self.assertEquals(self.client.auth.auth_token, 'TOKEN')
264-
265-
266-
class TestAuthenticationBase(unittest.TestCase):
267-
def test_get_headers(self):
268-
auth = SoftLayer.API.AuthenticationBase()
269-
self.assertRaises(NotImplementedError, auth.get_headers)
270-
271-
272-
class TestBasicAuthentication(unittest.TestCase):
273-
def setUp(self):
274-
self.auth = SoftLayer.BasicAuthentication('USERNAME', 'APIKEY')
275-
276-
def test_attribs(self):
277-
self.assertEquals(self.auth.username, 'USERNAME')
278-
self.assertEquals(self.auth.api_key, 'APIKEY')
279-
280-
def test_get_headers(self):
281-
self.assertEquals(self.auth.get_headers(), {
282-
'authenticate': {
283-
'username': 'USERNAME',
284-
'apiKey': 'APIKEY',
285-
}
286-
})
287-
288-
def test_repr(self):
289-
s = repr(self.auth)
290-
self.assertIn('BasicAuthentication', s)
291-
self.assertIn('USERNAME', s)
292-
293-
294-
class TestTokenAuthentication(unittest.TestCase):
295-
def setUp(self):
296-
self.auth = SoftLayer.TokenAuthentication(12345, 'TOKEN')
297-
298-
def test_attribs(self):
299-
self.assertEquals(self.auth.user_id, 12345)
300-
self.assertEquals(self.auth.auth_token, 'TOKEN')
301-
302-
def test_get_headers(self):
303-
self.assertEquals(self.auth.get_headers(), {
304-
'authenticate': {
305-
'complexType': 'PortalLoginToken',
306-
'userId': 12345,
307-
'authToken': 'TOKEN',
308-
}
309-
})
310-
311-
def test_repr(self):
312-
s = repr(self.auth)
313-
self.assertIn('TokenAuthentication', s)
314-
self.assertIn('12345', s)
315-
self.assertIn('TOKEN', s)

SoftLayer/tests/auth_tests.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
SoftLayer.tests.auth_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:copyright: (c) 2013, SoftLayer Technologies, Inc. All rights reserved.
6+
:license: BSD, see LICENSE for more details.
7+
"""
8+
try:
9+
import unittest2 as unittest
10+
except ImportError:
11+
import unittest # NOQA
12+
13+
from SoftLayer.auth import (
14+
AuthenticationBase, BasicAuthentication, TokenAuthentication)
15+
16+
17+
class TestAuthenticationBase(unittest.TestCase):
18+
def test_get_headers(self):
19+
auth = AuthenticationBase()
20+
self.assertRaises(NotImplementedError, auth.get_headers)
21+
22+
23+
class TestBasicAuthentication(unittest.TestCase):
24+
def setUp(self):
25+
self.auth = BasicAuthentication('USERNAME', 'APIKEY')
26+
27+
def test_attribs(self):
28+
self.assertEquals(self.auth.username, 'USERNAME')
29+
self.assertEquals(self.auth.api_key, 'APIKEY')
30+
31+
def test_get_headers(self):
32+
self.assertEquals(self.auth.get_headers(), {
33+
'authenticate': {
34+
'username': 'USERNAME',
35+
'apiKey': 'APIKEY',
36+
}
37+
})
38+
39+
def test_repr(self):
40+
s = repr(self.auth)
41+
self.assertIn('BasicAuthentication', s)
42+
self.assertIn('USERNAME', s)
43+
44+
45+
class TestTokenAuthentication(unittest.TestCase):
46+
def setUp(self):
47+
self.auth = TokenAuthentication(12345, 'TOKEN')
48+
49+
def test_attribs(self):
50+
self.assertEquals(self.auth.user_id, 12345)
51+
self.assertEquals(self.auth.auth_token, 'TOKEN')
52+
53+
def test_get_headers(self):
54+
self.assertEquals(self.auth.get_headers(), {
55+
'authenticate': {
56+
'complexType': 'PortalLoginToken',
57+
'userId': 12345,
58+
'authToken': 'TOKEN',
59+
}
60+
})
61+
62+
def test_repr(self):
63+
s = repr(self.auth)
64+
self.assertIn('TokenAuthentication', s)
65+
self.assertIn('12345', s)
66+
self.assertIn('TOKEN', s)

0 commit comments

Comments
 (0)