def get_gateways(kls, eipconfig, providerconfig): """ Return the selected gateways for a given provider, looking at the EIP config file. :param eipconfig: eip configuration object :type eipconfig: EIPConfig :param providerconfig: provider specific configuration :type providerconfig: ProviderConfig :rtype: list """ gateways = [] settings = Settings() domain = providerconfig.get_domain() gateway_conf = settings.get_selected_gateway(domain) gateway_selector = VPNGatewaySelector(eipconfig) if gateway_conf == GATEWAY_AUTOMATIC: gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] if not gateways: logger.error('No gateway was found!') raise VPNLauncherException('No gateway was found!') logger.debug("Using gateways ips: {0}".format(', '.join(gateways))) return gateways
def get_gateways(kls, eipconfig, providerconfig): """ Return the selected gateways for a given provider, looking at the EIP config file. :param eipconfig: eip configuration object :type eipconfig: EIPConfig :param providerconfig: provider specific configuration :type providerconfig: ProviderConfig :rtype: list """ gateways = [] settings = Settings() domain = providerconfig.get_domain() gateway_conf = settings.get_selected_gateway(domain) gateway_selector = VPNGatewaySelector(eipconfig) if gateway_conf == GATEWAY_AUTOMATIC: gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] if not gateways: logger.error('No gateway was found!') raise VPNLauncherException('No gateway was found!') logger.debug("Using gateways ips: {0}".format(', '.join(gateways))) return gateways
def get_gateways(kls, eipconfig, providerconfig): """ Return a list with the selected gateways for a given provider, looking at the EIP config file. Each item of the list is a tuple containing (gateway, port). :param eipconfig: eip configuration object :type eipconfig: EIPConfig :param providerconfig: provider specific configuration :type providerconfig: ProviderConfig :rtype: list """ gateways = [] settings = Settings() domain = providerconfig.get_domain() gateway_conf = settings.get_selected_gateway(domain) gateway_selector = VPNGatewaySelector(eipconfig) if gateway_conf == GATEWAY_AUTOMATIC: gws = gateway_selector.get_gateways() else: gws = [gateway_conf] if not gws: logger.error('No gateway was found!') raise VPNLauncherException('No gateway was found!') for idx, gw in enumerate(gws): ports = eipconfig.get_gateway_ports(idx) the_port = "1194" # default port # pick the port preferring this order: for port in kls.PREFERRED_PORTS: if port in ports: the_port = port break else: continue gateways.append((gw, the_port)) logger.debug("Using gateways (ip, port): {0!r}".format(gateways)) return gateways
def get_gateways(kls, eipconfig, providerconfig): """ Return a list with the selected gateways for a given provider, looking at the EIP config file. Each item of the list is a tuple containing (gateway, port). :param eipconfig: eip configuration object :type eipconfig: EIPConfig :param providerconfig: provider specific configuration :type providerconfig: ProviderConfig :rtype: list """ gateways = [] settings = Settings() domain = providerconfig.get_domain() gateway_conf = settings.get_selected_gateway(domain) gateway_selector = VPNGatewaySelector(eipconfig) if gateway_conf == GATEWAY_AUTOMATIC: gws = gateway_selector.get_gateways() else: gws = [gateway_conf] if not gws: logger.error('No gateway was found!') raise VPNLauncherException('No gateway was found!') for idx, gw in enumerate(gws): ports = eipconfig.get_gateway_ports(idx) the_port = "1194" # default port # pick the port preferring this order: for port in kls.PREFERRED_PORTS: if port in ports: the_port = port break else: continue gateways.append((gw, the_port)) logger.debug("Using gateways (ip, port): {0!r}".format(gateways)) return gateways
def get_gateway_country_code(self, domain): """ Signal the country code for the currently used gateway for the given provider. :param domain: the domain to get country code. :type domain: str Signals: eip_get_gateway_country_code -> str eip_no_gateway """ settings = Settings() eip_config = eipconfig.EIPConfig() provider_config = ProviderConfig.get_provider_config(domain) api_version = provider_config.get_api_version() eip_config.set_api_version(api_version) eip_config.load(eipconfig.get_eipconfig_path(domain)) gateway_selector = eipconfig.VPNGatewaySelector(eip_config) gateway_conf = settings.get_selected_gateway(domain) if gateway_conf == GATEWAY_AUTOMATIC: gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] if not gateways: self._signaler.signal(self._signaler.eip_no_gateway) return # this only works for selecting the first gateway, as we're # currently doing. ccodes = gateway_selector.get_gateways_country_code() gateway_ccode = '' # '' instead of None due to needed signal argument if ccodes is not None: gateway_ccode = ccodes[gateways[0]] self._signaler.signal(self._signaler.eip_get_gateway_country_code, gateway_ccode)
def get_gateway_country_code(self, domain): """ Signal the country code for the currently used gateway for the given provider. :param domain: the domain to get country code. :type domain: str Signals: eip_get_gateway_country_code -> str eip_no_gateway """ settings = Settings() eip_config = eipconfig.EIPConfig() provider_config = ProviderConfig.get_provider_config(domain) api_version = provider_config.get_api_version() eip_config.set_api_version(api_version) eip_config.load(eipconfig.get_eipconfig_path(domain)) gateway_selector = eipconfig.VPNGatewaySelector(eip_config) gateway_conf = settings.get_selected_gateway(domain) if gateway_conf == GATEWAY_AUTOMATIC: gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] if not gateways: self._signaler.signal(self._signaler.eip_no_gateway) return # this only works for selecting the first gateway, as we're # currently doing. ccodes = gateway_selector.get_gateways_country_code() gateway_ccode = '' # '' instead of None due to needed signal argument if ccodes is not None: gateway_ccode = ccodes[gateways[0]] self._signaler.signal(self._signaler.eip_get_gateway_country_code, gateway_ccode)