Connecting to a cluster YTsaurus
Note
The service is at the Preview stage.
You can connect to a YTsaurus cluster:
- From Yandex Cloud VMs.
- Via the internet over HTTPS.
Examples of connection strings
The examples for Linux were tested in the following environment:
- Yandex Cloud VM running Ubuntu 20.04 LTS.
- Bash:
5.0.16. - Python:
3.8.2; pip3:20.0.2. - Go:
1.24.8.
Bash
Before connecting:
-
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
-
Install the YTsaurus CLI according to the instructions
. -
Install the dependencies:
sudo apt update && sudo apt install -y python3 python3-pip && \ pip3 install ytsaurus-client-yc-auth
-
Get the access configuration file using the following YC CLI command:
yc managed-ytsaurus cluster get-configuration <cluster_name_or_ID> --privateConfiguration file example
{ auth_class = { module_name = "yc_managed_ytsaurus_auth"; class_name = "IamTokenAuth"; }; proxy = { url = "http://hp.<YTsaurus_cluster_ID>.ytsaurus.mdb.yandexcloud.net:32100"; network_name = "external"; http_proxy_role = "default"; } }The configuration file will be saved to
~/.yt/config.You can get the cluster ID with the list of clusters in the folder.
-
Run a request for the root directory contents list:
yt list /
-
Get the access configuration file using the following YC CLI command:
yc managed-ytsaurus cluster get-configuration <cluster_name_or_ID>Configuration file example
{ auth_class = { module_name = "yc_managed_ytsaurus_auth"; class_name = "IamTokenAuth"; }; proxy = { url = "https://<YTsaurus_cluster_ID>.proxy.ytsaurus.yandexcloud.net"; enable_proxy_discovery = %false; } }The configuration file will be saved to
~/.yt/config.You can get the cluster ID with the list of clusters in the folder.
-
Run a request for the root directory contents list:
yt list /
Go
The example uses OAuth token-based authorization.
To connect to your cluster:
-
Install the dependencies:
sudo apt update && sudo apt install --yes golang git && \ go mod init example && go get go.ytsaurus.tech/yt/go -
Issue an OAuth token.
-
Prepare a sample file for connection:
connect.go
package main import ( "context" "flag" "fmt" "time" ycsdk "github.com/yandex-cloud/go-sdk" ytsdk "go.ytsaurus.tech/yt/go/yt" ythttpsdk "go.ytsaurus.tech/yt/go/yt/ythttp" ) func main() { clusterID := flag.String("id", "", "YTsaurus cluster ID") token := flag.String("token", "", "OAuth token") flag.Parse() ctx := context.Background() sdk, err := ycsdk.Build(ctx, ycsdk.Config{ Credentials: ycsdk.OAuthToken(*token), }) if err != nil { panic(err) } iamTokenProvider, err := IamTokenProvider(ctx, sdk) if err != nil { panic(err) } timeout := 10 * time.Second client, err := ythttpsdk.NewClient(&ytsdk.Config{ Proxy: fmt.Sprintf("https://%s.proxy.ytsaurus.yandexcloud.net", *clusterID), LightRequestTimeout: &timeout, DisableProxyDiscovery: true, CredentialsProviderFn: iamTokenProvider, }) if err != nil { panic(err) } res, err := client.WhoAmI(context.Background(), nil) if err != nil { panic(err) } fmt.Printf("Logged in as %s\n", res.Login) } func IamTokenProvider(ctx context.Context, sdk *ycsdk.SDK) (ytsdk.CredentialsProviderFn, error) { var now = time.Now tokenMiddleware := ycsdk.NewIAMTokenMiddleware(sdk, now) return func(ctx context.Context) (ytsdk.Credentials, error) { currentToken, err := tokenMiddleware.GetIAMToken(ctx, false) if err != nil { return nil, err } return &ytsdk.BearerCredentials{Token: currentToken}, nil }, nil } -
Run this command:
go run connect.go -id <YTsaurus_cluster_ID> -token <user_OAuth_token>You can get the cluster ID with the list of clusters in the folder.
Python
Before connecting:
-
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
-
Install the YTsaurus CLI according to the instructions
. -
Install the dependencies:
sudo apt update && sudo apt install -y python3 python3-pip && \ pip3 install ytsaurus-client-yc-auth
-
Code example:
connect.pyimport yt.wrapper as yt from yc_managed_ytsaurus_auth import with_iam_token_auth client = yt.YtClient( proxy="http://hp.<YTsaurus_cluster_ID>.ytsaurus.mdb.yandexcloud.net:32100", config=with_iam_token_auth( config={"proxy": {"network_name": "external", "http_proxy_role": "default"}} ), ) client.list("/") -
Connecting:
python3 connect.py
-
Code example:
connect.pyimport yt.wrapper as yt from yc_managed_ytsaurus_auth import with_iam_token_auth client = yt.YtClient( proxy="https://<YTsaurus_cluster_ID>.proxy.ytsaurus.yandexcloud.net", config=with_iam_token_auth(config={"proxy": {"enable_proxy_discovery": False}}), ) client.list("/") -
Connecting:
python3 connect.py