1- """Get Load balancer details."""
2- # :license: MIT, see LICENSE for more details.
3-
1+ """Get Load Balancer as a Service details."""
42import click
53
64import SoftLayer
75from SoftLayer .CLI import environment
86from SoftLayer .CLI import formatting
9- from SoftLayer . CLI import loadbal
10-
7+ from SoftLayer import utils
8+ from pprint import pprint as pp
119
1210@click .command ()
1311@click .argument ('identifier' )
1412@environment .pass_env
1513def cli (env , identifier ):
16- """Get Load balancer details."""
14+ """Get Load Balancer as a Service details."""
1715 mgr = SoftLayer .LoadBalancerManager (env .client )
1816
19- _ , loadbal_id = loadbal .parse_id (identifier )
17+ lb = mgr .get_lb (identifier )
18+ pp (lb )
19+ table = lbaas_table (lb )
20+
21+ env .fout (table )
2022
21- load_balancer = mgr .get_local_lb (loadbal_id )
2223
24+ def lbaas_table (lb ):
25+ """Generates a table from a list of LBaaS devices"""
2326 table = formatting .KeyValueTable (['name' , 'value' ])
24- table .align ['name' ] = 'l '
27+ table .align ['name' ] = 'r '
2528 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' ]])
29+ table .add_row (['Id' , lb .get ('id' )])
30+ table .add_row (['UUI' , lb .get ('uuid' )])
31+ table .add_row (['Address' , lb .get ('address' )])
32+ table .add_row (['Location' , utils .lookup (lb , 'datacenter' , 'longName' )])
33+ table .add_row (['Description' , lb .get ('description' )])
34+ table .add_row (['Name' , lb .get ('name' )])
35+ table .add_row (['Status' , "{} / {}" .format (lb .get ('provisioningStatus' ), lb .get ('operatingStatus' ))])
3536
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' ])
37+ # https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_HealthMonitor/
38+ hp_table = formatting .Table (['UUID' , 'Interval' , 'Retries' , 'Type' , 'Timeout' , 'Modify' , 'Active' ])
39+ for hp in lb .get ('healthMonitors' , []):
40+ hp_table .add_row ([
41+ hp .get ('uuid' ),
42+ hp .get ('interval' ),
43+ hp .get ('maxRetries' ),
44+ hp .get ('monitorType' ),
45+ hp .get ('timeout' ),
46+ utils .clean_time (hp .get ('modifyDate' )),
47+ hp .get ('provisioningStatus' )
48+ ])
49+ table .add_row (['Checks' , hp_table ])
4050
41- table .add_row (['Service Group %s' % index0 , service_group_table ])
42- index0 += 1
51+ # https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_L7Pool/
52+ l7_table = formatting .Table (['UUID' , 'Balancer' , 'Name' , 'Protocol' , 'Modify' , 'Active' ])
53+ for l7 in lb .get ('l7Pools' , []):
54+ l7_table .add_row ([
55+ l7 .get ('uuid' ),
56+ l7 .get ('loadBalancingAlgorithm' ),
57+ l7 .get ('name' ),
58+ l7 .get ('protocol' ),
59+ utils .clean_time (l7 .get ('modifyDate' )),
60+ l7 .get ('provisioningStatus' )
61+ ])
62+ table .add_row (['L7 Pools' , l7_table ])
4363
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' ])])
64+ pools = {}
65+ # https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Listener/
66+ listener_table = formatting .Table (['UUID' , 'Max Connection' , 'Mapping' , 'Balancer' , 'Modify' , 'Active' ])
67+ for listener in lb .get ('listeners' , []):
68+ pool = listener .get ('defaultPool' )
69+ priv_map = "{}:{}" .format (pool ['protocol' ], pool ['protocolPort' ])
70+ pools [pool ['uuid' ]] = priv_map
71+ mapping = "{}:{} -> {}" .format (listener .get ('protocol' ), listener .get ('protocolPort' ), priv_map )
72+ pool_table = formatting .Table (['Address' , ])
73+ listener_table .add_row ([
74+ listener .get ('uuid' ),
75+ listener .get ('connectionLimit' , 'None' ),
76+ mapping ,
77+ pool .get ('loadBalancingAlgorithm' , 'None' ),
78+ utils .clean_time (listener .get ('modifyDate' )),
79+ listener .get ('provisioningStatus' )
80+ ])
81+ table .add_row (['Pools' , listener_table ])
5882
59- index1 = 1
60- for service in group ['services' ]:
61- service_table = formatting .KeyValueTable (['name' , 'value' ])
83+ # https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Member/
84+ member_col = ['UUID' , 'Address' , 'Weight' , 'Modify' , 'Active' ]
85+ for uuid in pools .keys ():
86+ member_col .append (pools [uuid ])
87+ member_table = formatting .Table (member_col )
88+ for member in lb .get ('members' , []):
89+ row = [
90+ member .get ('uuid' ),
91+ member .get ('address' ),
92+ member .get ('weight' ),
93+ utils .clean_time (member .get ('modifyDate' )),
94+ member .get ('provisioningStatus' )
95+ ]
96+ for uuid in pools .keys ():
97+ row .append (getMemberHp (lb .get ('health' ), member .get ('uuid' ), uuid ))
98+ member_table .add_row (row )
99+ table .add_row (['Members' ,member_table ])
62100
63- service_group_table .add_row (['Service %s' % index1 ,
64- service_table ])
65- index1 += 1
101+ # https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_SSLCipher/
102+ ssl_table = formatting .Table (['Id' , 'Name' ])
103+ for ssl in lb .get ('sslCiphers' , []):
104+ ssl_table .add_row ([ssl .get ('id' ), ssl .get ('name' )])
105+ table .add_row (['Ciphers' , ssl_table ])
106+ return table
66107
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' ]])
108+ def getMemberHp (checks , member_uuid , pool_uuid ):
109+ """Helper function to find a members health in a given pool
80110
81- env .fout (table )
111+ :param checks list: https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Pool/#healthMonitor
112+ :param member_uuid: server UUID we are looking for
113+ :param pool_uuid: Connection pool uuid to search for
114+ """
115+ status = "---"
116+ for check in checks :
117+ if check .get ('poolUuid' ) == pool_uuid :
118+ for hp_member in check .get ('membersHealth' ):
119+ if hp_member .get ('uuid' ) == member_uuid :
120+ status = hp_member .get ('status' )
121+
122+ return status
0 commit comments