Skip to content

Commit

Permalink
Merge pull request #527 from allmightyspiff/issues258
Browse files Browse the repository at this point in the history
Adding some doc examples - Issues258
  • Loading branch information
underscorephil committed Aug 11, 2015
2 parents 117cfdb + c9e3445 commit 5330151
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 41 deletions.
49 changes: 49 additions & 0 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class HardwareManager(utils.IdentifierMixin, object):
manager to handle ordering.
If none is provided, one will be
auto initialized.
Example::
# Initialize the Manager.
# env variables. These can also be specified in ~/.softlayer,
# or passed directly to SoftLayer.Client()
# SL_USERNAME = YOUR_USERNAME
# SL_API_KEY = YOUR_API_KEY
import SoftLayer
client = SoftLayer.Client()
mgr = SoftLayer.HardwareManager(client)
"""
def __init__(self, client, ordering_manager=None):
self.client = client
Expand All @@ -46,6 +56,10 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='',
come from :func:`get_cancellation_reasons`.
:param string comment: An optional comment to include with the
cancellation.
Example::
# Cancels hardware id 1234
result = mgr.cancel_hardware(hardware_id=1234)
"""

# Get cancel reason
Expand Down Expand Up @@ -83,6 +97,12 @@ def list_hardware(self, tags=None, cpus=None, memory=None, hostname=None,
hardware. This list will contain both dedicated servers and
bare metal computing instances
Example::
# Using a custom object-mask. Will get ONLY what is specified
# These will stem from the SoftLayer_Hardware_Server datatype
object_mask = "mask[hostname,monitoringRobot[robotStatus]]"
result = mgr.list_hardware(mask=object_mask)
"""
if 'mask' not in kwargs:
hw_items = [
Expand Down Expand Up @@ -152,6 +172,11 @@ def get_hardware(self, hardware_id, **kwargs):
:returns: A dictionary containing a large amount of information about
the specified server.
Example::
object_mask = "mask[id,networkVlans[vlanNumber]]"
# Object masks are optional
result = mgr.get_hardware(hardware_id=1234,mask=object_mask)
"""

if 'mask' not in kwargs:
Expand Down Expand Up @@ -219,6 +244,10 @@ def rescue(self, hardware_id):
"""Reboot a server into the a recsue kernel.
:param integer instance_id: the server ID to rescue
Example::
result = mgr.rescue(1234)
"""
return self.hardware.bootToRescueLayer(id=hardware_id)

Expand All @@ -230,6 +259,16 @@ def change_port_speed(self, hardware_id, public, speed):
True (default) means the public interface.
False indicates the private interface.
:param int speed: The port speed to set.
.. warning::
A port speed of 0 will disable the interface.
Example::
#change the Public interface to 10Mbps on instance 12345
result = mgr.change_port_speed(hardware_id=12345,
public=True, speed=10)
# result will be True or an Exception
"""
if public:
func = self.hardware.setPublicNetworkInterfaceSpeed
Expand Down Expand Up @@ -483,6 +522,11 @@ def edit(self, hardware_id, userdata=None, hostname=None, domain=None,
:param string tags: tags to set on the hardware as a comma separated
list. Use the empty string to remove all tags.
Example::
# Change the hostname on instance 12345 to 'something'
result = mgr.edit(hardware_id=12345 , hostname="something")
#result will be True or an Exception
"""

obj = {}
Expand Down Expand Up @@ -522,6 +566,11 @@ def update_firmware(self,
:param bool raid_controller: Update the raid controller firmware.
:param bool bios: Update the bios firmware.
:param bool hard_drive: Update the hard drive firmware.
Example::
# Check the servers active transactions to see progress
result = mgr.update_firmware(hardware_id=1234)
"""

return self.hardware.createFirmwareUpdateTransaction(
Expand Down
39 changes: 39 additions & 0 deletions SoftLayer/managers/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ class SSLManager(object):
"""Manages SSL certificates.
:param SoftLayer.API.Client client: an API client instance
Example::
# Initialize the Manager.
# env variables. These can also be specified in ~/.softlayer,
# or passed directly to SoftLayer.Client()
# SL_USERNAME = YOUR_USERNAME
# SL_API_KEY = YOUR_API_KEY
import SoftLayer
client = SoftLayer.Client()
mgr = SoftLayer.SSLManager(client)
"""

def __init__(self, client):
Expand All @@ -24,6 +36,12 @@ def list_certs(self, method='all'):
'all', 'expired', and 'valid'.
:returns: A list of dictionaries representing the requested SSL certs.
Example::
# Get all valid SSL certs
certs = mgr.list_certs(method='valid')
print certs
"""
ssl = self.client['Account']
methods = {
Expand All @@ -42,6 +60,11 @@ def add_certificate(self, certificate):
:param dict certificate: A dictionary representing the parts of the
certificate. See SLDN for more information.
Example::
cert = ??
result = mgr.add_certificate(certificate=cert)
"""
return self.ssl.createObject(certificate)

Expand All @@ -50,6 +73,10 @@ def remove_certificate(self, cert_id):
:param integer cert_id: a certificate ID to remove
Example::
# Removes certificate with id 1234
result = mgr.remove_certificate(cert_id = 1234)
"""
return self.ssl.deleteObject(id=cert_id)

Expand All @@ -61,6 +88,13 @@ def edit_certificate(self, certificate):
:param dict certificate: the certificate to update.
Example::
# Updates the cert id 1234
cert['id'] = 1234
cert['certificate'] = ??
result = mgr.edit_certificate(certificate=cert)
"""
return self.ssl.editObject(certificate, id=certificate['id'])

Expand All @@ -69,5 +103,10 @@ def get_certificate(self, cert_id):
:param integer cert_id: the certificate ID to retrieve
Example::
cert = mgr.get_certificate(cert_id=1234)
print(cert)
"""
return self.ssl.getObject(id=cert_id)

0 comments on commit 5330151

Please sign in to comment.