Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/streamer_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Streamer Types

`gnetcli` supports different connection types (streamers) for connecting to network equipment: SSH, Telnet.

## Supported Types

### Unknown (StreamerType_unknown)
- **Value**: `0`
- **Description**: Unspecified connection type, server will determine based on port or default to SSH
- **Usage**: When not explicitly set

### SSH (StreamerType_ssh)
- **Value**: `1`
- **Description**: Connection via SSH protocol (default when unknown)
- **Default port**: 22
- **Features**:
- SSH tunnel support (ProxyJump)
- SSH Control Files support
- SSH Agent support
- Private key authentication
- SFTP for file transfers

### Telnet (StreamerType_telnet)
- **Value**: `2`
- **Description**: Connection via Telnet protocol
- **Default port**: 23
- **Features**:
- Plain text connection
- Username/password authentication
- Custom port support

## API Usage

### Via gRPC
The streamer type is specified in host parameters:

```protobuf
message HostParams {
string host = 1;
Credentials credentials = 2;
int32 port = 3;
string device = 4;
string ip = 5;
StreamerType streamer_type = 6; // SSH or Telnet
}
```

### Example Request
```json
{
"host": "192.168.1.1",
"cmd": "show version",
"host_params": {
"streamer_type": 2,
"port": 23,
"credentials": {
"login": "admin",
"password": "password"
}
}
}
```
Note: `streamer_type: 2` for Telnet, `streamer_type: 1` for SSH, `streamer_type: 0` for unknown/auto-detect.

## Choosing Streamer Type

### SSH is recommended for:
- Modern network equipment
- Production environments where security is important
- Devices supporting cryptographic authentication
- Cases requiring file transfers

### Telnet is suitable for:
- Legacy equipment without SSH support
- Lab and test environments
- Devices with limited computational resources
- Connection debugging and diagnostics

## Default Configuration

If `streamer_type` is not explicitly specified, SSH is used as the more secure default option.
29 changes: 29 additions & 0 deletions grpc_sdk/python/gnetclisdk/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""gnetcli SDK for Python"""

from .client import (
Credentials,
File,
Gnetcli,
HostParams,
QA,
STREAMER_UNKNOWN,
STREAMER_SSH,
STREAMER_TELNET,
)
from .exceptions import (
DeviceConnectError,
GnetcliException,
)

__all__ = [
"Credentials",
"File",
"Gnetcli",
"HostParams",
"QA",
"STREAMER_UNKNOWN",
"STREAMER_SSH",
"STREAMER_TELNET",
"DeviceConnectError",
"GnetcliException",
]
10 changes: 9 additions & 1 deletion grpc_sdk/python/gnetclisdk/client.py
Comment thread
gescheit marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import asynccontextmanager
from dataclasses import dataclass, field
from functools import partial
from typing import Any, AsyncIterator, List, Optional, Tuple, Dict, Callable
from typing import Any, AsyncIterator, List, Optional, Tuple, Dict, Callable, Union

import grpc
from google.protobuf.message import Message
Expand All @@ -25,6 +25,10 @@
SERVER_ENV = "GNETCLI_SERVER"
GRPC_MAX_MESSAGE_LENGTH = 130 * 1024**2

STREAMER_UNKNOWN = server_pb2.StreamerType_unknown
STREAMER_SSH = server_pb2.StreamerType_ssh
STREAMER_TELNET = server_pb2.StreamerType_telnet

default_grpc_options: List[Tuple[str, Any]] = [
("grpc.max_concurrent_streams", 900),
("grpc.max_send_message_length", GRPC_MAX_MESSAGE_LENGTH),
Expand Down Expand Up @@ -72,6 +76,7 @@ class HostParams:
hostname: Optional[str] = None
credentials: Optional[Credentials] = None
ip: Optional[str] = None
streamer_type: Optional[int] = None

def make_pb(self) -> server_pb2.HostParams:
creds_pb: Optional[server_pb2.Credentials] = None
Expand All @@ -83,6 +88,7 @@ def make_pb(self) -> server_pb2.HostParams:
credentials=creds_pb,
device=self.device,
ip=self.ip,
streamer_type=self.streamer_type if self.streamer_type is not None else server_pb2.StreamerType_unknown,
)
return pbcmd

Expand Down Expand Up @@ -247,6 +253,8 @@ async def set_host_params(self, hostname: str, params: HostParams) -> None:
port=params.port,
credentials=params.credentials.make_pb(),
device=params.device,
ip=params.ip,
streamer_type=params.streamer_type if params.streamer_type is not None else server_pb2.StreamerType_unknown,
)
_logger.debug("connect to %s", self._server)
async with self._grpc_channel_fn(self._server, options=self._options) as channel:
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/devuath.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m authApp) GetHostParams(host string, params *pb.HostParams) (hostParams,
if err != nil {
return hostParams{}, err
}
res := NewHostParams(creds, params.GetDevice(), ip, port, proxyJump, controlPath, connectHost)
res := NewHostParams(creds, params.GetDevice(), ip, port, proxyJump, controlPath, connectHost, params.GetStreamerType())
return res, nil
}

Expand Down
Loading
Loading