Documentation
¶
Overview ¶
Package client provides an exec.Command and ssh like interface for cpu sessions. It attempts to cleave as much as possible to the original. The choice between options and environment variables mirrors this effort. For example, the namespace for the remote process is an environment variable, CPU_NAMESPACE. The nonce for the mount protocol back is also an environment variable. command name and arguments are passed in os.Args The only required parameter for Command() is a host name; if os.Args is empty, the remote server reads SHELL and starts a shell. Similarly, because the root for the client namespace is known only to the client. it is settable in the Cmd struct.
Index ¶
- Constants
- Variables
- func DsLookup(query dsQuery) (string, string, error)
- func DsParse(uri string) (dsQuery, error)
- func GetHostName(host string) string
- func GetKeyFile(host, kf string) string
- func GetPort(host, port string) (string, error)
- func SetVerbose(f func(string, ...interface{}))
- type Cmd
- func (c *Cmd) Close() error
- func (c *Cmd) Dial() error
- func (c *Cmd) HostKeyConfig(hostKeyFile string) error
- func (c *Cmd) Outputs() ([]bytes.Buffer, error)
- func (c *Cmd) Run() error
- func (c *Cmd) SSHStdin(w io.WriteCloser, r io.Reader)
- func (c *Cmd) SetEnv(envs ...string) error
- func (c *Cmd) SetOptions(opts ...Set) error
- func (c *Cmd) SetupInteractive() error
- func (c *Cmd) Signal(s ssh.Signal) error
- func (c *Cmd) Start() error
- func (c *Cmd) TTYIn(s *ssh.Session, w io.WriteCloser, r io.Reader)
- func (c *Cmd) UserKeyConfig() error
- func (c *Cmd) Wait() error
- type Set
- func With9P(p9 bool) Set
- func WithCpudCommand(cmd string) Set
- func WithFSTab(fstab string) Set
- func WithHostKeyFile(key string) Set
- func WithNameSpace(ns string) Set
- func WithNetwork(network string) Set
- func WithPort(port string) Set
- func WithPrivateKeyFile(key string) Set
- func WithRoot(root string) Set
- func WithTempMount(tmpMnt string) Set
- func WithTimeout(timeout string) Set
Constants ¶
const ( // DefaultNameSpace is the default used if the user does not request // something else. DefaultNameSpace = "/lib:/lib64:/usr:/bin:/etc:/home" )
const (
// DefaultPort is the default cpu port.
DefaultPort = "17010"
)
const DsDefault = "dnssd:"
Variables ¶
var ( // DefaultKeyFile is the default key for cpu users. DefaultKeyFile = filepath.Join(os.Getenv("HOME"), ".ssh/cpu_rsa") // Debug9p enables 9p debugging. Debug9p bool // Dump9p enables dumping 9p packets. Dump9p bool // DumpWriter is an io.Writer to which dump packets are written. DumpWriter io.Writer = os.Stderr )
var V = func(string, ...interface{}) {}
V allows debug printing.
Functions ¶
func DsLookup ¶
lookup based on hostname, return resolved host, port, network, and error uri currently supported dnssd://domain/_service._network/instance?reqkey=reqvalue default for domain is local, first path element is _ncpu._tcp, and instance is wildcard can omit to underspecify, e.g. dnssd:?arch=arm64 to pick any arm64 cpu server
func GetHostName ¶
GetHostName reads the host name from the ssh config file, if needed. If it is not found, the host name is returned.
func GetKeyFile ¶
GetKeyFile picks a keyfile if none has been set. It will use ssh config, else use a default.
func GetPort ¶
GetPort gets a port. It verifies that the port fits in 16-bit space. The rules here are messy, since config.Get will return "22" if there is no entry in .ssh/config. 22 is not allowed. So in the case of "22", convert to defaultPort.
func SetVerbose ¶
func SetVerbose(f func(string, ...interface{}))
Types ¶
type Cmd ¶
type Cmd struct { // CPU-specific options. // As in exec.Command, these controls are exposed and can // be set directly. Host string // HostName as found in .ssh/config; set to Host if not found HostName string Args []string Root string HostKeyFile string PrivateKeyFile string Port string Timeout time.Duration Env []string Stdin io.WriteCloser Stdout io.Reader Stderr io.Reader Row int Col int // NameSpace is a string as defined in the cpu documentation. NameSpace string // FSTab is an fstab(5)-format string FSTab string // Ninep determines if client will run a 9P server Ninep bool TmpMnt string // contains filtered or unexported fields }
Cmd is a cpu client. It implements as much of exec.Command as makes sense.
func Command ¶
Command implements exec.Command. The required parameter is a host. The args arg args to $SHELL. If there are no args, then starting $SHELL is assumed.
func (*Cmd) Dial ¶
Dial implements ssh.Dial for cpu. Additionaly, if Cmd.Root is not "", it starts up a server for 9p requests.
func (*Cmd) HostKeyConfig ¶
HostKeyConfig sets the host key. It is optional.
func (*Cmd) Outputs ¶
Outputs returns a slice of bytes.Buffer for stdout and stderr, and an error if either had trouble being read.
func (*Cmd) SSHStdin ¶
func (c *Cmd) SSHStdin(w io.WriteCloser, r io.Reader)
SSHStdin implements an ssh-like reader, honoring ~ commands.
func (*Cmd) SetOptions ¶
SetOptions sets various options into the Command.
func (*Cmd) SetupInteractive ¶
SetupInteractive sets up a cpu client for interactive access. It returns a function to be run when the session ends.
func (*Cmd) UserKeyConfig ¶
UserKeyConfig sets up authentication for a User Key. It is required in almost all cases.
type Set ¶
Set is the type of function used to set options in SetOptions.
func With9P ¶
With9P enables the 9P2000 server in cpu. The server is by default disabled. Ninep is sticky; if set by, e.g., WithNameSpace, the Principle of Least Confusion argues that it should remain set. Hence, we || it with its current value.
func WithCpudCommand ¶
WithCpudCommand sets the initial command to run on the remote side. This is extremely helpful when testing new implementations of cpud, of little use otherwise.
func WithHostKeyFile ¶
WithHostKeyFile adds a host key to a Cmd
func WithNameSpace ¶
WithNameSpace sets the namespace to Cmd.There is no default: having some default violates the principle of least surprise for package users. If ns is non-empty the Ninep is forced on.
func WithNetwork ¶
WithNetwork sets the network. This almost never needs to be set, save for vsock.
func WithPort ¶
WithPort sets the port in the Cmd. It calls GetPort with the passed-in port before assigning it.
func WithPrivateKeyFile ¶
WithPrivateKeyFile adds a private key file to a Cmd
func WithTempMount ¶
WithTempMount sets the private namespace mount point.