Check if a server:port combination is a member of a servicegroup

    CLI Example:

    .. code-block:: bash

        salt '*' netscaler.servicegroup_server_exists 'serviceGroupName' 'serverName' 'serverPort'
8401
def servicegroup_server_exists(sg_name, s_name, s_port=None, **connection_args):
    '''
    
    '''
    return _servicegroup_get_server(sg_name, s_name, s_port, **connection_args) is not None
790432
def exists(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    retries = 30
    while True:
        try:
            _conn = conn.get_all_groups(names=[name])
            if _conn:
                return True
            else:
                msg = 'The autoscale group does not exist in region {0}'.format(region)
                log.debug(msg)
                return False
        except boto.exception.BotoServerError as e:
            if retries and e.code == 'Throttling':
                log.debug('Throttled by AWS API, retrying in 5 seconds...')
                time.sleep(5)
                retries -= 1
                continue
            log.error(e)
            return False
650949
protected function checkAndSetServerOptions()
    {

        // Specific query port defined
        if (array_key_exists(self::SERVER_OPTIONS_QUERY_PORT, $this->options)) {
            $this->port_query = (int)$this->options[self::SERVER_OPTIONS_QUERY_PORT];
        } else {
            // Do math based on the protocol class
            $this->port_query = $this->protocol->findQueryPort($this->port_client);
        }
    }
1240260
def _get_dvs_uplink_portgroup(dvs, portgroup_name):
    '''
    
    '''
    for portgroup in dvs.portgroup:
        if portgroup.name == portgroup_name:
            return portgroup

    return None
391848
def port_available?(port)
      case @process.network_protocol
      when 'tcp'
        server = TCPServer.new('127.0.0.1', port)
        server.close
        true
      when 'udp'
        server = UDPSocket.new
        server.bind('127.0.0.1', port)
        server.close
        true
      else
        raise Procodile::Error, "Invalid network_protocol '#{@process.network_protocol}'"
      end
    rescue Errno::EADDRINUSE => e
      false
    end
392061
def vserver_servicegroup_add(v_name, sg_name, **connection_args):
    '''
    
    '''
    ret = True
    if vserver_servicegroup_exists(v_name, sg_name, **connection_args):
        return False
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    vsg = NSLBVServerServiceGroupBinding()
    vsg.set_name(v_name)
    vsg.set_servicegroupname(sg_name)
    try:
        NSLBVServerServiceGroupBinding.add(nitro, vsg)
    except NSNitroError as error:
        log.debug('netscaler module error - NSLBVServerServiceGroupBinding.add() failed: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
346799
public static boolean isServiceExported(Configuration configuration, int port, String serviceName) {
        if (serviceName == null)
            return false;
        try {
            final Registry registry = RegistryFinder.getInstance().getRegistry(configuration, port);
            String[] list = registry.list();

            if (list != null) {
                for (int i = 0; i < list.length; i++) {
                    if (serviceName.equals(list[i]))
                        return true;
                }
            }
        } catch (RemoteException ex) {
            return false;
        } catch (Exception e) {
            return false;
        }
        return false;
    }
436076
def servicegroup_server_enable(sg_name, s_name, s_port, **connection_args):
    '''
    
    '''
    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
    try:
        NSServiceGroup.enable_server(nitro, server)
    except NSNitroError as error:
        log.debug('netscaler module error - NSServiceGroup.enable_server() failed: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
619562
def status(name, sig=None):
    '''
    
    '''
    if sig:
        # usual way to do by others (debian_service, netbsdservice).
        # XXX probably does not work here (check 'runsv sshd' instead of 'sshd' ?)
        return bool(__salt__['status.pid'](sig))

    svc_path = _service_path(name)
    if not os.path.exists(svc_path):
        # service does not exist
        return False

    # sv return code is not relevant to get a service status.
    # Check its output instead.
    cmd = 'sv status {0}'.format(svc_path)
    try:
        out = __salt__['cmd.run_stdout'](cmd)
        return out.startswith('run: ')
    except Exception:
        # sv (as a command) returned an error
        return False
1060032
def _check_security_groups(self, names):
        
        self._init_os_api()
        log.debug("Checking existence of security group(s) %s ...", names)
        try:
            # python-novaclient < 8.0.0
            security_groups = self.nova_client.security_groups.list()
            existing = set(sg.name for sg in security_groups)
        except AttributeError:
            security_groups = self.neutron_client.list_security_groups()['security_groups']
            existing = set(sg[u'name'] for sg in security_groups)

        # TODO: We should be able to create the security group if it
        # doesn't exist and at least add a rule to accept ssh access.
        # Also, we should be able to add new rules to a security group
        # if needed.
        nonexisting = set(names) - existing
        if nonexisting:
            raise SecurityGroupError(
                "Security group(s) `{0}` do not exist"
                .format(', '.join(nonexisting)))

        # if we get to this point, all sec groups exist
        return True
672701
def target_group_exists(name,
                        region=None,
                        key=None,
                        keyid=None,
                        profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        if name.startswith('arn:aws:elasticloadbalancing'):
            alb = conn.describe_target_groups(TargetGroupArns=[name])
        else:
            alb = conn.describe_target_groups(Names=[name])
        if alb:
            return True
        else:
            log.warning('The target group does not exist in region %s', region)
            return False
    except ClientError as error:
        log.warning('target_group_exists check for %s returned: %s', name, error)
        return False
797114
def has_group(user, group_name):
    '''
    
    '''
    if user.groups.filter(name=group_name).exists():
        return True
    return False
830889
def has_known_servers(self):
        """"""
        return any(s for s in self._server_descriptions.values()
                   if s.is_server_type_known)
853636
def exists(key, host=None, port=None, db=None, password=None):
    '''
    
    '''
    server = _connect(host, port, db, password)
    return server.exists(key)
1257032
def vserver_exists(v_name, v_ip=None, v_port=None, v_type=None, **connection_args):
    '''
    
    '''
    vserver = _vserver_get(v_name, **connection_args)
    if vserver is None:
        return False
    if v_ip is not None and vserver.get_ipv46() != v_ip:
        return False
    if v_port is not None and vserver.get_port() != v_port:
        return False
    if v_type is not None and vserver.get_servicetype().upper() != v_type.upper():
        return False
    return True
1096212
function(server, cb) {
    var port = _getServerConfig(server).port || 3223;
    var result = {running: false, port: port, listening: false};
    var host = 'localhost';

    var pidFile = path.join(nscaleRoot, 'data', '.' + server);

    portscanner.checkPortStatus(port, host, function(err, status) {
      if (err) { return cb(err); }
      result.listening = (status === 'open') ? true : false;

      if (fs.existsSync(pidFile)) {
        var pid = Number(fs.readFileSync(pidFile));
        result.pid = pid;

        running(pid, function(err, running) {
          if (err) { cb(err); }
          result.running = running;
          cb(null, result);
        });
      }
      else { 
        cb(null, result); 
      }
    });
  }
623462
def _check_servers(self):
        """"""
        new_servers = []

        def check_format(server):
            if server.scheme not in ["thrift", "http", "https"]:
                raise RuntimeError("Unable to recognize protocol: \"%s\"" % _type)

            if server.scheme == "thrift":
                if not thrift_connect:
                    raise RuntimeError("If you want to use thrift, please install thrift. \"pip install thrift\"")
                if server.port is None:
                    raise RuntimeError("If you want to use thrift, please provide a port number")

            new_servers.append(server)

        for server in self.servers:
            if isinstance(server, (tuple, list)):
                if len(list(server)) != 3:
                    raise RuntimeError("Invalid server definition: \"%s\"" % repr(server))
                _type, host, port = server
                server = urlparse('%s://%s:%s' % (_type, host, port))
                check_format(server)
            elif isinstance(server, six.string_types):
                if server.startswith(("thrift:", "http:", "https:")):
                    server = urlparse(server)
                    check_format(server)
                    continue
                else:
                    tokens = [t for t in server.split(":") if t.strip()]
                    if len(tokens) == 2:
                        host = tokens[0]
                        try:
                            port = int(tokens[1])
                        except ValueError:
                            raise RuntimeError("Invalid port: \"%s\"" % tokens[1])

                        if 9200 <= port <= 9299:
                            _type = "http"
                        elif 9500 <= port <= 9599:
                            _type = "thrift"
                        else:
                            raise RuntimeError("Unable to recognize port-type: \"%s\"" % port)

                        server = urlparse('%s://%s:%s' % (_type, host, port))
                        check_format(server)

        self.servers = new_servers