cli

package
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnectCommandName                  = "connect"
	DisconnectCommandName               = "disconnect"
	ConnectionWebRTCAgentCommandName    = "webrtc_agent"
	ConnectionProxyAgentCommandName     = "proxy_agent"
	ConnectionWebSocketAgentCommandName = "websocket_agent"
)
View Source
const (
	FwdInitializing = iota // 0: The initial state after creation
	FwdReady        = iota
	FwdConnected    = iota
	FwdStopped      = iota
	FwdFailed       = iota
)
View Source
const (
	NoneCredentialsSource     = "none"
	InjectedCredentialsSource = "injected"
)
View Source
const (
	CVDHostPackageDirName = "cvd-host_package"
	CVDHostPackageName    = "cvd-host_package.tar.gz"
)
View Source
const (
	AndroidBuildTopVarName   = "ANDROID_BUILD_TOP"
	AndroidProductOutVarName = "ANDROID_PRODUCT_OUT"
)
View Source
const ADBServerPort = 5037
View Source
const RequiredImagesFilename = "device/google/cuttlefish/required_images"

Variables

This section is empty.

Functions

func ControlSocketName

func ControlSocketName(_ RemoteCVDLocator, cs ConnStatus) string

func DisconnectCVD

func DisconnectCVD(controlDir string, cvd RemoteCVDLocator, status ConnStatus) error

func EnsureConnDirsExist

func EnsureConnDirsExist(controlDir string) error

func ExpandPath

func ExpandPath(path string) string

func FindOrConnect

func FindOrConnect(controlDir string, cvd RemoteCVDLocator, service client.Service, localICEConfig *wclient.ICEConfig) (findOrConnRet, error)

func GetHostOutRelativePath

func GetHostOutRelativePath(targetArch string) (string, error)

func GetProxySocketPath

func GetProxySocketPath(controlDir, host, device string) string

func ImportAcloudConfig

func ImportAcloudConfig(src, dst string) error

func ListLocalImageRequiredFiles

func ListLocalImageRequiredFiles(buildTop, productOut string) ([]string, error)

List the required filenames to create a cuttlefish instance given the `build top` and `product out` values from an environment where Android was built.

func LoadConfig

func LoadConfig(srcs []string, c *Config) error

func PromptSelectionFromMap

func PromptSelectionFromMap[K comparable, T any](c *command, choices map[K]T, toStr func(K, T) string, selOpt SelectionOption) (map[K]T, error)

func PromptSelectionFromSlice

func PromptSelectionFromSlice[T any](c *command, choices []T, toStr func(T) string, selOpt SelectionOption) ([]T, error)

The PromptSelectionFromSlice<Type> functions iterate over given container and present users with a prompt like this: 0: String representation of first choice 2: String representation of second choice ... N: All Choose an option: <cursor> These should have been methods of command, but Go doesn't allow generic methods.

func PromptSelectionFromSliceString

func PromptSelectionFromSliceString(c *command, choices []string, selOpt SelectionOption) ([]string, error)

func PromptYesOrNo

func PromptYesOrNo(out *os.File, in *os.File, text string) (bool, error)

func StateAsStr

func StateAsStr(state int) string

func WriteListCVDsOutput

func WriteListCVDsOutput(w io.Writer, hosts []*RemoteHost)

Types

type ADBServerProxy

type ADBServerProxy interface {
	Connect(port int) error
	ConnectWithLocalFileSystem(path string) error
	Disconnect(port int) error
	DisconnectWithLocalFileSystem(path string) error
}

type ADBServerProxyImpl

type ADBServerProxyImpl struct{}

func (*ADBServerProxyImpl) Connect

func (p *ADBServerProxyImpl) Connect(port int) error

func (*ADBServerProxyImpl) ConnectWithLocalFileSystem

func (p *ADBServerProxyImpl) ConnectWithLocalFileSystem(path string) error

func (*ADBServerProxyImpl) Disconnect

func (p *ADBServerProxyImpl) Disconnect(port int) error

func (*ADBServerProxyImpl) DisconnectWithLocalFileSystem

func (p *ADBServerProxyImpl) DisconnectWithLocalFileSystem(path string) error

type AcloudConfig

type AcloudConfig struct {
	Zone        string
	MachineType string
}

type AsArgs

type AsArgs interface {
	AsArgs() []string
}

type AuthnConfig

type AuthnConfig struct {
	OIDCToken      *OIDCTokenConfig      `json:"oidc_token,omitempty"`
	HTTPBasicAuthn *HTTPBasicAuthnConfig `json:"http_basic_authn,omitempty"`
}

type CVDRemoteCommand

type CVDRemoteCommand struct {
	// contains filtered or unexported fields
}

func NewCVDRemoteCommand

func NewCVDRemoteCommand(o *CommandOptions) *CVDRemoteCommand

func (*CVDRemoteCommand) Execute

func (c *CVDRemoteCommand) Execute() error

type CVDRemoteFlags

type CVDRemoteFlags struct {
	ServiceURL string
	Zone       string
	Proxy      string
	Verbose    bool
}

func (*CVDRemoteFlags) AsArgs

func (f *CVDRemoteFlags) AsArgs() []string

type CommandOptions

type CommandOptions struct {
	IOStreams
	Args           []string
	InitialConfig  Config
	ServiceBuilder client.ServiceBuilder
	CommandRunner  CommandRunner
	ADBServerProxy ADBServerProxy
}

type CommandRunner

type CommandRunner interface {
	// Start a command and doesn't wait for it to exit. Instead it reads its entire
	// standard output and returns that or an error. The commands stdin and stderr
	// should be connected to sensible IO channels.
	StartBgCommand(...string) ([]byte, error)
}

type Config

type Config struct {
	// Default service, service to be used in case none other was selected.
	SystemDefaultService string `json:"system_default_service,omitempty"`
	// [OPTIONAL] If set, it overrides the `SystemDefaultService` parameter.
	UserDefaultService   string              `json:"user_default_service,omitempty"`
	Services             map[string]*Service `json:"services,omitempty"`
	ConnectionControlDir string              `json:"connection_control_dir,omitempty"`
	KeepLogFilesDays     int                 `json:"keep_log_files_days,omitempty"`
}

func BaseConfig

func BaseConfig() *Config

func (*Config) ConnectionControlDirExpanded

func (c *Config) ConnectionControlDirExpanded() string

func (*Config) DefaultService

func (c *Config) DefaultService() *Service

func (*Config) LogFilesDeleteThreshold

func (c *Config) LogFilesDeleteThreshold() time.Duration

type ConnController

type ConnController struct {
	// contains filtered or unexported fields
}

Controls the webrtc connection maintained between the connection agent and a cvd. Implements the Observer interface for the webrtc client.

func NewConnController

func NewConnController(
	controlDir string,
	service client.Service,
	cvd RemoteCVDLocator,
	localICEConfig *wclient.ICEConfig) (*ConnController, error)

func (*ConnController) ADBPort

func (tc *ConnController) ADBPort() int

func (*ConnController) OnADBDataChannel

func (tc *ConnController) OnADBDataChannel(dc *webrtc.DataChannel)

func (*ConnController) OnClose

func (tc *ConnController) OnClose()

func (*ConnController) OnError

func (tc *ConnController) OnError(err error)

func (*ConnController) OnFailure

func (tc *ConnController) OnFailure()

func (*ConnController) Run

func (tc *ConnController) Run()

func (*ConnController) Status

func (tc *ConnController) Status() ConnStatus

func (*ConnController) Stop

func (tc *ConnController) Stop()

type ConnStatus

type ConnStatus struct {
	ADB ForwarderState
}

func ConnectDevice

func ConnectDevice(host, device, ice_config, agent string, c *command, opts *subCommandOpts) (*ConnStatus, error)

Starts a connection agent process and waits for it to report the connection was successfully created or an error occurred.

type ConnectFlags

type ConnectFlags struct {
	*CVDRemoteFlags
	// contains filtered or unexported fields
}

func (*ConnectFlags) AsArgs

func (f *ConnectFlags) AsArgs() []string

type CreateCVDFlags

type CreateCVDFlags struct {
	*CVDRemoteFlags
	*CreateCVDOpts
	*CreateHostOpts
}

type CreateCVDLocalOpts

type CreateCVDLocalOpts struct {
	LocalBootloaderSrc string
	LocalCVDHostPkgSrc string
	LocalImagesSrcs    []string
	LocalImagesZipSrc  string
}

type CreateCVDOpts

type CreateCVDOpts struct {
	Host            string
	MainBuild       hoapi.AndroidCIBuild
	KernelBuild     hoapi.AndroidCIBuild
	BootloaderBuild hoapi.AndroidCIBuild
	SystemImgBuild  hoapi.AndroidCIBuild
	LocalImage      bool
	// Creates multiple instances. Only relevant if given a single build source.
	NumInstances int
	// Structure: https://android.googlesource.com/device/google/cuttlefish/+/8bbd3b9cd815f756f332791d45c4f492b663e493/host/commands/cvd/parser/README.md
	// Example: https://cs.android.com/android/platform/superproject/main/+/main:device/google/cuttlefish/host/cvd_test_configs/main_phone-main_watch.json;drc=b2e8f4f014abb7f9cb56c0ae199334aacb04542d
	EnvConfig map[string]interface{}
	// If true, perform the ADB connection automatically.
	AutoConnect               bool
	BuildAPICredentialsSource string
	CreateCVDLocalOpts
}

func (*CreateCVDOpts) AdditionalInstancesNum

func (o *CreateCVDOpts) AdditionalInstancesNum() uint32

type CreateGCPHostOpts

type CreateGCPHostOpts struct {
	MachineType        string
	MinCPUPlatform     string
	AcceleratorConfigs []acceleratorConfig
}

type CreateHostFlags

type CreateHostFlags struct {
	*CVDRemoteFlags
	*CreateHostOpts
}

type CreateHostOpts

type CreateHostOpts struct {
	GCP CreateGCPHostOpts
}

type CredentialsFactory

type CredentialsFactory func() string

type DeleteCVDFlags

type DeleteCVDFlags struct {
	*CVDRemoteFlags
	Host string
}

type Forwarder

type Forwarder struct {
	// contains filtered or unexported fields
}

Forwards messages between a local TCP server and a webrtc data channel.

func NewForwarder

func NewForwarder(logger *log.Logger) (*Forwarder, error)

func (*Forwarder) OnDataChannel

func (f *Forwarder) OnDataChannel(dc *webrtc.DataChannel)

func (*Forwarder) Send

func (f *Forwarder) Send(data []byte) error

func (*Forwarder) State

func (f *Forwarder) State() ForwarderState

func (*Forwarder) StopForwarding

func (f *Forwarder) StopForwarding(state int)

type ForwarderState

type ForwarderState struct {
	Port  int    `json:"port"`
	State string `json:"state"`
}

type GCPHostConfig

type GCPHostConfig struct {
	MachineType    string `json:"machine_type,omitempty"`
	MinCPUPlatform string `json:"min_cpu_platform,omitempty"`
}

type HTTPBasicAuthnConfig

type HTTPBasicAuthnConfig struct {
	UsernameSrc UsernameSrcType `json:"username_src,omitempty"`
}

type HostConfig

type HostConfig struct {
	GCP GCPHostConfig `json:"gcp,omitempty"`
}

type IOStreams

type IOStreams struct {
	In     io.Reader
	Out    io.Writer
	ErrOut io.Writer
}

Groups streams for standard IO.

type ListCVDsFlags

type ListCVDsFlags struct {
	*CVDRemoteFlags
	Host string
}

type MissingEnvVarErr

type MissingEnvVarErr string

func (MissingEnvVarErr) Error

func (s MissingEnvVarErr) Error() string

type OIDCTokenConfig

type OIDCTokenConfig struct {
	TokenFile string `json:"token_file,omitempty"`
}

type RemoteCVD

type RemoteCVD struct {
	RemoteCVDLocator
	Status     string
	Displays   []string
	ConnStatus *ConnStatus
}

func NewRemoteCVD

func NewRemoteCVD(url, host string, cvd *hoapi.CVD) *RemoteCVD

type RemoteCVDLocator

type RemoteCVDLocator struct {
	ServiceRootEndpoint string `json:"service_root_endpoint"`
	Host                string `json:"host"`
	// Identifier within the whole fleet.
	ID string `json:"id"`
	// Identifier within a group.
	Name string `json:"name"`
	// Instead of `Name`, `WebRTCDeviceID` is the identifier used for setting up the adb connections. It
	// contains the group name and the device name, eg: "cvd-1_1".
	WebRTCDeviceID string `json:"webrtc_device_id"`
	// ADB port of Cuttlefish instance.
	ADBSerial string `json:"adb_serial"`
}

type RemoteHost

type RemoteHost struct {
	ServiceRootEndpoint string `json:"service_root_endpoint"`
	Name                string `json:"host"`
	CVDs                []*RemoteCVD
}

type SelectionOption

type SelectionOption int32
const (
	Single   SelectionOption = 0
	AllowAll SelectionOption = 1 << iota
)

type Service

type Service struct {
	ServiceURL                string       `json:"service_url,omitempty"`
	Zone                      string       `json:"zone,omitempty"`
	Proxy                     string       `json:"proxy,omitempty"`
	BuildAPICredentialsSource string       `json:"build_api_credentials_source,omitempty"`
	Host                      *HostConfig  `json:"host,omitempty"`
	Authn                     *AuthnConfig `json:"authn,omitempty"`
}

type StatusCmdRes

type StatusCmdRes struct {
	CVD    RemoteCVDLocator
	Status ConnStatus
}

type UsernameSrcType

type UsernameSrcType string
const UnixUsernameSrc UsernameSrcType = "unix"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL