Skip to content

Commit b7b70f1

Browse files
code cleanup and docs
1 parent ef9494f commit b7b70f1

File tree

8 files changed

+67
-10
lines changed

8 files changed

+67
-10
lines changed

SoftLayer/CLI/account/event_detail.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def cli(env, identifier, ack):
3232

3333

3434
def basic_event_table(event):
35+
"""Formats a basic event table"""
3536
table = formatting.Table(["Id", "Status", "Type", "Start", "End"], title=event.get('subject'))
3637

3738
table.add_row([
@@ -46,6 +47,7 @@ def basic_event_table(event):
4647

4748

4849
def impacted_table(event):
50+
"""Formats a basic impacted resources table"""
4951
table = formatting.Table([
5052
"Type", "Id", "hostname", "privateIp", "Label"
5153
])
@@ -61,6 +63,7 @@ def impacted_table(event):
6163

6264

6365
def update_table(event):
66+
"""Formats a basic event update table"""
6467
update_number = 0
6568
for update in event.get('updates', []):
6669
header = "======= Update #%s on %s =======" % (update_number, utils.clean_time(update.get('startDate')))

SoftLayer/CLI/account/events.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
"""Summary and acknowledgement of upcoming and ongoing maintenance events"""
22
# :license: MIT, see LICENSE for more details.
3-
from pprint import pprint as pp
43
import click
54

65
import SoftLayer
76
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import exceptions
97
from SoftLayer.CLI import formatting
108
from SoftLayer.managers.account import AccountManager as AccountManager
119
from SoftLayer import utils
@@ -18,7 +16,6 @@
1816
def cli(env, ack_all):
1917
"""Summary and acknowledgement of upcoming and ongoing maintenance events"""
2018

21-
# Print a list of all on going maintenance
2219
manager = AccountManager(env.client)
2320
events = manager.get_upcoming_events()
2421

@@ -27,9 +24,6 @@ def cli(env, ack_all):
2724
result = manager.ack_event(event['id'])
2825
event['acknowledgedFlag'] = result
2926
env.fout(event_table(events))
30-
# pp(events)
31-
32-
# Allow ack all, or ack specific maintenance
3327

3428

3529
def event_table(events):

SoftLayer/CLI/account/invoice_detail.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import exceptions
98
from SoftLayer.CLI import formatting
109
from SoftLayer.managers.account import AccountManager as AccountManager
1110
from SoftLayer import utils
12-
from pprint import pprint as pp
1311

1412

1513
@click.command()
@@ -60,4 +58,5 @@ def cli(env, identifier, details):
6058

6159

6260
def nice_string(ugly_string, limit=100):
61+
"""Format and trims strings"""
6362
return (ugly_string[:limit] + '..') if len(ugly_string) > limit else ugly_string

SoftLayer/CLI/account/invoices.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
def cli(env, limit, closed=False, get_all=False):
2222
"""Invoices and all that mess"""
2323

24-
# List invoices
25-
2624
manager = AccountManager(env.client)
2725
invoices = manager.get_invoices(limit, closed, get_all)
2826

SoftLayer/managers/account.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def __init__(self, client):
2727
self.client = client
2828

2929
def get_summary(self):
30+
"""Gets some basic account information
31+
32+
:return: Account object
33+
"""
3034
mask = """mask[
3135
nextInvoiceTotalAmount,
3236
pendingInvoice[invoiceTotalAmount],
@@ -45,6 +49,10 @@ def get_summary(self):
4549
return self.client.call('Account', 'getObject', mask=mask)
4650

4751
def get_upcoming_events(self):
52+
"""Retreives a list of Notification_Occurrence_Events that have not ended yet
53+
54+
:return: SoftLayer_Notification_Occurrence_Event
55+
"""
4856
mask = "mask[id, subject, startDate, endDate, statusCode, acknowledgedFlag, impactedResourceCount, updateCount]"
4957
_filter = {
5058
'endDate': {
@@ -61,9 +69,19 @@ def get_upcoming_events(self):
6169
return self.client.call('Notification_Occurrence_Event', 'getAllObjects', filter=_filter, mask=mask, iter=True)
6270

6371
def ack_event(self, event_id):
72+
"""Acknowledge an event. This mostly prevents it from appearing as a notification in the control portal.
73+
74+
:param int event_id: Notification_Occurrence_Event ID you want to ack
75+
:return: True on success, Exception otherwise.
76+
"""
6477
return self.client.call('Notification_Occurrence_Event', 'acknowledgeNotification', id=event_id)
6578

6679
def get_event(self, event_id):
80+
"""Gets details about a maintenance event
81+
82+
:param int event_id: Notification_Occurrence_Event ID
83+
:return: Notification_Occurrence_Event
84+
"""
6785
mask = """mask[
6886
acknowledgedFlag,
6987
attachments,
@@ -75,6 +93,13 @@ def get_event(self, event_id):
7593
return self.client.call('Notification_Occurrence_Event', 'getObject', id=event_id, mask=mask)
7694

7795
def get_invoices(self, limit=50, closed=False, get_all=False):
96+
"""Gets an accounts invoices.
97+
98+
:param int limit: Number of invoices to get back in a single call.
99+
:param bool closed: If True, will also get CLOSED invoices
100+
:param bool get_all: If True, will paginate through invoices until all have been retrieved.
101+
:return: Billing_Invoice
102+
"""
78103
mask = "mask[invoiceTotalAmount, itemCount]"
79104
_filter = {
80105
'invoices': {
@@ -94,6 +119,11 @@ def get_invoices(self, limit=50, closed=False, get_all=False):
94119
return self.client.call('Account', 'getInvoices', mask=mask, filter=_filter, iter=get_all, limit=limit)
95120

96121
def get_billing_items(self, identifier):
122+
"""Gets all topLevelBillingItems from a specific invoice
123+
124+
:param int identifier: Invoice Id
125+
:return: Billing_Invoice_Item
126+
"""
97127

98128
mask = """mask[
99129
id, description, hostName, domainName, oneTimeAfterTaxAmount, recurringAfterTaxAmount, createDate,

SoftLayer/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ def clean_string(string):
291291

292292

293293
def clean_time(sltime, in_format='%Y-%m-%dT%H:%M:%S%z', out_format='%Y-%m-%d %H:%M'):
294+
"""Easy way to format time strings
294295
296+
:param string sltime: A softlayer formatted time string
297+
:param string in_format: Datetime format for strptime
298+
:param string out_format: Datetime format for strftime
299+
"""
295300
clean = datetime.datetime.strptime(sltime, in_format)
296301
return clean.strftime(out_format)

docs/api/managers/account.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. _account:
2+
3+
.. automodule:: SoftLayer.managers.account
4+
:members:
5+
:inherited-members:

docs/cli/account.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. _cli_account:
2+
3+
Account Commands
4+
5+
.. click:: SoftLayer.cli.account.summary:cli
6+
:prog: account summary
7+
:show-nested:
8+
9+
.. click:: SoftLayer.cli.account.events:cli
10+
:prog: account events
11+
:show-nested:
12+
13+
.. click:: SoftLayer.cli.account.event-detail:cli
14+
:prog: account event-detail
15+
:show-nested:
16+
17+
.. click:: SoftLayer.cli.account.invoices:cli
18+
:prog: account invoices
19+
:show-nested:
20+
21+
.. click:: SoftLayer.cli.account.invoice-detail:cli
22+
:prog: account invoice-detail
23+
:show-nested:

0 commit comments

Comments
 (0)