Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding some doc examples - Issues258 #527

Merged
merged 11 commits into from
Aug 11, 2015
46 changes: 46 additions & 0 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class HardwareManager(utils.IdentifierMixin, object):
manager to handle ordering.
If none is provided, one will be
auto initialized.
Example::
# Initialize the Manager.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line is required after Example::

# 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 +55,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 = mrg.cancel_hardware(hardware_id=1234)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be mgr?

"""
# Check to see if this is actually a pre-configured server (BMC). They
# require a different cancellation call.
Expand Down Expand Up @@ -112,6 +125,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 @@ -181,6 +200,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 = mrg.get_hardware(hardware_id=1234,mask=object_mask)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be mgr?

"""

if 'mask' not in kwargs:
Expand Down Expand Up @@ -248,6 +272,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 @@ -259,6 +287,15 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line is required after Example::

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 @@ -503,6 +540,10 @@ def edit(self, hardware_id, userdata=None, hostname=None, domain=None,
:param string domain: valid domain name
:param string notes: notes about this particular hardware

Example::
# Change the hostname on instance 12345 to 'something'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line is required after Example::

result = mgr.edit(hardware_id=12345 , hostname="something")
#result will be True or an Exception
"""

obj = {}
Expand Down Expand Up @@ -539,6 +580,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
38 changes: 38 additions & 0 deletions SoftLayer/managers/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ class SSLManager(object):
"""Manages SSL certificates.

:param SoftLayer.API.Client client: an API client instance

Example::
# Initialize the Manager.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blank line is required after Example::

# 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 +35,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 +59,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 +72,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 +87,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 +102,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)