libhoclient

package module
v0.0.0-...-6a22c32 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0, BSD-2-Clause, ISC, + 1 more Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HTTPHeaderBuildAPICreds              = "X-Cutf-Host-Orchestrator-BuildAPI-Creds"
	HTTPHeaderBuildAPICredsUserProjectID = "X-Cutf-Host-Orchestrator-BuildAPI-Creds-User-Project-ID"
	// If used, the Cloud Orchestrator proxy would set/override the "X-Cutf-Host-Orchestrator-BuildAPI-Creds"
	// http header.
	HTTPHeaderCOInjectBuildAPICreds = "X-Cutf-Cloud-Orchestrator-Inject-BuildAPI-Creds"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenBuildAPICreds

type AccessTokenBuildAPICreds struct {
	AccessToken   string
	UserProjectID string
}

func (*AccessTokenBuildAPICreds) ApplyToHTTPRequest

func (c *AccessTokenBuildAPICreds) ApplyToHTTPRequest(rb *HTTPRequestBuilder)

type ApiCallError

type ApiCallError struct {
	opapi.ErrorMsg

	HTTPStatusCode int
}

func (*ApiCallError) Error

func (e *ApiCallError) Error() string

type BuildAPICreds

type BuildAPICreds interface {
	ApplyToHTTPRequest(rb *HTTPRequestBuilder)
}

type ConnectWebRTCOpts

type ConnectWebRTCOpts struct {
	LocalICEConfig *wclient.ICEConfig
}

type CreateBugReportOpts

type CreateBugReportOpts struct {
	IncludeADBBugReport bool
}

type ExpBackOffOptions

type ExpBackOffOptions struct {
	InitialDuration     time.Duration
	RandomizationFactor float64
	Multiplier          float64
	MaxElapsedTime      time.Duration
}

type FakeHostOrchestratorClient

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

Fake implementation of the HostOrchestratorClient interface for use in testing

func NewFakeHostOrchestratorClient

func NewFakeHostOrchestratorClient() *FakeHostOrchestratorClient

func (*FakeHostOrchestratorClient) ConnectADBWebSocket

func (c *FakeHostOrchestratorClient) ConnectADBWebSocket(device string) (*websocket.Conn, error)

func (*FakeHostOrchestratorClient) ConnectWebRTC

func (c *FakeHostOrchestratorClient) ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

func (*FakeHostOrchestratorClient) CreateBugReport

func (c *FakeHostOrchestratorClient) CreateBugReport(group string, opts CreateBugReportOpts, dst io.Writer) error

func (*FakeHostOrchestratorClient) CreateCVD

func (*FakeHostOrchestratorClient) CreateCVDOp

func (*FakeHostOrchestratorClient) CreateImageDirectory

func (c *FakeHostOrchestratorClient) CreateImageDirectory() (*hoapi.Operation, error)

func (*FakeHostOrchestratorClient) CreateSnapshot

func (c *FakeHostOrchestratorClient) CreateSnapshot(groupName, instanceName string, req *hoapi.CreateSnapshotRequest) (*hoapi.CreateSnapshotResponse, error)

func (*FakeHostOrchestratorClient) CreateUploadDir

func (c *FakeHostOrchestratorClient) CreateUploadDir() (string, error)

func (*FakeHostOrchestratorClient) DeleteCVD

func (c *FakeHostOrchestratorClient) DeleteCVD(id string) error

func (*FakeHostOrchestratorClient) DeleteImageDirectory

func (c *FakeHostOrchestratorClient) DeleteImageDirectory(id string) (*hoapi.Operation, error)

func (*FakeHostOrchestratorClient) DeleteSnapshot

func (c *FakeHostOrchestratorClient) DeleteSnapshot(string) error

func (*FakeHostOrchestratorClient) ExtractArtifact

func (c *FakeHostOrchestratorClient) ExtractArtifact(filename string) (*hoapi.Operation, error)

func (*FakeHostOrchestratorClient) ExtractFile

func (c *FakeHostOrchestratorClient) ExtractFile(uploadDir string, filename string) (*hoapi.Operation, error)

func (*FakeHostOrchestratorClient) FetchArtifacts

func (*FakeHostOrchestratorClient) ListCVDs

func (c *FakeHostOrchestratorClient) ListCVDs() ([]*hoapi.CVD, error)

func (*FakeHostOrchestratorClient) ListImageDirectories

func (*FakeHostOrchestratorClient) Powerbtn

func (c *FakeHostOrchestratorClient) Powerbtn(groupName, instanceName string) error

func (*FakeHostOrchestratorClient) Powerwash

func (c *FakeHostOrchestratorClient) Powerwash(groupName, instanceName string) error

func (*FakeHostOrchestratorClient) Reset

func (c *FakeHostOrchestratorClient) Reset() error

func (*FakeHostOrchestratorClient) Start

func (c *FakeHostOrchestratorClient) Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error

func (*FakeHostOrchestratorClient) Stop

func (c *FakeHostOrchestratorClient) Stop(groupName, instanceName string) error

func (*FakeHostOrchestratorClient) UpdateImageDirectoryWithUserArtifact

func (c *FakeHostOrchestratorClient) UpdateImageDirectoryWithUserArtifact(id, filename string) (*hoapi.Operation, error)

func (*FakeHostOrchestratorClient) UploadArtifact

func (c *FakeHostOrchestratorClient) UploadArtifact(filename string) error

func (*FakeHostOrchestratorClient) UploadFile

func (c *FakeHostOrchestratorClient) UploadFile(uploadDir string, filename string) error

func (*FakeHostOrchestratorClient) UploadFileWithOptions

func (c *FakeHostOrchestratorClient) UploadFileWithOptions(uploadDir string, filename string, options UploadOptions) error

func (*FakeHostOrchestratorClient) WaitForOperation

func (c *FakeHostOrchestratorClient) WaitForOperation(opName string, result any) error

type FilesUploader

type FilesUploader struct {
	HTTPHelper     HTTPHelper
	UploadEndpoint string
	DumpOut        io.Writer
	UploadOptions
}

func (*FilesUploader) Upload

func (u *FilesUploader) Upload(files []string) error

type HTTPHelper

type HTTPHelper struct {
	Client            *http.Client
	RootEndpoint      string
	Dumpster          io.Writer
	AccessToken       string
	HTTPBasicUsername string
}

func (*HTTPHelper) NewDeleteRequest

func (h *HTTPHelper) NewDeleteRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewGetRequest

func (h *HTTPHelper) NewGetRequest(path string) *HTTPRequestBuilder

func (*HTTPHelper) NewPostRequest

func (h *HTTPHelper) NewPostRequest(path string, jsonBody any) *HTTPRequestBuilder

func (*HTTPHelper) NewPutRequest

func (h *HTTPHelper) NewPutRequest(path string, jsonBody any) *HTTPRequestBuilder

func (*HTTPHelper) NewUploadFileRequest

func (h *HTTPHelper) NewUploadFileRequest(ctx context.Context, path string, body io.Reader, contentType string) *HTTPRequestBuilder

type HTTPRequestBuilder

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

func (*HTTPRequestBuilder) AddHeader

func (rb *HTTPRequestBuilder) AddHeader(key, value string)

func (*HTTPRequestBuilder) Do

func (rb *HTTPRequestBuilder) Do() (*http.Response, error)

func (*HTTPRequestBuilder) JSONResDo

func (rb *HTTPRequestBuilder) JSONResDo(ret any) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) JSONResDoWithRetries

func (rb *HTTPRequestBuilder) JSONResDoWithRetries(ret any, retryOpts RetryOptions) error

Expects a response with JSON body to be decoded into `ret`.

func (*HTTPRequestBuilder) SetBasicAuth

func (rb *HTTPRequestBuilder) SetBasicAuth()

func (*HTTPRequestBuilder) SetHeader

func (rb *HTTPRequestBuilder) SetHeader(key, value string)

type HostOrchestratorClient

A client to the host orchestrator service running in a remote host.

type HostOrchestratorClientImpl

type HostOrchestratorClientImpl struct {
	HTTPHelper HTTPHelper
	ProxyURL   string
}

func NewHostOrchestratorClient

func NewHostOrchestratorClient(url string) *HostOrchestratorClientImpl

func (*HostOrchestratorClientImpl) ConnectADBWebSocket

func (c *HostOrchestratorClientImpl) ConnectADBWebSocket(device string) (*websocket.Conn, error)

func (*HostOrchestratorClientImpl) ConnectWebRTC

func (c *HostOrchestratorClientImpl) ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)

func (*HostOrchestratorClientImpl) CreateBugReport

func (c *HostOrchestratorClientImpl) CreateBugReport(group string, opts CreateBugReportOpts, dst io.Writer) error

func (*HostOrchestratorClientImpl) CreateCVD

func (*HostOrchestratorClientImpl) CreateCVDOp

func (*HostOrchestratorClientImpl) CreateImageDirectory

func (c *HostOrchestratorClientImpl) CreateImageDirectory() (*hoapi.Operation, error)

func (*HostOrchestratorClientImpl) CreateSnapshot

func (c *HostOrchestratorClientImpl) CreateSnapshot(groupName, instanceName string, req *hoapi.CreateSnapshotRequest) (*hoapi.CreateSnapshotResponse, error)

func (*HostOrchestratorClientImpl) DeleteCVD

func (c *HostOrchestratorClientImpl) DeleteCVD(id string) error

func (*HostOrchestratorClientImpl) DeleteImageDirectory

func (c *HostOrchestratorClientImpl) DeleteImageDirectory(id string) (*hoapi.Operation, error)

func (*HostOrchestratorClientImpl) DeleteSnapshot

func (c *HostOrchestratorClientImpl) DeleteSnapshot(id string) error

func (*HostOrchestratorClientImpl) ExtractArtifact

func (c *HostOrchestratorClientImpl) ExtractArtifact(filename string) (*hoapi.Operation, error)

func (*HostOrchestratorClientImpl) FetchArtifacts

func (*HostOrchestratorClientImpl) ListCVDs

func (c *HostOrchestratorClientImpl) ListCVDs() ([]*hoapi.CVD, error)

func (*HostOrchestratorClientImpl) ListImageDirectories

func (*HostOrchestratorClientImpl) Powerbtn

func (c *HostOrchestratorClientImpl) Powerbtn(groupName, instanceName string) error

func (*HostOrchestratorClientImpl) Powerwash

func (c *HostOrchestratorClientImpl) Powerwash(groupName, instanceName string) error

func (*HostOrchestratorClientImpl) Reset

func (c *HostOrchestratorClientImpl) Reset() error

func (*HostOrchestratorClientImpl) Start

func (c *HostOrchestratorClientImpl) Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error

func (*HostOrchestratorClientImpl) Stop

func (c *HostOrchestratorClientImpl) Stop(groupName, instanceName string) error

func (*HostOrchestratorClientImpl) UpdateImageDirectoryWithUserArtifact

func (c *HostOrchestratorClientImpl) UpdateImageDirectoryWithUserArtifact(id, filename string) (*hoapi.Operation, error)

func (*HostOrchestratorClientImpl) UploadArtifact

func (c *HostOrchestratorClientImpl) UploadArtifact(filename string) error

func (*HostOrchestratorClientImpl) WaitForOperation

func (c *HostOrchestratorClientImpl) WaitForOperation(name string, res any) error

type ImageDirectoriesClient

type ImageDirectoriesClient interface {
	// Create an empty image directory.
	CreateImageDirectory() (*hoapi.Operation, error)
	// List all image directories.
	ListImageDirectories() (*hoapi.ListImageDirectoriesResponse, error)
	// Update image directory to include uploaded or extracted user artifact at
	// Host Orchestrator.
	UpdateImageDirectoryWithUserArtifact(id, filename string) (*hoapi.Operation, error)
	// Delete the specified image directory.
	DeleteImageDirectory(id string) (*hoapi.Operation, error)
}

Manage image directories created by the user.

type InstanceConnectionsClient

type InstanceConnectionsClient interface {
	// Creates a webRTC connection to a device running in this host.
	ConnectWebRTC(device string, observer wclient.Observer, logger io.Writer, opts ConnectWebRTCOpts) (*wclient.Connection, error)
	// Connect to ADB WebSocket endpoint.
	ConnectADBWebSocket(device string) (*websocket.Conn, error)
}

Manage direct two-way communication channels with remote instances.

type InstanceOperationsClient

type InstanceOperationsClient interface {
	// Create cvd bugreport.
	CreateBugReport(group string, opts CreateBugReportOpts, dst io.Writer) error
	// Powerwash the device.
	Powerwash(groupName, instanceName string) error
	// Stop the device.
	Stop(groupName, instanceName string) error
	// Press power button.
	Powerbtn(groupName, instanceName string) error
	// Start the device.
	Start(groupName, instanceName string, req *hoapi.StartCVDRequest) error
	// Create device snapshot.
	CreateSnapshot(groupName, instanceName string, req *hoapi.CreateSnapshotRequest) (*hoapi.CreateSnapshotResponse, error)
}

Operations that could be performend on a given instance.

type InstancesClient

type InstancesClient interface {
	// Lists currently running devices.
	ListCVDs() ([]*hoapi.CVD, error)
	// Calls cvd fetch in the remote host, the downloaded artifacts can be used to create a CVD later.
	// If not empty, the provided credentials will be used by the host orchestrator to access the build api.
	FetchArtifacts(req *hoapi.FetchArtifactsRequest, creds BuildAPICreds) (*hoapi.FetchArtifactsResponse, error)
	// Create a new device with artifacts from the build server or previously uploaded by the user.
	// If not empty, the provided credentials will be used to download necessary artifacts from the build api.
	CreateCVD(req *hoapi.CreateCVDRequest, creds BuildAPICreds) (*hoapi.CreateCVDResponse, error)
	CreateCVDOp(req *hoapi.CreateCVDRequest, creds BuildAPICreds) (*hoapi.Operation, error)
	// Deletes an existing cvd instance.
	DeleteCVD(id string) error
	// Forcefully deletes all existing cvd instances and cleans up the host's state.
	Reset() error
}

Manage cuttlefish instances.

type JournalGatewaydClient

type JournalGatewaydClient struct {
	HTTPHelper HTTPHelper
	ProxyURL   string
}

Implementation of `ServiceLogsClient` collecting logs via systemd-journal-gatewayd HTTP API. https://www.freedesktop.org/software/systemd/man/latest/systemd-journal-gatewayd.service.html#Supported%20URLs

func NewJournalGatewaydClient

func NewJournalGatewaydClient(url string) *JournalGatewaydClient

func (*JournalGatewaydClient) PullHOLogs

func (c *JournalGatewaydClient) PullHOLogs(dst io.Writer) error

type OperationsClient

type OperationsClient interface {
	// Wait for an operation, `result` will be populated with the relevant operation's result object.
	WaitForOperation(name string, result any) error
}

Manage the `operation` resource in the HO API used to track lengthy actions.

type RetryOptions

type RetryOptions struct {
	StatusCodes []int
	RetryDelay  time.Duration
	// Keep retrying until the MaxWait threshold is reached out
	MaxWait time.Duration
}

type ServiceLogsClient

type ServiceLogsClient interface {
	PullHOLogs(dst io.Writer) error
}

Gather services logs.

type SnapshotsClient

type SnapshotsClient interface {
	// Create device snapshot.
	DeleteSnapshot(id string) error
}

Manages snapshots.

type StatusCodeError

type StatusCodeError struct {
	Code int
}

func (*StatusCodeError) Error

func (e *StatusCodeError) Error() string

type UploadOptions

type UploadOptions struct {
	BackOffOpts    ExpBackOffOptions
	ChunkSizeBytes int64
	NumWorkers     int
}

func DefaultUploadOptions

func DefaultUploadOptions() UploadOptions

type UserArtifactsClient

type UserArtifactsClient interface {
	// Upload artifact into the artifacts repository.
	// Artifacts are identified by their SHA256 checksum in the artifacts repository
	UploadArtifact(filename string) error
	// Extract artifact into the artifacts repository.
	// Artifacts are identified by their SHA256 checksum in the artifacts repository
	ExtractArtifact(filename string) (*hoapi.Operation, error)
}

Manage artifacts created by the user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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