Network adapters

Network adapters are for transforming network connections exposed by drivers

class jumpstarter_driver_network.adapters.TcpPortforwardAdapter(*, client: jumpstarter.client.base.DriverClient, method: str = 'connect', local_host: str = '127.0.0.1', local_port: int = 0)
class jumpstarter_driver_network.adapters.UnixPortforwardAdapter(*, client: jumpstarter.client.base.DriverClient, method: str = 'connect')
class jumpstarter_driver_network.adapters.NovncAdapter(*, client: jumpstarter.client.base.DriverClient, method: str = 'connect', local_host: str = '127.0.0.1', local_port: int = 0)
class jumpstarter_driver_network.adapters.PexpectAdapter(*, client: jumpstarter.client.base.DriverClient, method: str = 'connect', local_host: str = '127.0.0.1', local_port: int = 0)
class jumpstarter_driver_network.adapters.FabricAdapter(*, client: jumpstarter.client.base.DriverClient, method: str = 'connect', local_host: str = '127.0.0.1', local_port: int = 0, user: str | None = None, config: fabric.config.Config | None = None, forward_agent: bool | None = None, connect_timeout: int | None = None, connect_kwargs: dict[str, Any] | None = None, inline_ssh_env: bool | None = None)

Examples

export:
  tcp_port:
    type: "jumpstarter_driver_network.driver.TcpNetwork"
    config:
      host: localhost
      port: 80
  unix_socket:
    type: "jumpstarter_driver_network.driver.UnixNetwork"
    config:
      path: /tmp/test.sock

Forward a remote TCP port to a local TCP port

>>> # random port on localhost
>>> with TcpPortforwardAdapter(client=client.tcp_port) as addr:
...     print(addr[0], addr[1])
127.0.0.1 ...
>>>
>>> # specific address and port
>>> with TcpPortforwardAdapter(client=client.tcp_port, local_host="127.0.0.2", local_port=8080) as addr:
...     print(addr[0], addr[1])
127.0.0.2 8080

Forward a remote Unix domain socket to a local socket

>>> with UnixPortforwardAdapter(client=client.unix_socket) as addr:
...     print(addr)
/tmp/jumpstarter-.../socket
>>> # the type of the remote socket and the local one doesn't have to match
>>> # e.g. forward a remote Unix domain socket to a local TCP port
>>> with TcpPortforwardAdapter(client=client.unix_socket) as addr:
...     print(addr[0], addr[1])
127.0.0.1 ...

Connect to a remote TCP port with a web-based VNC client

>>> with NovncAdapter(client=client.tcp_port) as url:
...     print(url) # open the url in browser to access the VNC client
https://novnc.com/noVNC/vnc.html?autoconnect=1&reconnect=1&host=127.0.0.1&port=...

Interact with a remote TCP port as if it’s a serial console

See pexpect for API documentation

>>> # the server echos all inputs
>>> with PexpectAdapter(client=client.tcp_port) as expect:
...     assert expect.send("hello") == 5 # written 5 bytes
...     assert expect.expect(["hi", "hello"]) == 1 # found string at index 1

Connect to a remote TCP port with the fabric SSH client

See fabric for API documentation

with FabricAdapter(client=client.tcp_port, connect_kwargs={"password": "secret"}) as conn:
    conn.run("uname")