diff --git a/internal/cli/cli.go b/internal/cli/cli.go index b874854a..370091f6 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -88,16 +88,21 @@ func (cli *CLI) ConnectCluster(ctx context.Context, clusterName string) (*client // TODO: iterate over all connections and try to connect to the cluster using the first successful connection. conn := cfg.Connections[0] - user, host, port, err := conn.SSH.Parse() - if err != nil { - return nil, fmt.Errorf("parse SSH connection %q: %w", conn.SSH, err) + if conn.SSH != "" { + user, host, port, err := conn.SSH.Parse() + if err != nil { + return nil, fmt.Errorf("parse SSH connection %q: %w", conn.SSH, err) + } + sshConfig := &connector.SSHConnectorConfig{ + User: user, + Host: host, + Port: port, + } + return client.New(ctx, connector.NewSSHConnector(sshConfig)) + } else if conn.TCP.IsValid() { + return client.New(ctx, connector.NewTCPConnector(conn.TCP)) } - sshConfig := &connector.SSHConnectorConfig{ - User: user, - Host: host, - Port: port, - } - return client.New(ctx, connector.NewSSHConnector(sshConfig)) + return nil, errors.New("no valid connection configuration found for the cluster") } func (cli *CLI) InitCluster( diff --git a/internal/cli/config/connection.go b/internal/cli/config/connection.go index f85e5c0d..8a4158df 100644 --- a/internal/cli/config/connection.go +++ b/internal/cli/config/connection.go @@ -2,6 +2,7 @@ package config import ( "net" + "net/netip" "strconv" "strings" "uncloud/internal/secret" @@ -14,6 +15,7 @@ const ( type MachineConnection struct { SSH SSHDestination `toml:"ssh,omitempty"` + TCP netip.AddrPort `toml:"tcp,omitempty"` Host string `toml:"host,omitempty"` PublicKey secret.Secret `toml:"public_key,omitempty"` }