Skip to content

Commit cc46a13

Browse files
Merge pull request #1432 from caberos/issue1424
Add routers for each DC in `slcli hw create-options`
2 parents 62cbfbd + fa9da6a commit cc46a13

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

SoftLayer/CLI/hardware/create_options.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from SoftLayer.CLI import environment
77
from SoftLayer.CLI import formatting
8+
from SoftLayer.managers import account
89
from SoftLayer.managers import hardware
910

1011

@@ -18,8 +19,9 @@ def cli(env, prices, location=None):
1819
"""Server order options for a given chassis."""
1920

2021
hardware_manager = hardware.HardwareManager(env.client)
22+
account_manager = account.AccountManager(env.client)
2123
options = hardware_manager.get_create_options(location)
22-
24+
routers = account_manager.get_routers(location)
2325
tables = []
2426

2527
# Datacenters
@@ -34,6 +36,7 @@ def cli(env, prices, location=None):
3436
tables.append(_os_prices_table(options['operating_systems'], prices))
3537
tables.append(_port_speed_prices_table(options['port_speeds'], prices))
3638
tables.append(_extras_prices_table(options['extras'], prices))
39+
tables.append(_get_routers(routers))
3740

3841
# since this is multiple tables, this is required for a valid JSON object to be rendered.
3942
env.fout(formatting.listing(tables, separator='\n'))
@@ -50,7 +53,7 @@ def _preset_prices_table(sizes, prices=False):
5053
for size in sizes:
5154
if size.get('hourlyRecurringFee', 0) + size.get('recurringFee', 0) + 1 > 0:
5255
table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'],
53-
"%.4f" % size['recurringFee']])
56+
"%.4f" % size['recurringFee']])
5457
else:
5558
table = formatting.Table(['Size', 'Value'], title="Sizes")
5659
for size in sizes:
@@ -146,3 +149,18 @@ def _get_price_data(price, item):
146149
if item in price:
147150
result = price[item]
148151
return result
152+
153+
154+
def _get_routers(routers):
155+
"""Get all routers information
156+
157+
:param routers: Routers data
158+
"""
159+
160+
table = formatting.Table(["id", "hostname", "name"], title='Routers')
161+
for router in routers:
162+
table.add_row([router['id'],
163+
router['hostname'],
164+
router['topLevelLocation']['longName'], ])
165+
table.align = 'l'
166+
return table

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,3 +1020,21 @@
10201020
"resourceTableId": 777777
10211021
}
10221022
]
1023+
1024+
getRouters = [
1025+
{
1026+
"accountId": 1,
1027+
"bareMetalInstanceFlag": 0,
1028+
"domain": "softlayer.com",
1029+
"fullyQualifiedDomainName": "fcr01a.ams01.softlayer.com",
1030+
"hardwareStatusId": 5,
1031+
"hostname": "fcr01a.ams01",
1032+
"id": 123456,
1033+
"serviceProviderId": 1,
1034+
"topLevelLocation": {
1035+
"id": 265592,
1036+
"longName": "Amsterdam 1",
1037+
"name": "ams01",
1038+
"statusId": 2
1039+
}
1040+
}]

SoftLayer/managers/account.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,20 @@ def get_account_all_billing_orders(self, limit=100, mask=None):
276276
"""
277277
return self.client.call('Billing_Order', 'getAllObjects',
278278
limit=limit, mask=mask)
279+
280+
def get_routers(self, mask=None, location=None):
281+
"""Gets all the routers currently active on the account
282+
283+
:param string mask: Object Mask
284+
:param string location: location string
285+
:returns: Routers
286+
"""
287+
object_filter = ''
288+
if location:
289+
object_filter = {
290+
'routers': {
291+
'topLevelLocation': {'name': {'operation': location}}
292+
}
293+
}
294+
295+
return self.client['SoftLayer_Account'].getRouters(filter=object_filter, mask=mask)

tests/managers/account_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ def test_get_item_details_with_invoice_item_id(self):
149149
self.manager.get_item_detail(123456)
150150
self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier=123456)
151151
self.assert_called_with('SoftLayer_Billing_Invoice_Item', 'getBillingItem', identifier=123456)
152+
153+
def test_get_routers(self):
154+
self.manager.get_routers()
155+
self.assert_called_with("SoftLayer_Account", "getRouters")

0 commit comments

Comments
 (0)