saya

package
v0.0.0-...-b228686 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

taken from https://github.com/congop/go-virtualbox/blob/master/cmd_arg.go

Index

Constants

View Source
const RepoTypeHttp = "http"
View Source
const RepoTypeS3 = "s3"

Variables

This section is empty.

Functions

func DecodeJsonFile

func DecodeJsonFile[T any](usecaseCtx string, ctx context.Context, jsonFilepath string) (*T, error)

func ImageRm

func ImageRm(ctx context.Context, req ImageDeleteRequest) error

func ImgId

func ImgId(name, version, platform, imgType string) (string, error)

ImgId return an id which can be used to identify a tagged image in a repository. The format is <platform>:<name>:<version>:<imgType> where:

<platform> = os/arch[os-variant] ;

name = the name of the image

version = the version or tag of the image

imgType = the type of the image (e.g. ova, vmdk, img, qcow2, ...)

func IsRepoTypeHttp

func IsRepoTypeHttp(repoType string) bool

func IsRepoTypeS3

func IsRepoTypeS3(repoType string) bool

func StringNotEmpty

func StringNotEmpty(str string) bool

Types

type AuthHttpBasic

type AuthHttpBasic struct {
	Username string
	Pwd      string
}

type AwsCredentials

type AwsCredentials struct {
	// AWS Access key ID
	AccessKeyID string //revive:disable-line:var-naming

	// AWS Secret Access Key
	SecretAccessKey string

	// AWS Session Token
	SessionToken string

	// Source of the credentials
	Source string

	// Time the credentials will expire.
	CanExpire bool
	Expires   *time.Time
}

func (*AwsCredentials) HasExpires

func (cred *AwsCredentials) HasExpires() bool

func (*AwsCredentials) NormalizeToNil

func (cred *AwsCredentials) NormalizeToNil() *AwsCredentials

type CmdArgOpaqueStr

type CmdArgOpaqueStr struct {
	K             string                                   //Args key. e.g. --accelerated
	V             *opaque.String                           // V value. nil if arg does not allow value specification. Note that empty string "" is a valid value, and different from nil.
	ToCmdArgParts func(K string, V opaque.String) []string //
	Del           bool                                     // if true deleted, the arg will not be part of the final command
}

func (*CmdArgOpaqueStr) CmdArgs

func (arg *CmdArgOpaqueStr) CmdArgs() []string

func (*CmdArgOpaqueStr) CmdArgsDisplay

func (arg *CmdArgOpaqueStr) CmdArgsDisplay() []string

func (*CmdArgOpaqueStr) Key

func (arg *CmdArgOpaqueStr) Key() string

func (*CmdArgOpaqueStr) ToDel

func (arg *CmdArgOpaqueStr) ToDel() bool

type CmdArgStr

type CmdArgStr struct {
	K             string                     //Args key. e.g. --accelerated
	V             *string                    // V value. nil if arg does not allow value specification. Note that empty string "" is a valid value, and different from nil.
	ToCmdArgParts func(K, V string) []string //
	Del           bool                       // if true deleted, the arg will not be part of the final command
}

CmdArgStr models a command arg, which can be a flag or not.

func NewCmdArg

func NewCmdArg(k, v string) *CmdArgStr

func NewCmdArgDeleted

func NewCmdArgDeleted(k string) CmdArgStr

func NewCmdArgNoValue

func NewCmdArgNoValue(k string) *CmdArgStr

func (*CmdArgStr) CmdArgs

func (arg *CmdArgStr) CmdArgs() []string

func (*CmdArgStr) CmdArgsDisplay

func (arg *CmdArgStr) CmdArgsDisplay() []string

func (*CmdArgStr) Key

func (arg *CmdArgStr) Key() string

func (*CmdArgStr) ToDel

func (arg *CmdArgStr) ToDel() bool

type CmdArgs

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

func (*CmdArgs) Append

func (cmdArgs *CmdArgs) Append(key, value string)

func (*CmdArgs) AppendCmdArgs

func (cmdArgs *CmdArgs) AppendCmdArgs(arg ...ICmdArg)

func (*CmdArgs) AppendNoValue

func (cmdArgs *CmdArgs) AppendNoValue(key string)

func (*CmdArgs) AppendOverride

func (cmdArgs *CmdArgs) AppendOverride(arg ...ICmdArg)

func (CmdArgs) Args

func (cmdArgs CmdArgs) Args() []string

Args returns an slice containing the args which can be use in a command execution context. Args with multiple occurrence are not supported we will be overriding values.

func (CmdArgs) ArgsDisplay

func (cmdArgs CmdArgs) ArgsDisplay() []string

type CmdImgPull

type CmdImgPull struct {
	SayaCmd
}

func NewCmdImgPull

func NewCmdImgPull(sayaExe string) (*CmdImgPull, error)

NewCmdImgPull create a new image-pull base command to be completed with flags. The base command is <saya-exe> image pull

func (*CmdImgPull) WithRef

func (cmd *CmdImgPull) WithRef(tagName string)

type CmdImgRm

type CmdImgRm struct {
	SayaCmd
}

func NewCmdImgRm

func NewCmdImgRm(sayaExe string, reqSayaCtx RequestSayaCtx) (*CmdImgRm, error)

CmdImgDel create a new image rm base command to be completed with flags. The base command is <saya-exe> image rm

func (*CmdImgRm) WithRef

func (cmd *CmdImgRm) WithRef(tagName string)

type CmdMultiArgStr

type CmdMultiArgStr struct {
	K             string                     //Args key. e.g. --accelerated
	V             []string                   // V value. nil if arg does not allow value specification. Note that empty string "" is a valid value, and different from nil.
	ToCmdArgParts func(K, V string) []string //
	Del           bool                       // if true deleted, the arg will not be part of the final command
}

CmdMultiArgStr models a repeatable command arg

func (*CmdMultiArgStr) CmdArgs

func (arg *CmdMultiArgStr) CmdArgs() []string

func (*CmdMultiArgStr) CmdArgsDisplay

func (arg *CmdMultiArgStr) CmdArgsDisplay() []string

func (*CmdMultiArgStr) Key

func (arg *CmdMultiArgStr) Key() string

func (*CmdMultiArgStr) ToDel

func (arg *CmdMultiArgStr) ToDel() bool

type CmdVmLs

type CmdVmLs struct {
	SayaCmd
}

func NewCmdVmLs

func NewCmdVmLs(id string, reqSayaCtx RequestSayaCtx) (*CmdVmLs, error)

NewCmdVmLs create a saya cmd to list VMs with the given ID. The base command is <saya-exe> vm ls <id-if-not-blank>

type CmdVmRm

type CmdVmRm struct {
	SayaCmd
}

type CmdVmRun

type CmdVmRun struct {
	SayaCmd
}

func NewCmdVmRm

func NewCmdVmRm(id string, reqSayaCtx RequestSayaCtx) (*CmdVmRun, error)

CmdVmRm creates a saya cmd to remove a VM given its ID. The base command is <saya-exe> vm rm <id>

func NewCmdVmRun

func NewCmdVmRun(imgRef string, reqSayaCtx RequestSayaCtx) (*CmdVmRun, error)

CmdVmRun creates a saya cmd to run a VM. The base command is <saya-exe> vm run <img-reference>

type CmdVmStart

type CmdVmStart struct {
	SayaCmd
}

func NewCmdVmStart

func NewCmdVmStart(id string, reqSayaCtx RequestSayaCtx) (*CmdVmStart, error)

CmdVmRun creates a saya cmd to start a VM given its ID. The base command is <saya-exe> vm start <id>

type CmdVmStop

type CmdVmStop struct {
	SayaCmd
}

func NewCmdVmStop

func NewCmdVmStop(id string, reqSayaCtx RequestSayaCtx) (*CmdVmStop, error)

CmdVmStop creates a saya cmd to stop a VM given its ID. The base command is <saya-exe> vm stop <id>

type ExecOutcome

type ExecOutcome struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type HttpRepo

type HttpRepo struct {
	RepoUrl        string
	BasePath       string
	UploadStrategy string
	AuthHttpBasic  AuthHttpBasic
}

func (*HttpRepo) NormalizeToNil

func (repo *HttpRepo) NormalizeToNil() *HttpRepo

type ICmdArg

type ICmdArg interface {
	Key() string
	ToDel() bool
	CmdArgs() []string
	CmdArgsDisplay() []string
}

type ImageDeleteRequest

type ImageDeleteRequest struct {
	Name     string
	ImgType  string
	Platform string

	RequestSayaCtx
}

type ImageTagMetaData

type ImageTagMetaData struct {
	Name      string            `yaml:"name" json:"name"`
	Version   string            `yaml:"version" json:"version"`
	Sha256    string            `yaml:"sha256" json:"sha256"`
	Type      string            `yaml:"type" json:"type"` // the image type e.g. ova, vhd, vmdk, iso. img, ...
	Platform  PlatformSw        `yaml:"platform" json:"platform"`
	CreatedAt time.Time         `yaml:"created_at" json:"created_at"`
	Labels    map[string]string `yaml:"labels" json:"labels"`
	SrcType   string            `yaml:"src_type,omitempty" json:"src_type,omitempty"` // build | convert | tag | http | s3
}

func ImageTagMetaDataFromJsonFile

func ImageTagMetaDataFromJsonFile(ctx context.Context, jsonFilepath string) (*ImageTagMetaData, error)

func ImageTagMetaDataListFromJsonFile

func ImageTagMetaDataListFromJsonFile(ctx context.Context, jsonFilepath string) ([]ImageTagMetaData, error)

type LsCmdRes

type LsCmdRes struct {
	Name      string `json:"name"`
	Version   string `json:"tag"`
	Sha256    string `json:"id"`
	Type      string `json:"img_type"` // the image type e.g. ova, vhd, vmdk, iso. img, ...
	Platform  string `json:"platform"`
	OsVariant string
	CreatedAt time.Time         `json:"created_at"`
	Labels    map[string]string `json:"labels"`

	SrcType string `json:"src_type,omitempty"` // build | convert | tag | http | s3
}

LsCmdRes model image in the forge returned as result of saya image ls command. e.g. [{"Created":"2023-07-03T08:45:36.599939836+02:00", "Id":"c87c9fac305744a229103177230db4192bdb6d4547c416ed32fc6bac9971befb", "ImgType":"qcow2","Name":"testeearm","OsVar":"alpine", "Platform":"linux/arm64","Size":1074135040,"Tag":"latest"}]

type LsRequest

type LsRequest struct {
	Name      string
	ImgType   string
	Platform  string
	OsVariant string
	Sha256    string

	RequestSayaCtx
}

type LsResult

type LsResult struct {
	Name     string
	Version  string
	Sha256   string
	Type     string // the image type e.g. ova, vhd, vmdk, iso. img, ...
	Platform PlatformSw
	SrcType  string
}

func Ls

func Ls(ctx context.Context, req LsRequest) ([]LsResult, error)

func (LsResult) PlatformNameVersionTypeTaglike

func (res LsResult) PlatformNameVersionTypeTaglike() string

type ParsedImgId

type ParsedImgId struct {
	P       Platform
	R       Reference
	ImgType string
}

func ParseImgId

func ParseImgId(str string) (*ParsedImgId, error)

type Platform

type Platform struct {
	Os          string `json:"os,omitempty"`
	Arch        string `json:"arch,omitempty"`
	ArchVariant string `json:"arch_variant,omitempty"`
}

func PlatformNormalized

func PlatformNormalized(
	platformStr string,
) (*Platform, error)

PlatformNormalized return a normalized form of the specified platform string. It defaults to the current host platform, if passed platform string is blank.

func (Platform) ArchWithVariant

func (platform Platform) ArchWithVariant() string

func (Platform) PlatformSegmentParts

func (platform Platform) PlatformSegmentParts() []string

func (Platform) PlatformStr

func (platform Platform) PlatformStr() string

PlatformSegment returns a / separated str representation os[/arch[/arch-variant]].

e.g linux/amd64, linux/arm64, linux/arm/v7

type PlatformSw

type PlatformSw struct {
	Platform

	OsVariant string `json:"os_variant,omitempty"`
}

PlatformSw is a platform which knows the os variant. It is more software oriented because the os-variant hints at what kind of software natively belongs. e.g. apt for ubuntu but rpm for redhat

type PullRequest

type PullRequest struct {
	Name     string
	ImgType  string
	Platform string
	Hash     string
	RepoType string
	HttpRepo *HttpRepo
	S3Repo   *S3Repo

	Exe        string        // saya executable command or path
	Config     string        // saya executable command or path
	Forge      string        // forge(local image store) location
	LicenseKey opaque.String // License key
	LogLevel   string        // log level error|warn|info|debug|trace
}

type PullResult

type PullResult struct {
	Name     string
	Version  string
	Sha256   string
	Type     string // the image type e.g. ova, vhd, vmdk, iso. img, ...
	Platform PlatformSw
	SrcType  string // type of the repo used to fetch the image; e.g. http, s3
}

func Pull

func Pull(ctx context.Context, req PullRequest) (*PullResult, error)

type Reference

type Reference struct {
	Original string // the original reference value, e.g. ubuntu:latest.
	Name     string // name
	Version  string // Normalized i.e.  latest if None was given
}

func ParseReference

func ParseReference(ref string) (*Reference, error)

func ReferenceFromNameAndVersion

func ReferenceFromNameAndVersion(name, version string) Reference

func (Reference) Normalized

func (ref Reference) Normalized() string

type Repos

type Repos struct {
	Http *HttpRepo
	S3   *S3Repo
}

func (*Repos) AvailableRepoTypes

func (repo *Repos) AvailableRepoTypes() []string

func (*Repos) ExactlyOneRepoSpecified

func (repo *Repos) ExactlyOneRepoSpecified() bool

func (*Repos) HttpOnly

func (repo *Repos) HttpOnly() bool

HttpOnly return true if only the http repo is specified, false otherwise

func (*Repos) S3Only

func (repo *Repos) S3Only() bool

S3Only return true if only the S3 repo is specified; false otherwise.

type RequestSayaCtx

type RequestSayaCtx struct {
	Exe        string        // saya executable command or path
	Config     string        // saya executable command or path
	Forge      string        // forge(local image store) location
	LicenseKey opaque.String // License key
	LogLevel   string        // log level error|warn|info|debug|trace

}

type S3Repo

type S3Repo struct {
	Bucket  string
	BaseKey string
	EpUrl   string
	EpUrlS3 string
	Region  string // aws region to send request to

	AuthAwsCreds *AwsCredentials
	UsePathStyle bool
}

func (*S3Repo) NormalizeToNil

func (repo *S3Repo) NormalizeToNil() *S3Repo

type SayaCmd

type SayaCmd struct {
	Args                 CmdArgs
	ArgsValidationErrors []error
	// contains filtered or unexported fields
}

func (SayaCmd) Exec

func (sayaCmd SayaCmd) Exec(ctx context.Context) (ExecOutcome, error)

func (*SayaCmd) WithCfgFile

func (sayaCmd *SayaCmd) WithCfgFile(cfg string)

func (*SayaCmd) WithForgeLocation

func (sayaCmd *SayaCmd) WithForgeLocation(forgeLocation string)

func (*SayaCmd) WithLicenseKey

func (sayaCmd *SayaCmd) WithLicenseKey(lk opaque.String)

func (*SayaCmd) WithLogLevel

func (sayaCmd *SayaCmd) WithLogLevel(logLevel string)

func (*SayaCmd) WithRequestSayaCtx

func (sayaCmd *SayaCmd) WithRequestSayaCtx(req RequestSayaCtx)

type SayaCmdLs

type SayaCmdLs struct {
	SayaCmd
}

func NewCmdImgLs

func NewCmdImgLs(sayaExe string, reqSayaCtx RequestSayaCtx) (*SayaCmdLs, error)

NewSayaCmdLs create a new image ls base command to be completed with flags. The base command is <saya-exe> image ls

func (*SayaCmdLs) WithRef

func (cmd *SayaCmdLs) WithRef(tagName string)

type VmLsRequest

type VmLsRequest struct {
	RequestSayaCtx

	Id          string
	Name        string
	ImgRef      string
	ComputeType string
	OsVariant   string
	State       string
}

type VmLsResult

type VmLsResult struct {
	Id          string
	Name        string
	Arch        string
	Os          string
	OsVariant   string
	BaseImg     string // format: webserver:v1:ova
	ComputeType string
	State       string
}

func VmLs

func VmLs(ctx context.Context, req VmLsRequest) ([]VmLsResult, error)

func (*VmLsResult) ImgId

func (res *VmLsResult) ImgId() string

func (*VmLsResult) LabelNameAndId

func (res *VmLsResult) LabelNameAndId() string

func (*VmLsResult) Platform

func (res *VmLsResult) Platform() string

type VmLsResultCmd

type VmLsResultCmd struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Arch        string `json:"arch"`
	Os          string `json:"os"`
	OsVariant   string `json:"os_variant"`
	BaseImg     string `json:"base_img"` // format: webserver:v1:ova
	ComputeType string `json:"compute_type"`
	Status      string `json:"status"`
}

func (*VmLsResultCmd) ToVmLsResult

func (resJson *VmLsResultCmd) ToVmLsResult() VmLsResult

type VmRmRequest

type VmRmRequest struct {
	Id   string
	Name string

	RequestSayaCtx
}

type VmRmResult

type VmRmResult struct {
	Id string
}

func VmRm

func VmRm(ctx context.Context, req VmRmRequest) (*VmRmResult, error)

type VmRunRequest

type VmRunRequest struct {
	RequestSayaCtx

	Name        string
	ImgRef      string
	ComputeType string
	Platform    string
	ImgType     string
}

type VmRunResult

type VmRunResult struct {
	Id        string
	Name      string
	OsVariant string
	Ssh       struct {
		Ip                  string
		Port                uint16
		User                string
		CreatedPwdFile      string
		CreatedIdentityFile string
	}
}

func VmRun

func VmRun(ctx context.Context, req VmRunRequest) (*VmRunResult, error)

type VmRunResultCmd

type VmRunResultCmd struct {
	Id        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	OsVariant string `json:"os_variant,omitempty"`

	Ssh *VmRunResultCmdSsh `json:"ssh,omitempty"`
}

{"id":"81e4b6cf-ad66-409d-8a78-429b7499093e","name":"saya-2023-08-04T20-39-47Z-999d5a49cbbf","ssh":{"ip":"192.168.56.253","port":22,"user":"root"}}

func (*VmRunResultCmd) ToVmRunResultCmd

func (cmdRes *VmRunResultCmd) ToVmRunResultCmd() VmRunResult

type VmRunResultCmdSsh

type VmRunResultCmdSsh struct {
	Ip                  string `json:"ip,omitempty"`
	Port                uint16 `json:"port,omitempty"`
	User                string `json:"user,omitempty"`
	CreatedPwdFile      string `json:"created_pwd_file,omitempty"`
	CreatedIdentityFile string `json:"created_identity_file,omitempty"`
}

type VmStartRequest

type VmStartRequest struct {
	Id string

	RequestSayaCtx
}

type VmStartResult

type VmStartResult struct {
	Id string
}

func VmStart

func VmStart(ctx context.Context, req VmStartRequest) (*VmStartResult, error)

type VmStopRequest

type VmStopRequest struct {
	Id string

	RequestSayaCtx
}

type VmStopResult

type VmStopResult struct {
	Id string
}

func VmStop

func VmStop(ctx context.Context, req VmStopRequest) (*VmStopResult, error)

Jump to

Keyboard shortcuts

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