Skip to content

Commit 2f7b75f

Browse files
Merge pull request #1549 from ATGE/issues/1541-loadbal-details
Issues/1541 loadbal details
2 parents b07176e + 474f5fb commit 2f7b75f

File tree

4 files changed

+90
-37
lines changed

4 files changed

+90
-37
lines changed

SoftLayer/CLI/loadbal/detail.py

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,33 @@ def lbaas_table(this_lb):
2929
table.align['value'] = 'l'
3030
table.add_row(['Id', this_lb.get('id')])
3131
table.add_row(['UUI', this_lb.get('uuid')])
32+
table.add_row(['Name', this_lb.get('name')])
3233
table.add_row(['Address', this_lb.get('address')])
34+
table.add_row(['Type', SoftLayer.LoadBalancerManager.TYPE.get(this_lb.get('type'))])
3335
table.add_row(['Location', utils.lookup(this_lb, 'datacenter', 'longName')])
3436
table.add_row(['Description', this_lb.get('description')])
35-
table.add_row(['Name', this_lb.get('name')])
3637
table.add_row(['Status', "{} / {}".format(this_lb.get('provisioningStatus'), this_lb.get('operatingStatus'))])
3738

39+
listener_table, pools = get_listener_table(this_lb)
40+
table.add_row(['Protocols', listener_table])
41+
42+
member_table = get_member_table(this_lb, pools)
43+
table.add_row(['Members', member_table])
44+
45+
hp_table = get_hp_table(this_lb)
46+
table.add_row(['Health Checks', hp_table])
47+
48+
l7pool_table = get_l7pool_table(this_lb)
49+
table.add_row(['L7 Pools', l7pool_table])
50+
51+
ssl_table = get_ssl_table(this_lb)
52+
table.add_row(['Ciphers', ssl_table])
53+
54+
return table
55+
56+
57+
def get_hp_table(this_lb):
58+
"""Generates a table from a list of LBaaS devices"""
3859
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_HealthMonitor/
3960
hp_table = formatting.Table(['UUID', 'Interval', 'Retries', 'Type', 'Timeout', 'Modify', 'Active'])
4061
for health in this_lb.get('healthMonitors', []):
@@ -47,44 +68,17 @@ def lbaas_table(this_lb):
4768
utils.clean_time(health.get('modifyDate')),
4869
health.get('provisioningStatus')
4970
])
50-
table.add_row(['Checks', hp_table])
71+
return hp_table
5172

52-
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_L7Pool/
53-
l7_table = formatting.Table(['Id', 'UUID', 'Balancer', 'Name', 'Protocol', 'Modify', 'Active'])
54-
for layer7 in this_lb.get('l7Pools', []):
55-
l7_table.add_row([
56-
layer7.get('id'),
57-
layer7.get('uuid'),
58-
layer7.get('loadBalancingAlgorithm'),
59-
layer7.get('name'),
60-
layer7.get('protocol'),
61-
utils.clean_time(layer7.get('modifyDate')),
62-
layer7.get('provisioningStatus')
63-
])
64-
table.add_row(['L7 Pools', l7_table])
65-
66-
pools = {}
67-
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Listener/
68-
listener_table = formatting.Table(['UUID', 'Max Connection', 'Mapping', 'Balancer', 'Modify', 'Active'])
69-
for listener in this_lb.get('listeners', []):
70-
pool = listener.get('defaultPool')
71-
priv_map = "{}:{}".format(pool['protocol'], pool['protocolPort'])
72-
pools[pool['uuid']] = priv_map
73-
mapping = "{}:{} -> {}".format(listener.get('protocol'), listener.get('protocolPort'), priv_map)
74-
listener_table.add_row([
75-
listener.get('uuid'),
76-
listener.get('connectionLimit', 'None'),
77-
mapping,
78-
pool.get('loadBalancingAlgorithm', 'None'),
79-
utils.clean_time(listener.get('modifyDate')),
80-
listener.get('provisioningStatus')
81-
])
82-
table.add_row(['Pools', listener_table])
8373

74+
def get_member_table(this_lb, pools):
75+
"""Generates a members table from a list of LBaaS devices"""
8476
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Member/
8577
member_col = ['UUID', 'Address', 'Weight', 'Modify', 'Active']
78+
counter = 0
8679
for uuid in pools.values():
87-
member_col.append(uuid)
80+
member_col.append(f'P{counter}-> {uuid}')
81+
counter += 1
8882
member_table = formatting.Table(member_col)
8983
for member in this_lb.get('members', []):
9084
row = [
@@ -97,14 +91,54 @@ def lbaas_table(this_lb):
9791
for uuid in pools:
9892
row.append(get_member_hp(this_lb.get('health'), member.get('uuid'), uuid))
9993
member_table.add_row(row)
100-
table.add_row(['Members', member_table])
94+
return member_table
95+
10196

97+
def get_ssl_table(this_lb):
98+
"""Generates a ssl table from a list of LBaaS devices"""
10299
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_SSLCipher/
103100
ssl_table = formatting.Table(['Id', 'Name'])
104101
for ssl in this_lb.get('sslCiphers', []):
105102
ssl_table.add_row([ssl.get('id'), ssl.get('name')])
106-
table.add_row(['Ciphers', ssl_table])
107-
return table
103+
return ssl_table
104+
105+
106+
def get_listener_table(this_lb):
107+
"""Generates a protocols table from a list of LBaaS devices"""
108+
pools = {}
109+
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Listener/
110+
listener_table = formatting.Table(['UUID', 'Max Connection', 'Mapping', 'Balancer', 'Modify', 'Active'])
111+
for listener in this_lb.get('listeners', []):
112+
pool = listener.get('defaultPool')
113+
priv_map = "{}:{}".format(pool['protocol'], pool['protocolPort'])
114+
pools[pool['uuid']] = priv_map
115+
mapping = "{}:{} -> {}".format(listener.get('protocol'), listener.get('protocolPort'), priv_map)
116+
listener_table.add_row([
117+
listener.get('uuid'),
118+
listener.get('connectionLimit', 'None'),
119+
mapping,
120+
pool.get('loadBalancingAlgorithm', 'None'),
121+
utils.clean_time(listener.get('modifyDate')),
122+
listener.get('provisioningStatus')
123+
])
124+
return listener_table, pools
125+
126+
127+
def get_l7pool_table(this_lb):
128+
"""Generates a l7Pools table from a list of LBaaS devices"""
129+
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_L7Pool/
130+
l7_table = formatting.Table(['Id', 'UUID', 'Balancer', 'Name', 'Protocol', 'Modify', 'Active'])
131+
for layer7 in this_lb.get('l7Pools', []):
132+
l7_table.add_row([
133+
layer7.get('id'),
134+
layer7.get('uuid'),
135+
layer7.get('loadBalancingAlgorithm'),
136+
layer7.get('name'),
137+
layer7.get('protocol'),
138+
utils.clean_time(layer7.get('modifyDate')),
139+
layer7.get('provisioningStatus')
140+
])
141+
return l7_table
108142

109143

110144
def get_member_hp(checks, member_uuid, pool_uuid):

SoftLayer/fixtures/SoftLayer_Network_LBaaS_LoadBalancer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@
5858
'uuid': 'ab1a1abc-0e83-4690-b5d4-1359625dba8f',
5959
}
6060
},
61+
{
62+
'clientTimeout': 15,
63+
'defaultPool': {
64+
'healthMonitor': {
65+
'uuid': '222222ab-bbcc-4f32-9b31-1b6d3a1959c0'
66+
},
67+
'protocol': 'HTTP',
68+
'protocolPort': 256,
69+
'uuid': 'ab1a1abc-0e83-4690-b5d4-1359625dba8x',
70+
}
71+
},
6172
{'connectionLimit': None,
6273
'createDate': '2019-08-21T17:19:25-04:00',
6374
'defaultPool': {'createDate': '2019-08-21T17:19:25-04:00',

SoftLayer/managers/load_balancer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class LoadBalancerManager(utils.IdentifierMixin, object):
1818
:param SoftLayer.API.BaseClient client: the client instance
1919
2020
"""
21+
TYPE = {
22+
1: "Public to Private",
23+
0: "Private to Private",
24+
2: "Public to Public",
25+
}
2126

2227
def __init__(self, client):
2328
self.client = client

tests/CLI/modules/loadbal_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def test_lb_health_update_fails(self, update_lb_health_monitors):
215215
def test_lb_detail(self):
216216
result = self.run_command(['lb', 'detail', '1111111'])
217217
self.assert_no_fail(result)
218+
self.assertIn('Id', result.output)
219+
self.assertIn('UUI', result.output)
220+
self.assertIn('Address', result.output)
218221

219222
def test_lb_detail_by_name(self):
220223
name = SoftLayer_Network_LBaaS_LoadBalancer.getObject.get('name')

0 commit comments

Comments
 (0)