1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
"""Add a new load balancer protocol."""
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI.loadbal import protocol_add
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--uuid', help="Load Balancer Uuid.")
@click.option('--frontend', '-f', required=True, default='HTTP:80', show_default=True,
callback=protocol_add.parse_proto,
help='PROTOCOL:PORT string for incoming internet connections.')
@click.option('--backend', '-b', required=True, default='HTTP:80', show_default=True,
callback=protocol_add.parse_proto,
help='PROTOCOL:PORT string for connecting to backend servers.')
@click.option('--method', '-m', help="Balancing Method.", default='ROUNDROBIN', show_default=True,
type=click.Choice(['ROUNDROBIN', 'LEASTCONNECTION', 'WEIGHTED_RR']))
@click.option('--session', '-s', required=True,
help="Session stickiness type. Valid values are SOURCE_IP or HTTP_COOKIE ")
@click.option('--max', help="Max Connections setting", type=int)
@environment.pass_env
def cli(env, identifier, **args):
"""Edit a load balancer protocol."""
mgr = SoftLayer.LoadBalancerManager(env.client)
uuid = mgr.get_lb_uuid(identifier)
backend = args.get('backend')
frontend = args.get('frontend')
protocol_configurations = [
{
"backendPort": backend.get('port'),
"backendProtocol": backend.get('protocol'),
"frontendPort": frontend.get('port'),
"frontendProtocol": frontend.get('protocol'),
"loadBalancingMethod": args.get('method'),
"sessionType": args.get('session'),
"maxConn": args.get('max')
}
]
protocol_configurations[0]['listenerUuid'] = args.get('uuid')
protocol = mgr.add_protocols(uuid, protocol_configurations)
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Id', protocol.get('id')])
table.add_row(['UUI', protocol.get('uuid')])
table.add_row(['Address', protocol.get('address')])
table.add_row(['Type', mgr.get_lb_type(protocol.get('type'))])
table.add_row(['Description', protocol.get('description')])
env.fout(table)
|