Skip to content

feat: adding telnet streamer support#302

Open
vadvolo wants to merge 3 commits into
annetutil:mainfrom
vadvolo:telnet-streamer
Open

feat: adding telnet streamer support#302
vadvolo wants to merge 3 commits into
annetutil:mainfrom
vadvolo:telnet-streamer

Conversation

@vadvolo
Copy link
Copy Markdown
Contributor

@vadvolo vadvolo commented May 22, 2026

Add Telnet Streamer Support with StreamerType Selection

Summary

This PR implements Telnet protocol support as an alternative connection method to the existing SSH streamer, allowing gnetcli to connect to legacy network equipment that may not support SSH. The implementation includes a new StreamerType enum for explicit protocol selection and comprehensive documentation.

Key Changes

Core Implementation

  • Added StreamerType enum in protobuf API with SSH (default) and Telnet options
  • Enhanced HostParams with streamer_type field for explicit protocol selection
  • Refactored server architecture using factory pattern for cleaner streamer instantiation
  • Fixed Telnet port handling to properly use custom ports instead of hardcoded defaults

Protocol Support

  • SSH (StreamerType_ssh = 0) - Default, secure connection with full feature set
  • Telnet (StreamerType_telnet = 1) - Plain text connection for legacy equipment

Architecture Improvements

  • Refactored makeDevice() method using factory pattern to reduce cognitive complexity
  • Added dedicated StreamerConfig struct for cleaner configuration management
  • Implemented separate createStreamerSSH() and createStreamerTelnet() methods
  • Added resolveCredentials() method for better credential handling

Testing & Documentation

  • Comprehensive integration tests covering both SSH and Telnet scenarios:
    • TestTelnetBasicExecution - Basic Telnet command execution
    • TestTelnetCustomPort - Custom port support verification
    • TestStreamerTypeSelection - Protocol selection validation
  • Complete English documentation in docs/streamer_types.md with usage examples
  • API documentation with gRPC examples and best practices

API Changes

  message HostParams {
    // ... existing fields
    StreamerType streamer_type = 6;  // NEW: Protocol selection
  }

  enum StreamerType {
    StreamerType_ssh = 0;     // Default: SSH protocol  
    StreamerType_telnet = 1;  // Telnet protocol
  }

Backward Compatibility

Fully backward compatible - existing code continues to work unchanged

  • streamer_type defaults to SSH when not specified
  • No breaking changes to existing API surface
  • All existing SSH functionality preserved

Example Usage

  // Explicit SSH connection (same as default behavior)
  res, err := client.Exec(ctx, &pb.CMD{
      Host: "router.example.com",
      Cmd:  "show version",
      HostParams: &pb.HostParams{
          Ip:           "192.168.1.1",
          Port:         22,
          Device:       "cisco",
          StreamerType: pb.StreamerType_StreamerType_ssh,
      },
  })

  // Telnet connection for legacy device
  res, err := client.Exec(ctx, &pb.CMD{
      Host: "legacy-switch.example.com",
      Cmd:  "show version",
      HostParams: &pb.HostParams{
          Ip:           "192.168.1.100",
          Port:         23,
          Device:       "cisco",
          StreamerType: pb.StreamerType_StreamerType_telnet,
      },
  })

This implementation provides a robust foundation for multi-protocol support while maintaining the security-first approach with SSH as the default option.

Testing

Annet Config

fetcher:
  default:
    adapter: gnetcli
    params: &gnetcli_params
      dev_login: user
      dev_password: password
  ssh-10022:
    adapter: gnetcli
    params: &gnetcli_params
      dev_login: user
      dev_password: password
      dev_port: 10022
      streamer_type: ssh
  telnet:
    adapter: gnetcli
    params:
      dev_login: user
      dev_password: password
      dev_port: 23
      streamer_type: telnet

context:
  default:
    fetcher: default
    deployer: default
    connection: default
    generators: default
    storage: netbox
  ssh-10022:
    fetcher: ssh-10022
    deployer: default
    connection: default
    generators: default
    storage: netbox
  telnet:
    fetcher: telnet
    deployer: default
    connection: default
    generators: default
    storage: netbox

Diff Result

Cisco Telnet

# context switching from default to telnet
> annet context set-context telnet
root@ec0c2b0a180a:/# annet diff access-switch.com
# -------------------- access-switch.com.cfg --------------------
  interface FastEthernet1/0/1
+   no cdp enable
+   spanning-tree bpdufilter enable
+   spanning-tree bpduguard enable
  interface FastEthernet1/0/4
-   description core-switch.com
+   description NNI: core-switch.com
...

Mikrotik with SSH port 10022

root@ec0c2b0a180a:/# annet diff mikrotik-switch.com
[13:09:49]   ERROR MainProcess - /venv/lib/python3.12/site-packages/annet/gen.py:672 - config error ExecError('AioRpcError generic_error req_id:5aa202ab-614b-42ba-8537-f74a5d75697e') -- host='mikrotik-switch.com'

Switch context to ssh-10022

root@ec0c2b0a180a:/# annet context set-context ssh-10022

Result

root@ec0c2b0a180a:/# annet diff mikrotik-switch.com
# -------------------- mikrotik-switch.com.cfg --------------------
+ system identity set name=mikrotik-switch.com
root@ec0c2b0a180a:/# 

@vadvolo vadvolo changed the title [WIP] feat: adding telnet streamer support feat: adding telnet streamer support May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant