Skip to content

Commit fe403e1

Browse files
tox style fixes
1 parent 9322d60 commit fe403e1

11 files changed

Lines changed: 185 additions & 399 deletions

File tree

SoftLayer/CLI/loadbal/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
"""Load balancers."""
2-

SoftLayer/CLI/loadbal/detail.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,72 @@
55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import formatting
77
from SoftLayer import utils
8-
from pprint import pprint as pp
8+
99

1010
@click.command()
1111
@click.argument('identifier')
1212
@environment.pass_env
1313
def cli(env, identifier):
1414
"""Get Load Balancer as a Service details."""
1515
mgr = SoftLayer.LoadBalancerManager(env.client)
16-
uuid, lbid = mgr.get_lbaas_uuid_id(identifier)
17-
lb = mgr.get_lb(lbid)
18-
# pp(lb)
19-
if lb.get('previousErrorText'):
20-
print("THERE WAS AN ERROR")
21-
print(lb.get('previousErrorText'))
22-
table = lbaas_table(lb)
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)
2321

2422
env.fout(table)
2523

2624

27-
def lbaas_table(lb):
25+
def lbaas_table(this_lb):
2826
"""Generates a table from a list of LBaaS devices"""
2927
table = formatting.KeyValueTable(['name', 'value'])
3028
table.align['name'] = 'r'
3129
table.align['value'] = 'l'
32-
table.add_row(['Id', lb.get('id')])
33-
table.add_row(['UUI', lb.get('uuid')])
34-
table.add_row(['Address', lb.get('address')])
35-
table.add_row(['Location', utils.lookup(lb, 'datacenter', 'longName')])
36-
table.add_row(['Description', lb.get('description')])
37-
table.add_row(['Name', lb.get('name')])
38-
table.add_row(['Status', "{} / {}".format(lb.get('provisioningStatus'), lb.get('operatingStatus'))])
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'))])
3937

4038
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_HealthMonitor/
4139
hp_table = formatting.Table(['UUID', 'Interval', 'Retries', 'Type', 'Timeout', 'Modify', 'Active'])
42-
for hp in lb.get('healthMonitors', []):
40+
for health in this_lb.get('healthMonitors', []):
4341
hp_table.add_row([
44-
hp.get('uuid'),
45-
hp.get('interval'),
46-
hp.get('maxRetries'),
47-
hp.get('monitorType'),
48-
hp.get('timeout'),
49-
utils.clean_time(hp.get('modifyDate')),
50-
hp.get('provisioningStatus')
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')
5149
])
5250
table.add_row(['Checks', hp_table])
5351

5452
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_L7Pool/
55-
l7_table = formatting.Table(['Id', 'UUID', 'Balancer', 'Name', 'Protocol', 'Modify', 'Active' ])
56-
for l7 in lb.get('l7Pools', []):
53+
l7_table = formatting.Table(['Id', 'UUID', 'Balancer', 'Name', 'Protocol', 'Modify', 'Active'])
54+
for layer7 in this_lb.get('l7Pools', []):
5755
l7_table.add_row([
58-
l7.get('id'),
59-
l7.get('uuid'),
60-
l7.get('loadBalancingAlgorithm'),
61-
l7.get('name'),
62-
l7.get('protocol'),
63-
utils.clean_time(l7.get('modifyDate')),
64-
l7.get('provisioningStatus')
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')
6563
])
6664
table.add_row(['L7 Pools', l7_table])
6765

6866
pools = {}
6967
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Listener/
7068
listener_table = formatting.Table(['UUID', 'Max Connection', 'Mapping', 'Balancer', 'Modify', 'Active'])
71-
for listener in lb.get('listeners', []):
69+
for listener in this_lb.get('listeners', []):
7270
pool = listener.get('defaultPool')
7371
priv_map = "{}:{}".format(pool['protocol'], pool['protocolPort'])
7472
pools[pool['uuid']] = priv_map
7573
mapping = "{}:{} -> {}".format(listener.get('protocol'), listener.get('protocolPort'), priv_map)
76-
pool_table = formatting.Table(['Address', ])
7774
listener_table.add_row([
7875
listener.get('uuid'),
7976
listener.get('connectionLimit', 'None'),
@@ -86,30 +83,31 @@ def lbaas_table(lb):
8683

8784
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Member/
8885
member_col = ['UUID', 'Address', 'Weight', 'Modify', 'Active']
89-
for uuid in pools.keys():
86+
for uuid in pools:
9087
member_col.append(pools[uuid])
9188
member_table = formatting.Table(member_col)
92-
for member in lb.get('members', []):
89+
for member in this_lb.get('members', []):
9390
row = [
9491
member.get('uuid'),
9592
member.get('address'),
9693
member.get('weight'),
9794
utils.clean_time(member.get('modifyDate')),
9895
member.get('provisioningStatus')
9996
]
100-
for uuid in pools.keys():
101-
row.append(getMemberHp(lb.get('health'), member.get('uuid'), uuid))
97+
for uuid in pools:
98+
row.append(get_member_hp(this_lb.get('health'), member.get('uuid'), uuid))
10299
member_table.add_row(row)
103-
table.add_row(['Members',member_table])
100+
table.add_row(['Members', member_table])
104101

105102
# https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_SSLCipher/
106103
ssl_table = formatting.Table(['Id', 'Name'])
107-
for ssl in lb.get('sslCiphers', []):
104+
for ssl in this_lb.get('sslCiphers', []):
108105
ssl_table.add_row([ssl.get('id'), ssl.get('name')])
109106
table.add_row(['Ciphers', ssl_table])
110107
return table
111108

112-
def getMemberHp(checks, member_uuid, pool_uuid):
109+
110+
def get_member_hp(checks, member_uuid, pool_uuid):
113111
"""Helper function to find a members health in a given pool
114112
115113
:param checks list: https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_LBaaS_Pool/#healthMonitor
@@ -123,4 +121,4 @@ def getMemberHp(checks, member_uuid, pool_uuid):
123121
if hp_member.get('uuid') == member_uuid:
124122
status = hp_member.get('status')
125123

126-
return status
124+
return status

SoftLayer/CLI/loadbal/health.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
import SoftLayer
55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import exceptions
7-
from SoftLayer.CLI import formatting
8-
from SoftLayer.CLI import helpers
97
from SoftLayer import utils
10-
from pprint import pprint as pp
8+
119

1210
@click.command()
1311
@click.argument('identifier')
1412
@click.option('--uuid', required=True, help="Health check UUID to modify.")
15-
@click.option('--interval', '-i', type=click.IntRange(2, 60), help="Seconds between checks. [2-60]")
13+
@click.option('--interval', '-i', type=click.IntRange(2, 60), help="Seconds between checks. [2-60]")
1614
@click.option('--retry', '-r', type=click.IntRange(1, 10), help="Number of times before marking as DOWN. [1-10]")
1715
@click.option('--timeout', '-t', type=click.IntRange(1, 59), help="Seconds to wait for a connection. [1-59]")
1816
@click.option('--url', '-u', help="Url path for HTTP/HTTPS checks.")
1917
@environment.pass_env
20-
def cli(env, identifier, uuid, interval, retry, timeout, url):
18+
def cli(env, identifier, uuid, interval, retry, timeout, url):
2119
"""Manage LBaaS health checks."""
2220

2321
if not any([interval, retry, timeout, url]):
2422
raise exceptions.ArgumentError("Specify either interval, retry, timeout, url")
2523

2624
# map parameters to expected API names
27-
template = {'healthMonitorUuid': uuid, 'interval': interval, 'maxRetries': retry, 'timeout': timeout, 'urlPath': url}
25+
template = {'healthMonitorUuid': uuid, 'interval': interval,
26+
'maxRetries': retry, 'timeout': timeout, 'urlPath': url}
2827
# Removes those empty values
2928
clean_template = {k: v for k, v in template.items() if v is not None}
3029

@@ -49,20 +48,16 @@ def cli(env, identifier, uuid, interval, retry, timeout, url):
4948
check['timeout'] = utils.lookup(listener, 'defaultPool', 'healthMonitor', 'timeout')
5049
check['urlPath'] = utils.lookup(listener, 'defaultPool', 'healthMonitor', 'urlPath')
5150

52-
5351
if url and check['backendProtocol'] == 'TCP':
5452
raise exceptions.ArgumentError('--url cannot be used with TCP checks')
5553

5654
# Update existing check with supplied values
5755
for key in clean_template.keys():
5856
check[key] = clean_template[key]
5957

60-
result = mgr.updateLoadBalancerHealthMonitors(lb_uuid, [check])
58+
result = mgr.update_lb_health_monitors(lb_uuid, [check])
6159

6260
if result:
6361
click.secho('Health Check {} updated successfully'.format(uuid), fg='green')
6462
else:
6563
click.secho('ERROR: Failed to update {}'.format(uuid), fg='red')
66-
67-
68-

SoftLayer/CLI/loadbal/list.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from SoftLayer.CLI import environment
66
from SoftLayer.CLI import formatting
77
from SoftLayer import utils
8-
from pprint import pprint as pp
8+
99

1010
@click.command()
1111
@environment.pass_env
@@ -22,9 +22,9 @@ def cli(env):
2222
env.fout("No LBaaS devices found")
2323

2424

25-
def location_sort(x):
25+
def location_sort(location):
2626
"""Quick function that just returns the datacenter longName for sorting"""
27-
return utils.lookup(x, 'datacenter', 'longName')
27+
return utils.lookup(location, 'datacenter', 'longName')
2828

2929

3030
def generate_lbaas_table(lbaas):
@@ -36,19 +36,17 @@ def generate_lbaas_table(lbaas):
3636
table.align['Address'] = 'l'
3737
table.align['Description'] = 'l'
3838
table.align['Location'] = 'l'
39-
for lb in sorted(lbaas,key=location_sort):
40-
print("PUBLIC: {}".format(lb.get('isPublic')))
39+
for this_lb in sorted(lbaas, key=location_sort):
4140
table.add_row([
42-
lb.get('id'),
43-
utils.lookup(lb, 'datacenter', 'longName'),
44-
lb.get('address'),
45-
lb.get('description'),
46-
'Yes' if lb.get('isPublic', 1) == 1 else 'No',
47-
utils.clean_time(lb.get('createDate')),
48-
lb.get('memberCount', 0),
49-
lb.get('listenerCount', 0)
41+
this_lb.get('id'),
42+
utils.lookup(this_lb, 'datacenter', 'longName'),
43+
this_lb.get('address'),
44+
this_lb.get('description'),
45+
'Yes' if this_lb.get('isPublic', 1) == 1 else 'No',
46+
utils.clean_time(this_lb.get('createDate')),
47+
this_lb.get('memberCount', 0),
48+
this_lb.get('listenerCount', 0)
5049

5150

5251
])
5352
return table
54-

SoftLayer/CLI/loadbal/members.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
import click
33

44
import SoftLayer
5-
from SoftLayer.CLI import environment, formatting, helpers
5+
from SoftLayer.CLI import environment
66
from SoftLayer.exceptions import SoftLayerAPIError
7-
from SoftLayer import utils
8-
from pprint import pprint as pp
7+
98

109
@click.command()
1110
@click.argument('identifier')
1211
@click.option('--member', '-m', required=True, help="Member UUID")
1312
@environment.pass_env
14-
def remove(env, identifier, member):
13+
def remove(env, identifier, member):
1514
"""Remove a LBaaS member.
1615
1716
Member UUID can be found from `slcli lb detail`.
1817
"""
1918

2019
mgr = SoftLayer.LoadBalancerManager(env.client)
2120

22-
uuid, lbid = mgr.get_lbaas_uuid_id(identifier)
21+
uuid, _ = mgr.get_lbaas_uuid_id(identifier)
2322
# Get a member ID to remove
2423

2524
try:
26-
result = mgr.delete_lb_member(uuid, member)
25+
mgr.delete_lb_member(uuid, member)
2726
click.secho("Member {} removed".format(member), fg='green')
28-
except SoftLayerAPIError as e:
29-
click.secho("ERROR: {}".format(e.faultString), fg='red')
27+
except SoftLayerAPIError as exception:
28+
click.secho("ERROR: {}".format(exception.faultString), fg='red')
3029

3130

3231
@click.command()
@@ -35,11 +34,11 @@ def remove(env, identifier, member):
3534
@click.option('--member', '-m', required=True, help="Member IP address.")
3635
@click.option('--weight', '-w', default=50, type=int, help="Weight of this member.")
3736
@environment.pass_env
38-
def add(env, identifier, private, member, weight):
37+
def add(env, identifier, private, member, weight):
3938
"""Add a new LBaaS members."""
4039

4140
mgr = SoftLayer.LoadBalancerManager(env.client)
42-
uuid, lbid = mgr.get_lbaas_uuid_id(identifier)
41+
uuid, _ = mgr.get_lbaas_uuid_id(identifier)
4342
# Get a server ID to add
4443
to_add = {"weight": weight}
4544
if private:
@@ -48,15 +47,11 @@ def add(env, identifier, private, member, weight):
4847
to_add['publicIpAddress'] = member
4948

5049
try:
51-
result = mgr.add_lb_member(uuid, to_add)
50+
mgr.add_lb_member(uuid, to_add)
5251
click.secho("Member {} added".format(member), fg='green')
53-
except SoftLayerAPIError as e:
54-
if 'publicIpAddress must be a string' in e.faultString:
52+
except SoftLayerAPIError as exception:
53+
if 'publicIpAddress must be a string' in exception.faultString:
5554
click.secho("This LB requires a Public IP address for its members and none was supplied", fg='red')
56-
elif 'privateIpAddress must be a string' in e.faultString:
55+
elif 'privateIpAddress must be a string' in exception.faultString:
5756
click.secho("This LB requires a Private IP address for its members and none was supplied", fg='red')
58-
click.secho("ERROR: {}".format(e.faultString), fg='red')
59-
60-
61-
62-
57+
click.secho("ERROR: {}".format(exception.faultString), fg='red')

SoftLayer/CLI/loadbal/ns_detail.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ def cli(env, identifier):
1414
"""Get Netscaler details."""
1515
mgr = SoftLayer.LoadBalancerManager(env.client)
1616

17-
lb = mgr.get_adc(identifier)
18-
table = netscaler_table(lb)
17+
this_lb = mgr.get_adc(identifier)
18+
table = netscaler_table(this_lb)
1919
env.fout(table)
2020

2121

22-
def netscaler_table(lb):
22+
def netscaler_table(this_lb):
23+
"""Formats the netscaler info table"""
2324
table = formatting.KeyValueTable(['name', 'value'])
2425
table.align['name'] = 'r'
2526
table.align['value'] = 'l'
26-
table.add_row(['Id', lb.get('id')])
27-
table.add_row(['Type', lb.get('description')])
28-
table.add_row(['Name', lb.get('name')])
29-
table.add_row(['Location', utils.lookup(lb, 'datacenter', 'longName')])
30-
table.add_row(['Managment Ip', lb.get('managementIpAddress')])
31-
table.add_row(['Root Password', utils.lookup(lb, 'password', 'password')])
32-
table.add_row(['Primary Ip', lb.get('primaryIpAddress')])
33-
table.add_row(['License Expiration', utils.clean_time(lb.get('licenseExpirationDate'))])
27+
table.add_row(['Id', this_lb.get('id')])
28+
table.add_row(['Type', this_lb.get('description')])
29+
table.add_row(['Name', this_lb.get('name')])
30+
table.add_row(['Location', utils.lookup(this_lb, 'datacenter', 'longName')])
31+
table.add_row(['Managment Ip', this_lb.get('managementIpAddress')])
32+
table.add_row(['Root Password', utils.lookup(this_lb, 'password', 'password')])
33+
table.add_row(['Primary Ip', this_lb.get('primaryIpAddress')])
34+
table.add_row(['License Expiration', utils.clean_time(this_lb.get('licenseExpirationDate'))])
3435
subnet_table = formatting.Table(['Id', 'Subnet', 'Type', 'Space'])
35-
for subnet in lb.get('subnets', []):
36+
for subnet in this_lb.get('subnets', []):
3637
subnet_table.add_row([
3738
subnet.get('id'),
3839
"{}/{}".format(subnet.get('networkIdentifier'), subnet.get('cidr')),
@@ -42,7 +43,7 @@ def netscaler_table(lb):
4243
table.add_row(['Subnets', subnet_table])
4344

4445
vlan_table = formatting.Table(['Id', 'Number'])
45-
for vlan in lb.get('networkVlans', []):
46+
for vlan in this_lb.get('networkVlans', []):
4647
vlan_table.add_row([vlan.get('id'), vlan.get('vlanNumber')])
4748
table.add_row(['Vlans', vlan_table])
4849

0 commit comments

Comments
 (0)