Skip to content

Commit 4dc4e32

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
Merge branch 'master' of https://github.com/softlayer/softlayer-python into issue_2003
2 parents e029225 + 3f13fe8 commit 4dc4e32

21 files changed

+434
-8
lines changed

SoftLayer/CLI/bandwidth/pools.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def cli(env):
3131
"Allocation",
3232
"Current Usage",
3333
"Projected Usage",
34-
"Cost"
34+
"Cost",
35+
"Deletion"
3536
], title="Bandwidth Pools")
3637
table.align = 'l'
3738
for item in items:
@@ -55,5 +56,10 @@ def cli(env):
5556
else:
5657
cost = "$0.0"
5758

58-
table.add_row([id_bandwidth, name, region, servers, allocation, current, projected, cost])
59+
deletion = utils.clean_time(item.get('endDate'))
60+
61+
if deletion == '':
62+
deletion = formatting.blank()
63+
64+
table.add_row([id_bandwidth, name, region, servers, allocation, current, projected, cost, deletion])
5965
env.fout(table)

SoftLayer/CLI/bandwidth/pools_create.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,42 @@
2121
"FRA": "FRA"
2222
}
2323

24+
regions = ['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR', 'SNG/HKG/OSA/TOK', 'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']
25+
26+
27+
def check_region_param(ctx, param, value): # pylint: disable=unused-argument
28+
"""Check if provided region is region group or part of region"""
29+
30+
# :params string value: Region or Region-Groups
31+
# return string Region-Groups
32+
33+
region_group = None
34+
for key in location_groups:
35+
if value in key or value is key:
36+
region_group = key
37+
38+
if region_group:
39+
return region_group
40+
else:
41+
raise click.BadParameter(f"{value} is not a region or part of any region."
42+
" Available Choices: ['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR',"
43+
" 'SNG/HKG/OSA/TOK', 'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']")
44+
2445

2546
@click.command(cls=SLCommand)
2647
@click.option('--name', required=True, help="Pool name")
2748
@click.option('--region', required=True,
28-
type=click.Choice(['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR', 'SNG/HKG/OSA/TOK',
29-
'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']),
30-
help="Region selected")
49+
help=f"Choose Region/Region-Group {regions}", callback=check_region_param)
50+
@click.help_option('--help', '-h')
3151
@environment.pass_env
3252
def cli(env, name, region):
33-
"""Create bandwidth pool."""
53+
"""Create bandwidth pool.
54+
55+
Region can be the full zone name 'SJC/DAL/WDC/TOR/MON', or just a single datacenter like 'SJC'.
56+
Example::
57+
slcli bandwidth pool-create --name testPool --region DAL
58+
slcli bandwidth pool-create --name testPool --region SJC/DAL/WDC/TOR/MON
59+
"""
3460

3561
manager = BandwidthManager(env.client)
3662
locations = manager.get_location_group()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Delete bandwidth pool."""
2+
# :license: MIT, see LICENSE for more details.
3+
import click
4+
5+
from SoftLayer import BandwidthManager
6+
from SoftLayer.CLI.command import SLCommand as SLCommand
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command(cls=SLCommand)
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""Delete bandwidth pool."""
15+
16+
manager = BandwidthManager(env.client)
17+
manager.delete_pool(identifier)
18+
env.fout(f"Bandwidth pool {identifier} has been scheduled for deletion.")

SoftLayer/CLI/bandwidth/pools_detail.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def cli(env, identifier):
2424
table.add_row(['Id', bandwidths['id']])
2525
table.add_row(['Name', bandwidths['name']])
2626
table.add_row(['Create Date', utils.clean_time(bandwidths.get('createDate'), '%Y-%m-%d')])
27+
end_date = utils.clean_time(bandwidths.get('endDate'))
28+
if end_date == '':
29+
end_date = formatting.blank()
30+
table.add_row(['End Date', end_date])
31+
else:
32+
table.add_row(['End Date', utils.clean_time(bandwidths.get('endDate'))])
2733
current = f"{utils.lookup(bandwidths, 'billingCyclePublicBandwidthUsage', 'amountOut')} GB"
2834
if current is None:
2935
current = '-'
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Add a new load balancer protocol."""
2+
import click
3+
4+
import SoftLayer
5+
from SoftLayer.CLI import environment
6+
from SoftLayer.CLI import exceptions
7+
from SoftLayer.CLI import formatting
8+
9+
10+
# pylint: disable=unused-argument
11+
def parse_proto(ctx, param, value):
12+
"""Parses the frontend and backend cli options"""
13+
proto = {'protocol': 'HTTP', 'port': 80}
14+
splitout = value.split(':')
15+
if len(splitout) != 2:
16+
raise exceptions.ArgumentError("{}={} is not properly formatted.".format(param, value))
17+
proto['protocol'] = splitout[0]
18+
proto['port'] = int(splitout[1])
19+
return proto
20+
21+
22+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
23+
@click.argument('identifier')
24+
@click.option('--frontend', '-f', required=True, default='HTTP:80', show_default=True, callback=parse_proto,
25+
help='PROTOCOL:PORT string for incoming internet connections.')
26+
@click.option('--backend', '-b', required=True, default='HTTP:80', show_default=True, callback=parse_proto,
27+
help='PROTOCOL:PORT string for connecting to backend servers.')
28+
@click.option('--method', '-m', help="Balancing Method.", default='ROUNDROBIN', show_default=True,
29+
type=click.Choice(['ROUNDROBIN', 'LEASTCONNECTION', 'WEIGHTED_RR']))
30+
@click.option('--session', '-s', required=True,
31+
help="Session stickiness type. Valid values are SOURCE_IP or HTTP_COOKIE ")
32+
@click.option('--max', help="Max Connections setting", type=int)
33+
@environment.pass_env
34+
def cli(env, identifier, **args):
35+
"""Add a new load balancer protocol."""
36+
37+
mgr = SoftLayer.LoadBalancerManager(env.client)
38+
39+
uuid = mgr.get_lb_uuid(identifier)
40+
41+
backend = args.get('backend')
42+
frontend = args.get('frontend')
43+
protocols = [
44+
{
45+
"backendPort": backend.get('port'),
46+
"backendProtocol": backend.get('protocol'),
47+
"frontendPort": frontend.get('port'),
48+
"frontendProtocol": frontend.get('protocol'),
49+
"loadBalancingMethod": args.get('method'),
50+
"sessionType": args.get('session'),
51+
"maxConn": args.get('max')
52+
}
53+
]
54+
55+
protocol = mgr.add_protocols(uuid, protocols)
56+
57+
table = formatting.KeyValueTable(['name', 'value'])
58+
table.align['name'] = 'r'
59+
table.align['value'] = 'l'
60+
table.add_row(['Id', protocol.get('id')])
61+
table.add_row(['UUI', protocol.get('uuid')])
62+
table.add_row(['Address', protocol.get('address')])
63+
table.add_row(['Type', mgr.get_lb_type(protocol.get('type'))])
64+
table.add_row(['Description', protocol.get('description')])
65+
66+
env.fout(table)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Delete load balancer protocol."""
2+
import click
3+
4+
import SoftLayer
5+
from SoftLayer.CLI import environment
6+
from SoftLayer.CLI import formatting
7+
8+
9+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
10+
@click.argument('identifier')
11+
@click.option('--uuid', help="Load Balancer Uuid.")
12+
@environment.pass_env
13+
def cli(env, identifier, uuid):
14+
"""delete a load balancer protocol."""
15+
16+
mgr = SoftLayer.LoadBalancerManager(env.client)
17+
18+
uuid_lb = mgr.get_lb(identifier)['uuid']
19+
20+
protocol = mgr.delete_protocol(uuid_lb, uuid)
21+
22+
table = formatting.KeyValueTable(['name', 'value'])
23+
table.align['name'] = 'r'
24+
table.align['value'] = 'l'
25+
table.add_row(['Id', protocol.get('id')])
26+
table.add_row(['UUI', protocol.get('uuid')])
27+
table.add_row(['Address', protocol.get('address')])
28+
table.add_row(['Type', SoftLayer.LoadBalancerManager.TYPE.get(protocol.get('type'))])
29+
table.add_row(['Description', protocol.get('description')])
30+
31+
env.fout(table)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""Add a new load balancer protocol."""
2+
import click
3+
4+
import SoftLayer
5+
from SoftLayer.CLI import environment
6+
from SoftLayer.CLI import exceptions
7+
from SoftLayer.CLI import formatting
8+
9+
10+
# pylint: disable=unused-argument
11+
def parse_proto(ctx, param, value):
12+
"""Parses the frontend and backend cli options"""
13+
proto = {'protocol': 'HTTP', 'port': 80}
14+
splitout = value.split(':')
15+
if len(splitout) != 2:
16+
raise exceptions.ArgumentError("{}={} is not properly formatted.".format(param, value))
17+
proto['protocol'] = splitout[0]
18+
proto['port'] = int(splitout[1])
19+
return proto
20+
21+
22+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
23+
@click.argument('identifier')
24+
@click.option('--uuid', help="Load Balancer Uuid.")
25+
@click.option('--frontend', '-f', required=True, default='HTTP:80', show_default=True, callback=parse_proto,
26+
help='PROTOCOL:PORT string for incoming internet connections.')
27+
@click.option('--backend', '-b', required=True, default='HTTP:80', show_default=True, callback=parse_proto,
28+
help='PROTOCOL:PORT string for connecting to backend servers.')
29+
@click.option('--method', '-m', help="Balancing Method.", default='ROUNDROBIN', show_default=True,
30+
type=click.Choice(['ROUNDROBIN', 'LEASTCONNECTION', 'WEIGHTED_RR']))
31+
@click.option('--session', '-s', required=True,
32+
help="Session stickiness type. Valid values are SOURCE_IP or HTTP_COOKIE ")
33+
@click.option('--max', help="Max Connections setting", type=int)
34+
@environment.pass_env
35+
def cli(env, identifier, **args):
36+
"""Edit a load balancer protocol."""
37+
38+
mgr = SoftLayer.LoadBalancerManager(env.client)
39+
40+
uuid = mgr.get_lb_uuid(identifier)
41+
42+
backend = args.get('backend')
43+
frontend = args.get('frontend')
44+
protocol_configurations = [
45+
{
46+
"backendPort": backend.get('port'),
47+
"backendProtocol": backend.get('protocol'),
48+
"frontendPort": frontend.get('port'),
49+
"frontendProtocol": frontend.get('protocol'),
50+
"loadBalancingMethod": args.get('method'),
51+
"sessionType": args.get('session'),
52+
"maxConn": args.get('max')
53+
}
54+
]
55+
protocol_configurations[0]['listenerUuid'] = args.get('uuid')
56+
protocol = mgr.add_protocols(uuid, protocol_configurations)
57+
58+
table = formatting.KeyValueTable(['name', 'value'])
59+
table.align['name'] = 'r'
60+
table.align['value'] = 'l'
61+
table.add_row(['Id', protocol.get('id')])
62+
table.add_row(['UUI', protocol.get('uuid')])
63+
table.add_row(['Address', protocol.get('address')])
64+
table.add_row(['Type', mgr.get_lb_type(protocol.get('type'))])
65+
table.add_row(['Description', protocol.get('description')])
66+
67+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@
244244
('loadbal:order', 'SoftLayer.CLI.loadbal.order:order'),
245245
('loadbal:order-options', 'SoftLayer.CLI.loadbal.order:order_options'),
246246
('loadbal:cancel', 'SoftLayer.CLI.loadbal.order:cancel'),
247+
('loadbal:protocol-add', 'SoftLayer.CLI.loadbal.protocol_add:cli'),
248+
('loadbal:protocol-edit', 'SoftLayer.CLI.loadbal.protocol_edit:cli'),
249+
('loadbal:protocol-delete', 'SoftLayer.CLI.loadbal.protocol_delete:cli'),
247250

248251
('loadbal:ns-detail', 'SoftLayer.CLI.loadbal.ns_detail:cli'),
249252
('loadbal:ns-list', 'SoftLayer.CLI.loadbal.ns_list:cli'),
@@ -426,6 +429,7 @@
426429
('bandwidth:pools-detail', 'SoftLayer.CLI.bandwidth.pools_detail:cli'),
427430
('bandwidth:pools-create', 'SoftLayer.CLI.bandwidth.pools_create:cli'),
428431
('bandwidth:pools-edit', 'SoftLayer.CLI.bandwidth.pools_edit:cli'),
432+
('bandwidth:pools-delete', 'SoftLayer.CLI.bandwidth.pools_delete:cli'),
429433
]
430434

431435
ALL_ALIASES = {

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@
14201420
'amountIn': '6.94517',
14211421
'amountOut': '6.8859'
14221422
},
1423+
"endDate": "2023-07-03T22:59:59-06:00",
14231424
'id': 309961,
14241425
'locationGroup': {
14251426
'description': 'All Datacenters in Mexico',

SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@
158158
}
159159

160160
editObject = True
161+
162+
requestVdrCancellation = True

0 commit comments

Comments
 (0)