Skip to content

Commit b3c8ff4

Browse files
author
Nathan Beittenmiller
committed
Adding more CCI documentation and tweaking some hardware docs. Fixed a TOC issue I caused when rearranging the manager docs.
1 parent 3f31da6 commit b3c8ff4

File tree

3 files changed

+97
-17
lines changed

3 files changed

+97
-17
lines changed

SoftLayer/managers/cci.py

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
SoftLayer.CCI
2+
SoftLayer.cci
33
~~~~~~~~~~~~~
44
CCI Manager/helpers
55
@@ -17,9 +17,16 @@ class CCIManager(IdentifierMixin, object):
1717
""" Manage CCIs """
1818
def __init__(self, client):
1919
self.client = client
20+
""" A valid `SoftLayer.API.Client` object that will be used for all
21+
actions. """
2022
self.account = client['Account']
23+
""" Reference to the SoftLayer_Account API object. """
2124
self.guest = client['Virtual_Guest']
25+
""" Reference to the SoftLayer_Virtual_Guest API object. """
2226
self.resolvers = [self._get_ids_from_ip, self._get_ids_from_hostname]
27+
""" A list of resolver functions. Used primarily by the CLI to provide
28+
a variety of methods for uniquely identifying an object such as
29+
hostname and IP address."""
2330

2431
def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
2532
memory=None, hostname=None, domain=None,
@@ -40,6 +47,21 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
4047
:param string public_ip: filter based on public ip address
4148
:param string private_ip: filter based on private ip address
4249
:param dict \*\*kwargs: response-level arguments (limit, offset, etc.)
50+
:returns: Returns an array of dictionaries representing the matching
51+
CCIs.
52+
53+
::
54+
55+
# Print out a list of all hourly CCIs in the DAL05 data center.
56+
# env variables
57+
# SL_USERNAME = YOUR_USERNAME
58+
# SL_API_KEY = YOUR_API_KEY
59+
import SoftLayer
60+
client = SoftLayer.Client()
61+
62+
mgr = SoftLayer.CCIManager(client)
63+
for cci in mgr.list_instances(hourly=True, datacenter='dal05'):
64+
print cci['fullyQualifiedDomainName'], cci['primaryIpAddress']
4365
4466
"""
4567
if 'mask' not in kwargs:
@@ -115,6 +137,8 @@ def get_instance(self, id, **kwargs):
115137
""" Get details about a CCI instance
116138
117139
:param integer id: the instance ID
140+
:returns: A dictionary containing a large amount of information about
141+
the specified instance.
118142
119143
"""
120144

@@ -157,6 +181,11 @@ def get_instance(self, id, **kwargs):
157181
return self.guest.getObject(id=id, **kwargs)
158182

159183
def get_create_options(self):
184+
""" Retrieves the available options for creating a CCI.
185+
186+
:returns: A dictionary of creation options.
187+
188+
"""
160189
return self.guest.getCreateObjectOptions()
161190

162191
def cancel_instance(self, id):
@@ -192,6 +221,37 @@ def _generate_create_dict(
192221
datacenter=None, os_code=None, image_id=None,
193222
private=False, public_vlan=None, private_vlan=None,
194223
userdata=None, nic_speed=None, disks=None, post_uri=None):
224+
"""
225+
Translates a list of arguments into a dictionary necessary for creating
226+
a CCI.
227+
228+
:param int cpus: The number of virtual CPUs to include in the instance.
229+
:param int memory: The amount of RAM to order.
230+
:param bool hourly: Flag to indicate if this server should be billed
231+
hourly (default) or monthly.
232+
:param string hostname: The hostname to use for the new server.
233+
:param string domain: The domain to use for the new server.
234+
:param bool local_disk: Flag to indicate if this should be a local disk
235+
(default) or a SAN disk.
236+
:param string datacenter: The short name of the data center in which
237+
the CCI should reside.
238+
:param string os_code: The operating system to use. Cannot be specified
239+
if image_id is specified.
240+
:param int image_id: The ID of the image to load onto the server.
241+
Cannot be specified if os_code is specified.
242+
:param bool private: Flag to indicate if this should be housed on a
243+
private or shared host (default). This will incur
244+
a fee on your account.
245+
:param int public_vlan: The ID of the public VLAN on which you want
246+
this CCI placed.
247+
:param int private_vlan: The ID of the public VLAN on which you want
248+
this CCI placed.
249+
:param bool bare_metal: Flag to indicate if this is a bare metal server
250+
or a dedicated server (default).
251+
:param list disks: A list of disk capacities for this server.
252+
:param string post_url: The URI of the post-install script to run
253+
after reload
254+
"""
195255

196256
required = [cpus, memory, hostname, domain]
197257

@@ -265,6 +325,13 @@ def _generate_create_dict(
265325
return data
266326

267327
def wait_for_transaction(self, id, limit, delay=1):
328+
""" Waits on a CCI transaction for the specified amount of time.
329+
330+
:param int id: The instance ID with the pending transaction
331+
:param int limit: The maximum amount of time to wait.
332+
:param int delay: The number of seconds to sleep before checks.
333+
Defaults to 1.
334+
"""
268335
for count, new_instance in enumerate(repeat(id)):
269336
instance = self.get_instance(new_instance)
270337
if not instance.get('activeTransaction', {}).get('id') and \
@@ -277,16 +344,27 @@ def wait_for_transaction(self, id, limit, delay=1):
277344
sleep(delay)
278345

279346
def verify_create_instance(self, **kwargs):
280-
""" see _generate_create_dict """ # TODO: document this
347+
""" Verifies an instance creation command without actually placing an
348+
order. See :func:`_generate_create_dict` for a list of available
349+
options. """
281350
create_options = self._generate_create_dict(**kwargs)
282351
return self.guest.generateOrderTemplate(create_options)
283352

284353
def create_instance(self, **kwargs):
285-
""" see _generate_create_dict """ # TODO: document this
354+
""" Orders a new instance. See :func:`_generate_create_dict` for
355+
a list of available options. """
286356
create_options = self._generate_create_dict(**kwargs)
287357
return self.guest.createObject(create_options)
288358

289359
def change_port_speed(self, id, public, speed):
360+
""" Allows you to change the port speed of a CCI's NICs.
361+
362+
:param int id: The ID of the CCI
363+
:param bool public: Flag to indicate which interface to change.
364+
True (default) means the public interface.
365+
False indicates the private interface.
366+
:param int speed: The port speed to set.
367+
"""
290368
if public:
291369
func = self.guest.setPublicNetworkInterfaceSpeed
292370
else:

SoftLayer/managers/hardware.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ def change_port_speed(self, id, public, speed):
291291
292292
:param int id: The ID of the server
293293
:param bool public: Flag to indicate which interface to change.
294-
True (default) means the public interface.
295-
False indicates the private interface.
294+
True (default) means the public interface.
295+
False indicates the private interface.
296296
:param int speed: The port speed to set.
297297
"""
298298
if public:
@@ -312,7 +312,7 @@ def place_order(self, **kwargs):
312312
following sample for an example of using HardwareManager functions
313313
for ordering a basic server.
314314
315-
.. code-block:: python
315+
::
316316
317317
# client is assumed to be an initialized SoftLayer.API.Client object
318318
mgr = HardwareManager(client)
@@ -405,10 +405,10 @@ def _generate_create_dict(
405405
.. warning::
406406
All items here must be price IDs, NOT quantities!
407407
408-
:param string server: The identification string for the server to
409-
order. This will either be the CPU/Memory
410-
combination ID for bare metal instances or the
411-
CPU model for dedicated servers.
408+
:param int server: The identification string for the server to
409+
order. This will either be the CPU/Memory
410+
combination ID for bare metal instances or the
411+
CPU model for dedicated servers.
412412
:param string hostname: The hostname to use for the new server.
413413
:param string domain: The domain to use for the new server.
414414
:param bool hourly: Flag to indicate if this server should be billed

docs/api/client.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ For day to day operation, most users will find the managers to be the most conve
6161
>>> cci.list_instances()
6262
[...]
6363

64+
Available Managers:
65+
~~~~~~~~~~~~~~~~~~~
66+
67+
.. toctree::
68+
:maxdepth: 2
69+
:glob:
70+
71+
managers/*
72+
6473
If you need more power or functionality than the managers provide, you can make direct API calls as well.
6574

6675

@@ -150,13 +159,6 @@ API Reference
150159
:undoc-members:
151160

152161

153-
.. toctree::
154-
:maxdepth: 2
155-
:glob:
156-
157-
managers/*
158-
159-
160162
Backwards Compatibility
161163
-----------------------
162164
As of 3.0, the old API methods and parameters no longer work. Below are examples of converting the old API to the new one.

0 commit comments

Comments
 (0)