Пример #1
0
    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 test_get_gateway_with_no_locations(self):
     gateway_selector = VPNGatewaySelector(self.eipconfig)
     self.eipconfig.get_gateways = Mock(
         return_value=sample_gateways_no_location)
     self.eipconfig.get_locations = Mock(return_value=[])
     gateways = gateway_selector.get_gateways()
     gateways_default_order = [
         sample_gateways[0]['ip_address'], sample_gateways[1]['ip_address'],
         sample_gateways[2]['ip_address']
     ]
     self.assertEqual(gateways, gateways_default_order)
Пример #3
0
    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 test_get_no_gateways(self):
     gateway_selector = VPNGatewaySelector(self.eipconfig)
     self.eipconfig.get_gateways = Mock(return_value=[])
     gateways = gateway_selector.get_gateways()
     self.assertEqual(gateways, [])
 def test_correct_order_gmt_plus_14(self):
     gateway_selector = VPNGatewaySelector(self.eipconfig, 14)
     gateways = gateway_selector.get_gateways()
     self.assertEqual(gateways, [ips[4], ips[2], ips[3], ips[1]])