Skip to content

Commit 281fa0e

Browse files
committed
currently BillingManager is not working ...first round of checkin
1 parent 067cd65 commit 281fa0e

File tree

5 files changed

+62
-23
lines changed

5 files changed

+62
-23
lines changed

SoftLayer/CLI/billing/info.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""List BIlling information of Accounts."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
from SoftLayer import utils
9+
10+
import click
11+
12+
13+
@click.command()
14+
@environment.pass_env
15+
def cli(env):
16+
"""List billing information for accounts."""
17+
billing = SoftLayer.BillingManager(env.client)
18+
table = formatting.Table(['Name','Value'])
19+
info = billing.get_info()
20+
print info
21+
table.add_row(['id', info['id']])
22+
table.add_row(['paymentTerms', info['paymentTerms']])
23+
table.add_row(['modifyDate', info['modifyDate']])
24+
table.add_row(['anniversaryDayOfMonth', info['anniversaryDayOfMonth']])
25+
table.add_row(['lastFourPaymentCardDigits', info['lastFourPaymentCardDigits']])
26+
table.add_row(['cardExpirationMonth', info['cardExpirationMonth']])
27+
table.add_row(['cardExpirationYear', info['cardExpirationYear']])
28+
table.add_row(['percentDiscountOnetime', info['percentDiscountOnetime']])
29+
table.add_row(['sparePoolAmount', info['sparePoolAmount']])
30+
table.add_row(['lastPaymentDate', info['lastPaymentDate']])
31+
table.add_row(['createDate', info['createDate']])
32+
table.add_row(['percentDiscountRecurring', info['percentDiscountRecurring']])
33+
pass_table = formatting.Table(['Name', 'Value'])
34+
d = info['currency']
35+
print d
36+
for key in d.keys():
37+
print key, d[key]
38+
pass_table.add_row([key,d[key]])
39+
table.add_row(['currency',pass_table ])
40+
41+
42+
return table

SoftLayer/CLI/billing/list.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
@click.option('--group', '-g',
1818
help='grouping by a resource type e.g server, iscsi etc.')
1919
@click.option('--resource', '-r',
20-
help='shows only cost of the active(running)/inactive resources',
21-
type=click.Choice(['guid',
22-
'hostname',
23-
'primary_ip',
24-
'backend_ip',
25-
'datacenter']))
20+
help='shows only cost of the active/inactive resources',
21+
type=click.Choice(['active',
22+
'inactive']))
2623
@environment.pass_env
2724
def cli(env, frmdate, enddate, group, resource):
2825
"""List billing information for accounts."""
@@ -33,16 +30,7 @@ def cli(env, frmdate, enddate, group, resource):
3330
resource_status = resource
3431
table = formatting.Table(['Order ID', 'Resource Name', 'Resource Type',
3532
'cost', 'create_date'])
36-
resources = billing.list_resources(from_date, to_date, group_by)
37-
print resources
38-
for resource in resources:
39-
resource = utils.NestedDict(resource)
40-
table.add_row([
41-
resource['id'],
42-
resource['hostName'],
43-
resource['resourceType'],
44-
resource['cost'],
45-
resource['createDate']
46-
])
33+
result = billing.list_resources(from_date, to_date, group_by)
34+
4735

4836
return table

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
ALL_ROUTES = [
1010
('billing', 'SoftLayer.CLI.billing'),
1111
('billing:list', 'SoftLayer.CLI.billing.list:cli'),
12+
('billing:info', 'SoftLayer.CLI.billing.info:cli'),
1213

1314
('call-api', 'SoftLayer.CLI.call_api:cli'),
1415

SoftLayer/CLI/virt/detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def cli(self, identifier, passwords=False, price=False):
5757
)])
5858
table.add_row(['os_version',
5959
operating_system.get('version') or formatting.blank()])
60-
table.add_row(['cores', result['maxCpu']])
60+
('billing:list', 'SoftLayer.CLI.billing.list:cli'),
6161
table.add_row(['memory', formatting.mb_to_gb(result['maxMemory'])])
6262
table.add_row(['public_ip',
6363
result['primaryIpAddress'] or formatting.blank()])

SoftLayer/managers/billing.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ def __init__(self, client):
3636
self.account = self.client['Account']
3737
self.billing_order = self.client['Billing_Order']
3838

39-
def list_resources(self, from_date=None, to_date=None, group_by=None, **kwargs):
39+
def get_info(self):
40+
result = self.account.getBillingInfo()
41+
return result
42+
43+
44+
def list_resources(self, from_date=None, to_date=None, group_by=None, resource_status=None, **kwargs):
4045
""" Retrieve a list of all ordered resources along with their costing.
4146
4247
:param dict \\*\\*kwargs: response-level option (limit)
@@ -69,23 +74,25 @@ def list_resources(self, from_date=None, to_date=None, group_by=None, **kwargs):
6974
user = self.account.getCurrentUser(mask='mask[id]')
7075
_filter['orders']['userRecordId'] = query_filter(user['id'])
7176
date_format = '%Y-%m-%d'
72-
print user
77+
7378
if from_date:
7479
from_date_filter = from_date + '*'
7580
_filter['orders']['createDate'] = query_filter(from_date_filter)
7681
if to_date:
7782
to_date_filter = to_date + '*'
7883
_filter['orders']['createDate'] = query_filter(to_date_filter)
7984
if group_by:
80-
group_by_filter = '~' + group_by
81-
_filter['orders']['description'] = query_filter()
85+
group_by_filter = '*' + group_by
86+
_filter['orders']['description'] = query_filter(group_by_filter)
8287
orders = self.account.getOrders(filter=_filter.to_dict())
83-
print orders
8488
total = 0.0
8589
result = []
8690

8791
for order in orders:
92+
print order
93+
print order['id'], order['orderTypeId']
8894
billing_order = self.client['Billing_Order']
95+
8996
params['id'] = order_id = order['id']
9097
items = billing_order.getItems(**params)
9198
cost = float(0.0)
@@ -97,6 +104,7 @@ def list_resources(self, from_date=None, to_date=None, group_by=None, **kwargs):
97104
cancellation_date = ''
98105

99106
for item in items:
107+
#print item
100108
if flag == 1:
101109
resource_type = item['description']
102110

0 commit comments

Comments
 (0)