Skip to content

Commit 15fc1a2

Browse files
Merge pull request #1167 from softlayer/loadbalancers
New Feature: Loadbalancers
2 parents 11dac93 + b29a24a commit 15fc1a2

39 files changed

+1895
-1026
lines changed

SoftLayer/CLI/loadbal/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
11
"""Load balancers."""
2-
3-
from SoftLayer.CLI import exceptions
4-
5-
6-
def parse_id(input_id):
7-
"""Parse the load balancer kind and actual id from the "kind:id" form."""
8-
parts = input_id.split(':')
9-
if len(parts) != 2:
10-
raise exceptions.CLIAbort(
11-
'Invalid ID %s: ID should be of the form "kind:id"' % input_id)
12-
return parts[0], int(parts[1])

SoftLayer/CLI/loadbal/cancel.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

SoftLayer/CLI/loadbal/create.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

SoftLayer/CLI/loadbal/create_options.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

SoftLayer/CLI/loadbal/detail.py

Lines changed: 100 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,124 @@
1-
"""Get Load balancer details."""
2-
# :license: MIT, see LICENSE for more details.
3-
1+
"""Get Load Balancer as a Service details."""
42
import click
53

64
import SoftLayer
75
from SoftLayer.CLI import environment
86
from SoftLayer.CLI import formatting
9-
from SoftLayer.CLI import loadbal
7+
from SoftLayer import utils
108

119

1210
@click.command()
1311
@click.argument('identifier')
1412
@environment.pass_env
1513
def cli(env, identifier):
16-
"""Get Load balancer details."""
14+
"""Get Load Balancer as a Service details."""
1715
mgr = SoftLayer.LoadBalancerManager(env.client)
16+
_, lbid = mgr.get_lbaas_uuid_id(identifier)
17+
this_lb = mgr.get_lb(lbid)
18+
if this_lb.get('previousErrorText'):
19+
print(this_lb.get('previousErrorText'))
20+
table = lbaas_table(this_lb)
1821

19-
_, loadbal_id = loadbal.parse_id(identifier)
22+
env.fout(table)
2023

21-
load_balancer = mgr.get_local_lb(loadbal_id)
2224

25+
def lbaas_table(this_lb):
26+
"""Generates a table from a list of LBaaS devices"""
2327
table = formatting.KeyValueTable(['name', 'value'])
24-
table.align['name'] = 'l'
28+
table.align['name'] = 'r'
2529
table.align['value'] = 'l'
26-
table.add_row(['ID', 'local:%s' % load_balancer['id']])
27-
table.add_row(['IP Address', load_balancer['ipAddress']['ipAddress']])
28-
name = load_balancer['loadBalancerHardware'][0]['datacenter']['name']
29-
table.add_row(['Datacenter', name])
30-
table.add_row(['Connections limit', load_balancer['connectionLimit']])
31-
table.add_row(['Dedicated', load_balancer['dedicatedFlag']])
32-
table.add_row(['HA', load_balancer['highAvailabilityFlag']])
33-
table.add_row(['SSL Enabled', load_balancer['sslEnabledFlag']])
34-
table.add_row(['SSL Active', load_balancer['sslActiveFlag']])
30+
table.add_row(['Id', this_lb.get('id')])
31+
table.add_row(['UUI', this_lb.get('uuid')])
32+
table.add_row(['Address', this_lb.get('address')])
33+
table.add_row(['Location', utils.lookup(this_lb, 'datacenter', 'longName')])
34+
table.add_row(['Description', this_lb.get('description')])
35+
table.add_row(['Name', this_lb.get('name')])
36+
table.add_row(['Status', "{} / {}".format(this_lb.get('provisioningStatus'), this_lb.get('operatingStatus'))])
3537

36-
index0 = 1
37-
for virtual_server in load_balancer['virtualServers']:
38-
for group in virtual_server['serviceGroups']:
39-
service_group_table = formatting.KeyValueTable(['name', 'value'])
38+
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_HealthMonitor/
39+
hp_table = formatting.Table(['UUID', 'Interval', 'Retries', 'Type', 'Timeout', 'Modify', 'Active'])
40+
for health in this_lb.get('healthMonitors', []):
41+
hp_table.add_row([
42+
health.get('uuid'),
43+
health.get('interval'),
44+
health.get('maxRetries'),
45+
health.get('monitorType'),
46+
health.get('timeout'),
47+
utils.clean_time(health.get('modifyDate')),
48+
health.get('provisioningStatus')
49+
])
50+
table.add_row(['Checks', hp_table])
4051

41-
table.add_row(['Service Group %s' % index0, service_group_table])
42-
index0 += 1
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])
4365

44-
service_group_table.add_row(['Guest ID',
45-
virtual_server['id']])
46-
service_group_table.add_row(['Port', virtual_server['port']])
47-
service_group_table.add_row(['Allocation',
48-
'%s %%' %
49-
virtual_server['allocation']])
50-
service_group_table.add_row(['Routing Type',
51-
'%s:%s' %
52-
(group['routingTypeId'],
53-
group['routingType']['name'])])
54-
service_group_table.add_row(['Routing Method',
55-
'%s:%s' %
56-
(group['routingMethodId'],
57-
group['routingMethod']['name'])])
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])
5883

59-
index1 = 1
60-
for service in group['services']:
61-
service_table = formatting.KeyValueTable(['name', 'value'])
84+
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Member/
85+
member_col = ['UUID', 'Address', 'Weight', 'Modify', 'Active']
86+
for uuid in pools:
87+
member_col.append(pools[uuid])
88+
member_table = formatting.Table(member_col)
89+
for member in this_lb.get('members', []):
90+
row = [
91+
member.get('uuid'),
92+
member.get('address'),
93+
member.get('weight'),
94+
utils.clean_time(member.get('modifyDate')),
95+
member.get('provisioningStatus')
96+
]
97+
for uuid in pools:
98+
row.append(get_member_hp(this_lb.get('health'), member.get('uuid'), uuid))
99+
member_table.add_row(row)
100+
table.add_row(['Members', member_table])
62101

63-
service_group_table.add_row(['Service %s' % index1,
64-
service_table])
65-
index1 += 1
102+
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_SSLCipher/
103+
ssl_table = formatting.Table(['Id', 'Name'])
104+
for ssl in this_lb.get('sslCiphers', []):
105+
ssl_table.add_row([ssl.get('id'), ssl.get('name')])
106+
table.add_row(['Ciphers', ssl_table])
107+
return table
66108

67-
health_check = service['healthChecks'][0]
68-
service_table.add_row(['Service ID', service['id']])
69-
service_table.add_row(['IP Address',
70-
service['ipAddress']['ipAddress']])
71-
service_table.add_row(['Port', service['port']])
72-
service_table.add_row(['Health Check',
73-
'%s:%s' %
74-
(health_check['healthCheckTypeId'],
75-
health_check['type']['name'])])
76-
service_table.add_row(
77-
['Weight', service['groupReferences'][0]['weight']])
78-
service_table.add_row(['Enabled', service['enabled']])
79-
service_table.add_row(['Status', service['status']])
80109

81-
env.fout(table)
110+
def get_member_hp(checks, member_uuid, pool_uuid):
111+
"""Helper function to find a members health in a given pool
112+
113+
:param checks list: https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Pool/#healthMonitor
114+
:param member_uuid: server UUID we are looking for
115+
:param pool_uuid: Connection pool uuid to search for
116+
"""
117+
status = "---"
118+
for check in checks:
119+
if check.get('poolUuid') == pool_uuid:
120+
for hp_member in check.get('membersHealth'):
121+
if hp_member.get('uuid') == member_uuid:
122+
status = hp_member.get('status')
123+
124+
return status

SoftLayer/CLI/loadbal/group_add.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

SoftLayer/CLI/loadbal/group_delete.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)