Ejemplo n.º 1
0
def order(env, **args):
    """Creates a LB. Protocols supported are TCP, HTTP, and HTTPS."""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    network = SoftLayer.NetworkManager(env.client)

    datacenter = network.get_datacenter(datacenter=args.get('datacenter'))
    if datacenter:
        location = {'id': datacenter[0]['id']}
    else:
        raise exceptions.CLIHalt('Datacenter {} was not found'.format(datacenter))

    name = args.get('name')
    description = args.get('label', None)

    backend = args.get('backend')
    frontend = args.get('frontend')
    protocols = [
        {
            "backendPort": backend.get('port'),
            "backendProtocol": backend.get('protocol'),
            "frontendPort": frontend.get('port'),
            "frontendProtocol": frontend.get('protocol'),
            "loadBalancingMethod": args.get('method'),
            "maxConn": 1000
        }
    ]

    # remove verify=True to place the order
    receipt = mgr.order_lbaas(location, name, description, protocols, args.get('subnet'),
                              public=args.get('public'), verify=args.get('verify'))
    table = parse_receipt(receipt)
    env.fout(table)
Ejemplo n.º 2
0
def cli(env):
    """List active load balancers."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    load_balancers = mgr.get_local_lbs()

    table = formatting.Table([
        'ID', 'VIP Address', 'Location', 'SSL Offload', 'Connections/second',
        'Type'
    ])

    table.align['Connections/second'] = 'r'

    for load_balancer in load_balancers:
        ssl_support = 'Not Supported'
        if load_balancer['sslEnabledFlag']:
            if load_balancer['sslActiveFlag']:
                ssl_support = 'On'
            else:
                ssl_support = 'Off'
        lb_type = 'Standard'
        if load_balancer['dedicatedFlag']:
            lb_type = 'Dedicated'
        elif load_balancer['highAvailabilityFlag']:
            lb_type = 'HA'
        table.add_row([
            'local:%s' % load_balancer['id'],
            load_balancer['ipAddress']['ipAddress'],
            load_balancer['loadBalancerHardware'][0]['datacenter']['name'],
            ssl_support, load_balancer['connectionLimit'], lb_type
        ])

    env.fout(table)
Ejemplo n.º 3
0
def cli(env, identifier):
    """Get Netscaler details."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    this_lb = mgr.get_adc(identifier)
    table = netscaler_table(this_lb)
    env.fout(table)
Ejemplo n.º 4
0
def cli(env, identifier, enabled, port, weight, healthcheck_type, ip_address):
    """Edit the properties of a service group."""

    mgr = SoftLayer.LoadBalancerManager(env.client)

    loadbal_id, service_id = loadbal.parse_id(identifier)

    # check if any input is provided
    if not any([ip_address, enabled, weight, port, healthcheck_type]):
        raise exceptions.CLIAbort(
            'At least one property is required to be changed!')

    # check if the IP is valid
    ip_address_id = None
    if ip_address:
        ip_service = env.client['Network_Subnet_IpAddress']
        ip_record = ip_service.getByIpAddress(ip_address)
        ip_address_id = ip_record['id']

    mgr.edit_service(loadbal_id,
                     service_id,
                     ip_address_id=ip_address_id,
                     enabled=enabled,
                     port=port,
                     weight=weight,
                     hc_type=healthcheck_type)
    env.fout('Load balancer service %s is being modified!' % identifier)
Ejemplo n.º 5
0
def add(env, identifier, **args):
    """Adds a listener to the identifier LB"""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)

    new_listener = {
        'backendPort':
        args.get('backport'),
        'backendProtocol':
        args.get('backprotocol')
        if args.get('backprotocol') else args.get('frontprotocol'),
        'frontendPort':
        args.get('frontport'),
        'frontendProtocol':
        args.get('frontprotocol'),
        'loadBalancingMethod':
        args.get('method'),
        'maxConn':
        args.get('connections', None),
        'sessionType':
        args.get('sticky'),
        'tlsCertificateId':
        args.get('sslcert')
    }

    try:
        mgr.add_lb_listener(uuid, new_listener)
        click.secho("Success", fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 6
0
def l7pool_add(env, identifier, **args):
    """Adds a new l7 pool

    -S is in colon deliminated format to make grouping IP:port:weight a bit easier.
    """

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)

    pool_main = {
        'name': args.get('name'),
        'loadBalancingAlgorithm': args.get('method'),
        'protocol': args.get('protocol')
    }

    pool_members = list(args.get('server'))

    pool_health = {
        'interval': args.get('healthinterval'),
        'timeout': args.get('healthtimeout'),
        'maxRetries': args.get('healthretry'),
        'urlPath': args.get('healthpath')
    }

    pool_sticky = {'type': args.get('sticky')}

    try:
        mgr.add_lb_l7_pool(uuid, pool_main, pool_members, pool_health,
                           pool_sticky)
        click.secho("Success", fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 7
0
def add(env, identifier, private, member, weight):
    """Add a new LBaaS members."""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)
    # Get a server ID to add
    to_add = {"weight": weight}
    if private:
        to_add['privateIpAddress'] = member
    else:
        to_add['publicIpAddress'] = member

    try:
        mgr.add_lb_member(uuid, to_add)
        click.secho("Member {} added".format(member), fg='green')
    except SoftLayerAPIError as exception:
        if 'publicIpAddress must be a string' in exception.faultString:
            click.secho(
                "This LB requires a Public IP address for its members and none was supplied",
                fg='red')
        elif 'privateIpAddress must be a string' in exception.faultString:
            click.secho(
                "This LB requires a Private IP address for its members and none was supplied",
                fg='red')
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 8
0
def edit(env, identifier, listener, **args):
    """Updates a listener's configuration.

    LISTENER should be a UUID, and can be found from `slcli lb detail <IDENTIFIER>`
    """

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)

    new_listener = {'listenerUuid': listener}

    arg_to_option = {
        'frontprotocol': 'frontendProtocol',
        'backprotocol': 'backendProtocol',
        'frontport': 'frontendPort',
        'backport': 'backendPort',
        'method': 'loadBalancingMethod',
        'connections': 'maxConn',
        'sticky': 'sessionType',
        'sslcert': 'tlsCertificateId'
    }

    for arg in args:
        if args[arg]:
            new_listener[arg_to_option[arg]] = args[arg]

    try:
        mgr.add_lb_listener(uuid, new_listener)
        click.secho("Success", fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 9
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)
        input_id = args.get('<identifier>')

        key_value = get_ids(input_id)
        loadbal_id = int(key_value[0])
        service_id = int(key_value[1])

        # check if any input is provided
        if not (args['--ip'] or args['--enabled'] or args['--weight']
                or args['--port'] or args['--hc_type']):
            return 'At least one property is required to be changed!'

        # check if the IP is valid
        ip_address_id = None
        if args['--ip']:
            ip_address = mgr.get_ip_address(args['--ip'])
            if not ip_address:
                return 'Provided IP address is not valid!'
            else:
                ip_address_id = ip_address['id']

        mgr.edit_service(loadbal_id,
                         service_id,
                         ip_address_id=ip_address_id,
                         enabled=args.get('--enabled'),
                         port=args.get('--port'),
                         weight=args.get('--weight'),
                         hc_type=args.get('--hc_type'))
        return 'Load balancer service %s is being modified!' % input_id
Ejemplo n.º 10
0
def order(env, **args):
    """Creates a LB. Protocols supported are TCP, HTTP, and HTTPS."""

    mgr = SoftLayer.LoadBalancerManager(env.client)

    location = args.get('datacenter')
    name = args.get('name')
    description = args.get('label', None)

    backend = args.get('backend')
    frontend = args.get('frontend')
    protocols = [{
        "backendPort": backend.get('port'),
        "backendProtocol": backend.get('protocol'),
        "frontendPort": frontend.get('port'),
        "frontendProtocol": frontend.get('protocol'),
        "loadBalancingMethod": args.get('method'),
        "maxConn": 1000
    }]

    # remove verify=True to place the order
    receipt = mgr.order_lbaas(location,
                              name,
                              description,
                              protocols,
                              args.get('subnet'),
                              public=args.get('public'),
                              verify=args.get('verify'))
    table = parse_receipt(receipt)
    env.fout(table)
Ejemplo n.º 11
0
def delete_loadbalancers(resources, client):
    if 'loadbalancers' not in resources:
        return

    lbmgr = SoftLayer.LoadBalancerManager(client)
    for lb, lbinfo in resources['loadbalancers'].iteritems():
        print("deleting loadbalancer {}: {}".format(
            lb, lbmgr.cancel_lb(lbinfo['id'])))
Ejemplo n.º 12
0
def cli(env, identifier):
    """Reset connections on a certain service group."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    loadbal_id, group_id = loadbal.parse_id(identifier)

    mgr.reset_service_group(loadbal_id, group_id)
    return 'Load balancer service group connections are being reset!'
Ejemplo n.º 13
0
def cli(env, billing_id, datacenter):
    """Adds a load balancer given the id returned from create-options."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    if not formatting.confirm("This action will incur charges on your "
                              "account. Continue?"):
        raise exceptions.CLIAbort('Aborted.')
    mgr.add_local_lb(billing_id, datacenter=datacenter)
    env.fout("Load balancer is being created!")
Ejemplo n.º 14
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)
        input_id = args.get('<identifier>')

        key_value = get_ids(input_id)
        loadbal_id = int(key_value[0])
        group_id = int(key_value[1])

        mgr.reset_service_group(loadbal_id, group_id)
        return 'Load balancer service group connections are being reset!'
Ejemplo n.º 15
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)

        input_id = args.get('<identifier>')

        key_value = get_ids(input_id)
        loadbal_id = int(key_value[1])

        load_balancer = mgr.get_local_lb(loadbal_id)
        return get_local_lb_table(load_balancer)
Ejemplo n.º 16
0
def cli(env, identifier):
    """Get Load Balancer as a Service details."""
    mgr = SoftLayer.LoadBalancerManager(env.client)
    _, lbid = mgr.get_lbaas_uuid_id(identifier)
    this_lb = mgr.get_lb(lbid)
    if this_lb.get('previousErrorText'):
        print(this_lb.get('previousErrorText'))
    table = lbaas_table(this_lb)

    env.fout(table)
Ejemplo n.º 17
0
def cli(env):
    """List active Netscaler devices."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    netscalers = mgr.get_adcs()
    if netscalers:
        adc_table = generate_netscaler_table(netscalers)
        env.fout(adc_table)
    else:
        env.fout("No Netscalers")
Ejemplo n.º 18
0
 def execute(self, args):
     mgr = SoftLayer.LoadBalancerManager(self.client)
     input_id = helpers.resolve_id(mgr.resolve_ids,
                                   args.get('<identifier>'),
                                   'load_balancer')
     if not formatting.confirm("This action will incur charges on your "
                               "account. Continue?"):
         raise exceptions.CLIAbort('Aborted.')
     mgr.add_local_lb(input_id, datacenter=args['--datacenter'])
     return "Load balancer is being created!"
Ejemplo n.º 19
0
def l7pool_del(env, identifier):
    """Deletes the identified pool

    Identifier is L7Pool Id. NOT the UUID
    """
    mgr = SoftLayer.LoadBalancerManager(env.client)
    try:
        mgr.del_lb_l7_pool(identifier)
        click.secho("Success", fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 20
0
def policies(env, protocol_id):
    """List policies of the front-end protocol (listener)."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    if protocol_id:
        l7policies = mgr.get_l7policies(protocol_id)
        table = generate_l7policies_table(l7policies, protocol_id)
    else:
        l7policies = mgr.get_all_l7policies()
        table = l7policies_table(l7policies)
    env.fout(table)
Ejemplo n.º 21
0
def cli(env):
    """List active Load Balancer as a Service devices."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    lbaas = mgr.get_lbaas()
    if lbaas:
        lbaas_table = generate_lbaas_table(lbaas)
        env.fout(lbaas_table)

    else:
        env.fout("No LBaaS devices found")
Ejemplo n.º 22
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)

        routing_types = mgr.get_routing_types()
        table = formatting.KeyValueTable(['ID', 'Name'])
        table.align['ID'] = 'l'
        table.align['Name'] = 'l'
        table.sortby = 'ID'
        for routing_type in routing_types:
            table.add_row([routing_type['id'], routing_type['name']])
        return table
Ejemplo n.º 23
0
def cancel(env, identifier):
    """Cancels a LBaaS instance"""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)

    try:
        mgr.cancel_lbaas(uuid)
        click.secho("LB {} canceled succesfully.".format(identifier), fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
Ejemplo n.º 24
0
def cli(env):
    """List routing types."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    routing_methods = mgr.get_routing_methods()
    table = formatting.KeyValueTable(['ID', 'Name'])
    table.align['ID'] = 'l'
    table.align['Name'] = 'l'
    table.sortby = 'ID'
    for routing_method in routing_methods:
        table.add_row([routing_method['id'], routing_method['name']])
    env.fout(table)
Ejemplo n.º 25
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)
        input_id = args.get('<identifier>')

        key_value = get_ids(input_id)
        group_id = int(key_value[1])

        if args['--really'] or formatting.confirm("This action will cancel a "
                                                  "service group. Continue?"):
            mgr.delete_service_group(group_id)
            return 'Service group %s is being deleted!' % input_id
        else:
            raise exceptions.CLIAbort('Aborted.')
Ejemplo n.º 26
0
    def execute(self, args):
        mgr = SoftLayer.LoadBalancerManager(self.client)
        input_id = args.get('<identifier>')

        key_value = get_ids(input_id)
        loadbal_id = int(key_value[1])

        if args['--really'] or formatting.confirm("This action will cancel a "
                                                  "load balancer. Continue?"):
            mgr.cancel_lb(loadbal_id)
            return 'Load Balancer with id %s is being cancelled!' % input_id
        else:
            raise exceptions.CLIAbort('Aborted.')
Ejemplo n.º 27
0
def cli(env, identifier):
    """Deletes an existing load balancer service."""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    _, service_id = loadbal.parse_id(identifier)

    if not (env.skip_confirmations or formatting.confirm(
            "This action will cancel a service from your "
            "load balancer. Continue?")):
        raise exceptions.CLIAbort('Aborted.')

    mgr.delete_service(service_id)
    return 'Load balancer service %s is being cancelled!' % service_id
Ejemplo n.º 28
0
def delete(env, identifier, listener):
    """Removes the listener from identified LBaaS instance

    LISTENER should be a UUID, and can be found from `slcli lb detail <IDENTIFIER>`
    """

    mgr = SoftLayer.LoadBalancerManager(env.client)
    uuid, _ = mgr.get_lbaas_uuid_id(identifier)
    try:
        mgr.remove_lb_listener(uuid, listener)
        click.secho("Success", fg='green')
    except SoftLayerAPIError as exception:
        click.secho("ERROR: {}".format(exception.faultString), fg='red')
def cli(env, identifier):
    """Toggle the status of an existing load balancer service."""

    mgr = SoftLayer.LoadBalancerManager(env.client)
    _, service_id = loadbal.parse_id(identifier)

    if not (env.skip_confirmations
            or formatting.confirm("This action will toggle the status on the "
                                  "service. Continue?")):
        raise exceptions.CLIAbort('Aborted.')

    mgr.toggle_service_status(service_id)
    return 'Load balancer service %s status updated!' % identifier
Ejemplo n.º 30
0
def cli(env, identifier):
    """Deletes an existing load balancer service group."""
    mgr = SoftLayer.LoadBalancerManager(env.client)

    _, group_id = loadbal.parse_id(identifier)

    if not (env.skip_confirmations
            or formatting.confirm("This action will cancel a service group. "
                                  "Continue?")):
        raise exceptions.CLIAbort('Aborted.')

    mgr.delete_service_group(group_id)
    env.fout('Service group %s is being deleted!' % identifier)