示例#1
0
def tunnel(ctx, tunnel_name):
    """
    Tunnel through an EC2 instance in the ECS cluster.

    The parameters for this command should be found in a tunnels: top-level section in the yaml file, in the format:

    \b
    tunnels:
      - name: my_tunnel
        service: my_service
        host: config.MY_TUNNEL_DESTINATION_HOST
        port: 3306
        local_port: 8888

    where config.MY_TUNNEL_DESTINATION_HOST is the value of MY_TUNNEL_DESTINATION_HOST
    for this service in the AWS Parameter Store. The host value could also just
    be a hostname.

    """
    config = Config(filename=ctx.obj['CONFIG_FILE'],
                    env_file=ctx.obj['ENV_FILE'],
                    import_env=ctx.obj['IMPORT_ENV'],
                    tfe_token=ctx.obj['TFE_TOKEN'])
    yml = config.get_category_item('tunnels', tunnel_name)
    service_name = yml['service']

    service = Service(yml=config.get_service(service_name))
    host = _interpolate_tunnel_info(yml['host'], service)
    port = int(_interpolate_tunnel_info(yml['port'], service))
    local_port = int(_interpolate_tunnel_info(yml['local_port'], service))

    interim_port = random.randrange(10000, 64000, 1)

    service.tunnel(host, local_port, interim_port, port)
示例#2
0
class TestTunnelParameters_load_yqml(unittest.TestCase):
    def setUp(self):
        current_dir = os.path.dirname(os.path.abspath(__file__))
        config_yml = os.path.join(current_dir, 'interpolate.yml')
        env_file = os.path.join(current_dir, 'env_file.env')
        self.config = Config(filename=config_yml,
                             env_file=env_file,
                             interpolate=False)

    def test_tunnel_find_instance(self):
        yml = self.config.get_category_item('tunnels', 'test')
        self.assertEqual(yml['service'], 'cit-auth-prod')
        self.assertEqual(yml['host'], 'config.DB_HOST')
        self.assertEqual(yml['port'], 3306)
        self.assertEqual(yml['local_port'], 8888)