metaservice

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package metaservice implements the meta-data service that the guests use to talk to the host.

The meta-data service is exposed to the guest on 169.254.169.254:80. This is how the command and environment variables enter the virtual machine. It is also the services that the guest uses to report logs and final result.

Index

Constants

View Source
const (
	ErrorCodeMethodNotAllowed = "MethodNotAllowed"
	ErrorCodeNoSuchEndPoint   = "NoSuchEndPoint"
	ErrorCodeInternalError    = "InternalError"
	ErrorCodeResourceConflict = "ResourceConflict"
	ErrorCodeUnknownActionID  = "UnknownActionId"
	ErrorCodeInvalidPayload   = "InvalidPayload"
)

List of API error codes for using the Error struct.

View Source
const PollTimeout = 30 * time.Second

PollTimeout is the maximum amount of time a poll request will be left hanging before getting a response (even if the response is none).

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	ID      string   `json:"id"`      // id, to be used when replying
	Type    string   `json:"type"`    // none, get-artifact, list-folder, exec-shell, kill-process
	Path    string   `json:"path"`    // file path, if get-artifact/list-folder
	Command []string `json:"command"` // Command for exec-shell
	TTY     bool     `json:"tty"`     // TTY or not for exec-shell
}

Action is the response payload for the /engine/v1/poll end-point.

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Error is the response payload for any error senario.

type Execute

type Execute struct {
	Env     map[string]string `json:"env"`
	Command []string          `json:"command"`
}

Execute is the response payload for the /engine/v1/execute end-point.

type Files

type Files struct {
	Files    []string `json:"files"`    // List of absolute file paths
	NotFound bool     `json:"notFound"` // true, if path doesn't exist
}

Files is the request payload for the /engine/v1/list-folder end-point.

type MetaService

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

MetaService implements the meta-data service that communicates worker process running inside the virtual machine. This is how the command to run gets into the virtual machine, and how logs and artifacts are copied out.

func New

func New(
	command []string, env map[string]string, logDrain io.Writer,
	resultCallback func(bool), environment *runtime.Environment,
) *MetaService

New returns a new MetaService that will tell the virtual machine to run command, with environment variables env. It will write the logs to logDrain.

The callback resultCallback will be called when the guest reports that the command is done.

func (*MetaService) ExecShell

func (s *MetaService) ExecShell(command []string, tty bool) (engines.Shell, error)

ExecShell will send an action to guest-tools to execute a shell, then wait for guest-tools to callback establish a websocket and connect to an implementation of engines.Shell

func (*MetaService) GetArtifact

func (s *MetaService) GetArtifact(path string) (ioext.ReadSeekCloser, error)

GetArtifact will tell polling guest-tools to send a given artifact.

func (*MetaService) KillProcess added in v0.1.0

func (s *MetaService) KillProcess() error

KillProcess will send an action to guest-tools to kill the process executing the main command.

Note: For robustness this shouldn't be relied upon.

func (*MetaService) ListFolder

func (s *MetaService) ListFolder(path string) ([]string, error)

ListFolder the contents of a folder (recursively)

func (*MetaService) ServeHTTP

func (s *MetaService) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles request to the meta-data service.

func (*MetaService) StopPollers

func (s *MetaService) StopPollers()

StopPollers will stop all polling requests. This is only used for testing, where it is important that clients stop polling or we can't Close the server.

Jump to

Keyboard shortcuts

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