Exemplo n.º 1
0
def servicegroup_server_delete(sg_name, s_name, s_port, **connection_args):
    '''
    Remove a server:port member from a servicegroup

    CLI Example:

    .. code-block:: bash

        salt '*' netscaler.servicegroup_server_delete 'serviceGroupName' 'serverName' 'serverPort'
    '''
    # Nitro will throw an error if the server is already not present
    ret = True
    server = _servicegroup_get_server(sg_name, s_name, s_port, **connection_args)
    if server is None:
        return False
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    sgsb = NSServiceGroupServerBinding()
    sgsb.set_servicegroupname(sg_name)
    sgsb.set_servername(s_name)
    sgsb.set_port(s_port)
    try:
       NSServiceGroupServerBinding.delete(nitro, sgsb)
    except NSNitroError, e:
        log.debug('netscaler module error - NSServiceGroupServerBinding() failed: {0}'.format(e.message))
        ret = False
Exemplo n.º 2
0
def servicegroup_server_add(sg_name, s_name, s_port, **connection_args):
    """
    Add a server:port member to a servicegroup

    CLI Example:

    .. code-block:: bash

        salt '*' netscaler.servicegroup_server_add 'serviceGroupName' 'serverName' 'serverPort'
    """
    # Nitro will throw an error if the server is already present
    ret = True
    server = _servicegroup_get_server(sg_name, s_name, s_port, **connection_args)
    if server is not None:
        return False
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    sgsb = NSServiceGroupServerBinding()
    sgsb.set_servicegroupname(sg_name)
    sgsb.set_servername(s_name)
    sgsb.set_port(s_port)
    try:
        NSServiceGroupServerBinding.add(nitro, sgsb)
    except NSNitroError as error:
        log.debug("netscaler module error - NSServiceGroupServerBinding() failed: {0}".format(error))
        ret = False
    _disconnect(nitro)
    return ret
Exemplo n.º 3
0
def action_bindserver(args, nitro):
        svcgrpbinding = NSServiceGroupServerBinding()
        svcgrpbinding.set_servername(args.server)
        svcgrpbinding.set_servicegroupname(args.servicegroup)
        svcgrpbinding.set_port(args.serviceport)
        try:
                NSServiceGroupServerBinding.add(nitro, svcgrpbinding)
                print "bound server %s to service group %s on port %s" % (
                        args.servername, args.servicegroupname, args.serviceport)
        except nsnitro.nsexceptions.nsexceptions.NSNitroNserrExist as e:
                print "Error: ", e.message
                return 2
Exemplo n.º 4
0
def action_unbindserver(args, nitro):
        svcgrpbinding = NSServiceGroupServerBinding()
        svcgrpbinding.set_servername(args.server)
        svcgrpbinding.set_servicegroupname(args.servicegroup)
        svcgrpbinding.set_port(args.serviceport)
        try:
                NSServiceGroupServerBinding.delete(nitro, svcgrpbinding)
                print "unbound server %s from service group %s on port %s" % (
                        args.servername, args.servicegroupname, args.serviceport)
        except nsnitro.nsexceptions.nsexceptions.NSNitroNserrNoent as e:
                print "Error: ", e.message
Exemplo n.º 5
0
def action_bindserver(args, nitro):
        svcgrpbinding = NSServiceGroupServerBinding()
        svcgrpbinding.set_servername(args.server)
        svcgrpbinding.set_servicegroupname(args.servicegroup)
        svcgrpbinding.set_port(args.serviceport)
        try:
                NSServiceGroupServerBinding.add(nitro, svcgrpbinding)
                print "bound server %s to service group %s on port %s" % (
                        args.servername, args.servicegroupname, args.serviceport)
        except nsnitro.nsexceptions.nsexceptions.NSNitroNserrExist as e:
                print "Error: ", e.message
Exemplo n.º 6
0
        if args.dargs:
                print(args)
                sys.exit(0)

        nitro = NSNitro(args.lbip, args.user, args.password, args.ssl)

        try:
                nitro.login()

                if args.bindservertoservicegroup:
                  if not args.servername or not args.servicegroupname or not args.serviceport: 
                    print "--servername, --servicename, and --serviceport are required for binding a server to a service group"
                    nitro.logout()
                    sys.exit(0)
                  else:
                    svcgrpbinding=NSServiceGroupServerBinding()
                    svcgrpbinding.set_servername(args.servername)
                    svcgrpbinding.set_servicegroupname(args.servicegroupname)
                    svcgrpbinding.set_port(args.serviceport)
                    try:
                      NSServiceGroupServerBinding.add(nitro, svcgrpbinding)
                      print "bound server %s to service group %s on port %s" % (args.servername, args.servicegroupname, args.serviceport)
                    except nsnitro.nsexceptions.nsexceptions.NSNitroNserrExist as e:
                      print "Error: ", e.message
                    finally:
                      nitro.logout()
                      sys.exit(0)
                    
                if args.unbindserverfromservicegroup:
                  if not args.servername or not args.servicegroupname or not args.serviceport: 
                    print "--servername, --servicename, and --serviceport are required for binding a server to a service group"