Enable a server:port member of a servicegroup

    CLI Example:

    .. code-block:: bash

        salt '*' netscaler.servicegroup_server_enable 'serviceGroupName' 'serverName' 'serverPort'
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
218095
private ServerAddress createServerAddress(String group) {
		final Setting setting = checkSetting();

		if (group == null) {
			group = StrUtil.EMPTY;
		}

		final String tmpHost = setting.getByGroup("host", group);
		if (StrUtil.isBlank(tmpHost)) {
			throw new NotInitedException("Host name is empy of group: {}", group);
		}

		final int defaultPort = setting.getInt("port", group, 27017);
		return new ServerAddress(NetUtil.buildInetSocketAddress(tmpHost, defaultPort));
	}
342435
def portgroups_configured(name, dvs, portgroups):
    '''
    
    '''
    datacenter = _get_datacenter_name()
    log.info('Running state %s on DVS \'%s\', datacenter \'%s\'',
             name, dvs, datacenter)
    changes_required = False
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': None}
    comments = []
    changes = {}
    changes_required = False

    try:
        #TODO portroups validation
        si = __salt__['vsphere.get_service_instance_via_proxy']()
        current_pgs = __salt__['vsphere.list_dvportgroups'](
            dvs=dvs, service_instance=si)
        expected_pg_names = []
        for pg in portgroups:
            pg_name = pg['name']
            expected_pg_names.append(pg_name)
            del pg['name']
            log.info('Checking pg \'%s\'', pg_name)
            filtered_current_pgs = \
                    [p for p in current_pgs if p.get('name') == pg_name]
            if not filtered_current_pgs:
                changes_required = True
                if __opts__['test']:
                    comments.append('State {0} will create a new portgroup '
                                    '\'{1}\' in DVS \'{2}\', datacenter '
                                    '\'{3}\''.format(name, pg_name, dvs,
                                                     datacenter))
                else:
                    __salt__['vsphere.create_dvportgroup'](
                        portgroup_dict=pg, portgroup_name=pg_name, dvs=dvs,
                        service_instance=si)
                    comments.append('Created a new portgroup \'{0}\' in DVS '
                                    '\'{1}\', datacenter \'{2}\''
                                    ''.format(pg_name, dvs, datacenter))
                log.info(comments[-1])
                changes.update({pg_name: {'new': pg}})
            else:
                # Porgroup already exists. Checking the config
                log.trace('Portgroup \'%s\' found in DVS \'%s\', datacenter '
                          '\'%s\'. Checking for any updates.',
                          pg_name, dvs, datacenter)
                current_pg = filtered_current_pgs[0]
                diff_dict = _get_diff_dict(current_pg, pg)

                if diff_dict:
                    changes_required = True
                    if __opts__['test']:
                        changes_strings = \
                                _get_changes_from_diff_dict(diff_dict)
                        log.trace('changes_strings = %s', changes_strings)
                        comments.append(
                            'State {0} will update portgroup \'{1}\' in '
                            'DVS \'{2}\', datacenter \'{3}\':\n{4}'
                            ''.format(name, pg_name, dvs, datacenter,
                                      '\n'.join(['\t{0}'.format(c) for c in
                                                 changes_strings])))
                    else:
                        __salt__['vsphere.update_dvportgroup'](
                            portgroup_dict=pg, portgroup=pg_name, dvs=dvs,
                            service_instance=si)
                        comments.append('Updated portgroup \'{0}\' in DVS '
                                        '\'{1}\', datacenter \'{2}\''
                                        ''.format(pg_name, dvs, datacenter))
                    log.info(comments[-1])
                    changes.update(
                        {pg_name: {'new':
                                   _get_val2_dict_from_diff_dict(diff_dict),
                                   'old':
                                   _get_val1_dict_from_diff_dict(diff_dict)}})
        # Add the uplink portgroup to the expected pg names
        uplink_pg = __salt__['vsphere.list_uplink_dvportgroup'](
            dvs=dvs, service_instance=si)
        expected_pg_names.append(uplink_pg['name'])
        # Remove any extra portgroups
        for current_pg in current_pgs:
            if current_pg['name'] not in expected_pg_names:
                changes_required = True
                if __opts__['test']:
                    comments.append('State {0} will remove '
                                    'the portgroup \'{1}\' from DVS \'{2}\', '
                                    'datacenter \'{3}\''
                                    ''.format(name, current_pg['name'], dvs,
                                              datacenter))
                else:
                    __salt__['vsphere.remove_dvportgroup'](
                        portgroup=current_pg['name'], dvs=dvs,
                        service_instance=si)
                    comments.append('Removed the portgroup \'{0}\' from DVS '
                                    '\'{1}\', datacenter \'{2}\''
                                    ''.format(current_pg['name'], dvs,
                                              datacenter))
                log.info(comments[-1])
                changes.update({current_pg['name']:
                                {'old': current_pg}})
        __salt__['vsphere.disconnect'](si)
    except salt.exceptions.CommandExecutionError as exc:
        log.exception('Encountered error')
        if si:
            __salt__['vsphere.disconnect'](si)
        if not __opts__['test']:
            ret['result'] = False
        ret.update({'comment': exc.strerror,
                    'result': False if not __opts__['test'] else None})
        return ret
    if not changes_required:
        # We have no changes
        ret.update({'comment': ('All portgroups in DVS \'{0}\', datacenter '
                                '\'{1}\' exist and are correctly configured. '
                                'Nothing to be done.'.format(dvs, datacenter)),
                    'result': True})
    else:
        ret.update({
            'comment': '\n'.join(comments),
            'changes': changes,
            'result': None if __opts__['test'] else True,
        })
    return ret
604063
def local_bind_ports(self):
        
        self._check_is_started()
        return [_server.local_port for _server in self._server_list if
                _server.local_port is not None]
1271676
def filter_service_by_hostgroup_name(group):
    

    def inner_filter(items):
        """Inner filter for service. Accept if hostgroup in service.host.hostgroups"""
        service = items["service"]
        host = items["hosts"][service.host]
        if service is None or host is None:
            return False
        return group in [items["hostgroups"][g].hostgroup_name for g in host.hostgroups]

    return inner_filter
960088
def enable(resource_group_name, workflow_name, custom_headers:nil)
      response = enable_async(resource_group_name, workflow_name, custom_headers:custom_headers).value!
      nil
    end
1338086
def service_disable(s_name, s_delay=None, **connection_args):
    '''
    
    '''
    ret = True
    service = _service_get(s_name, **connection_args)
    if service is None:
        return False
    if s_delay is not None:
        service.set_delay(s_delay)
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    try:
        NSService.disable(nitro, service)
    except NSNitroError as error:
        log.debug('netscaler module error - NSService.enable() failed: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
480826
def SetServerInformation(self, server, port):
    
    self._host = server
    self._port = port
359029
def server_add(s_name, s_ip, s_state=None, **connection_args):
    '''
    
    '''
    ret = True
    if server_exists(s_name, **connection_args):
        return False
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    server = NSServer()
    server.set_name(s_name)
    server.set_ipaddress(s_ip)
    if s_state is not None:
        server.set_state(s_state)
    try:
        NSServer.add(nitro, server)
    except NSNitroError as error:
        log.debug('netscaler module error - NSServer.add() failed: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
689887
def start(self, tcpport=102):
        
        if tcpport != 102:
            logger.info("setting server TCP port to %s" % tcpport)
            self.set_param(snap7.snap7types.LocalPort, tcpport)
        logger.info("starting server on 0.0.0.0:%s" % tcpport)
        return self.library.Srv_Start(self.pointer)
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
762309
public boolean isSupportedByServer()
            throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
        return ServiceDiscoveryManager.getInstanceFor(connection()).serverSupportsFeature(NAMESPACE);
    }
1275454
def enable_plugin(name, runas=None):
    '''
    
    '''
    if runas is None and not salt.utils.platform.is_windows():
        runas = salt.utils.user.get_user()
    cmd = [_get_rabbitmq_plugin(), 'enable', name]
    ret = __salt__['cmd.run_all'](cmd, reset_system_locale=False, runas=runas, python_shell=False)
    return _format_response(ret, 'Enabled')
671275
def servicegroup_server_add(sg_name, s_name, s_port, **connection_args):
    '''
    
    '''
    # 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: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
871659
def port_mapping(port)
      case port.to_s
      when /\A(\d+)(?:\/([a-z]+))?\z/
        port = $1.to_i
        {
          "hostPort" => port,
          "containerPort" => port,
          "protocol" => $2 || "tcp"
        }
      when /\A(\d+):(\d+)(?:\/([a-z]+))?\z/
        {
          "hostPort" => $1.to_i,
          "containerPort" => $2.to_i,
          "protocol" => $3 || "tcp"
        }
      else
        raise "Cannot parse port specification: #{port}"
      end
    end
813199
def get_server_group(self):
        
        api_url = "{0}/applications/{1}".format(API_URL, self.app)
        response = requests.get(api_url, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT)
        for server_group in response.json()['clusters'][self.env]:
            return server_group['serverGroups'][-1]
819027
def server(**kwargs):
    
    start_server(**{k: v for k, v in kwargs.items() if v},
                 blocking=True)