Documentation
¶
Index ¶
- Constants
- Variables
- func AddMounts(mounts []string, config *types.Config) error
- func Apply(update io.Reader, opts Options) error
- func BaseHTTPRequest(method string, url string, body io.Reader) (*http.Request, error)
- func BuildImage(c types.Config) error
- func BuildImageFromPackage(packagepath string, c types.Config) error
- func BuildManifest(c *types.Config) (*fs.Manifest, error)
- func BuildPackageManifest(packagepath string, c *types.Config) (*fs.Manifest, error)
- func BuildRequestForArchiveUpload(namespace, name string, pkg Package, archiveLocation string, private bool) (*http.Request, error)
- func Bytes2Human(b int64) string
- func CCidr(netmask string) int
- func CheckNanosVersionExists(version string) (bool, error)
- func ClonePackage(old string, newPkg string, version string, oldconfig *types.Config, ...)
- func CreateArchive(archive string, files []string) error
- func CreateDNSRecord(config *types.Config, aRecordIP string, dnsService DNSService) error
- func CreatePackageFromRun(newPkg string, version string, mergedCfg *types.Config)
- func CreateTarGz(src string, destination string) error
- func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
- func DoUpdate(url string) error
- func DownloadCommonFiles() error
- func DownloadFile(fpath string, url string, timeout int, showProgress bool) error
- func DownloadFileWithProgress(filepath string, url string, timeout int) error
- func DownloadNightlyImages(c *types.Config) error
- func DownloadPackage(identifier string, config *types.Config) (string, error)
- func DownloadReleaseImages(version string, arch string) error
- func ErrInstanceNotFound(name string) error
- func ExtractNS(identifier string) (string, string)
- func ExtractPackage(archive, dest string, config *types.Config)
- func GenerateImageName(program string) string
- func GetElfFileInfo(path string) (*elf.File, error)
- func GetLocalUsername() string
- func GetNSPkgnameAndVersion(pkgIdentifier string) (string, string, string)
- func GetOpsHome() string
- func GetPackageManifestFile() string
- func GetSizeInGb(size string) (int, error)
- func GetUefiBoot(version string) string
- func HasDebuggingSymbols(efd *elf.File) bool
- func HomeDir() (string, error)
- func IsDynamicLinked(efd *elf.File) bool
- func IsInstanceNotFoundError(err error) bool
- func LocalTimeStamp() (string, error)
- func NewConfig() *types.Config
- func NightlyLocalFolder() string
- func NightlyReleaseURL() string
- func PackageManifestChanged(fino os.FileInfo, remoteURL string) bool
- func PrintVolumesList(volumes *[]NanosVolume)
- func RAMInBytes(size string) (int64, error)
- func RelTime(a, b time.Time, albl, blbl string) string
- func RemoteTimeStamp() (string, error)
- func RollbackError(err error) error
- func SliceAtoi(sa []string) ([]int, error)
- func StoreCredentials(creds Credentials) error
- func Time2Human(then time.Time) string
- func UpdateLocalRelease(version string) error
- func ValidateELF(executablePath string)
- type APIMetadataRequest
- type CloudImage
- type CloudInstance
- type Context
- type Credentials
- type DNSRecord
- type DNSService
- type JSONStore
- type Mirrorer
- type NanosVolume
- type Options
- type Package
- type PackageIdentifier
- type PackageList
- type Provider
- type RelTimeMagnitude
- type Storage
- type ValidateSuccessResponse
- type VolumeService
- type WriteCounter
Constants ¶
const ( Day = 24 * time.Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month LongTime = 37 * Year KB = 1000 MB = 1000 * KB GB = 1000 * MB TB = 1000 * GB PB = 1000 * TB KiB = 1024 MiB = 1024 * KiB GiB = 1024 * MiB TiB = 1024 * GiB PiB = 1024 * TiB )
Seconds-based time units
const ( // DefaultVolumeLabel is the default label of a volume created with mkfs DefaultVolumeLabel = "default" // VolumeDelimiter is the reserved character used as delimiter between // volume name and uuid/label VolumeDelimiter = ":" )
const APIKeyHeader = "x-api-key"
APIKeyHeader is the header key where we set the api key for packagehub
const CredentialFileName = "credentials"
CredentialFileName is the name of the file which stores packagehub's credentials
const OpsReleaseURL = "https://storage.googleapis.com/cli/%v/ops"
OpsReleaseURL gives URL to download latest ops binary
const PackageBaseURL string = PkghubBaseURL + "/v2/packages"
PackageBaseURL gives URL for downloading of packages
const PackageManifestFileName string = "manifest.json"
PackageManifestFileName is manifest file path
const PackageManifestURL string = PkghubBaseURL + "/v2/manifest.json"
PackageManifestURL stores info about all packages
const PackageSysRootFolderName = "sysroot"
PackageSysRootFolderName is the name of package root folder
const PkghubBaseURL string = "https://repo.ops.city"
PkghubBaseURL is the base url of packagehub
Variables ¶
var AltGOARCH = ""
AltGOARCH is an optional user-supplied cross-build arch for both build and run.
var ErrCredentialsNotExist = errors.New("credentials not exist")
ErrCredentialsNotExist is the error we return if the credential file doesn't exist
var ( // ErrVolumeNotFound is error returned when a volume with a given id does not exist ErrVolumeNotFound = func(id string) error { return errors.Errorf("volume with UUID %s not found", id) } )
var LatestReleaseVersion = getLatestRelVersion()
LatestReleaseVersion give latest stable release for nanos
var LocalImageDir = path.Join(GetOpsHome(), "images")
LocalImageDir is the directory where ops save images
var LocalReleaseVersion = getLocalRelVersion()
LocalReleaseVersion is version latest release downloaded in ops home
var ( // LocalVolumeDir is the default local volume directory LocalVolumeDir = path.Join(GetOpsHome(), "volumes") )
var NightlyLocalFolderm = NightlyLocalFolder()
NightlyLocalFolderm is directory path where nightly builds are stored
var NightlyReleaseURLm = NightlyReleaseURL()
NightlyReleaseURLm give URL for nightly build.
var PackagesCache = getPackageCache()
PackagesCache where all packages are stored
var RealGOARCH = getGOARCH()
RealGOARCH is the underlying host architecture.
var (
// TTLDefault is the default ttl value used to create DNS records
TTLDefault = 300
)
var Version string
Version for ops
Functions ¶
func Apply ¶
Apply performs an update of the current executable (or opts.TargetFile, if set) with the contents of the given io.Reader.
Apply performs the following actions to ensure a safe cross-platform update:
1. If configured, applies the contents of the update io.Reader as a binary patch.
2. If configured, computes the checksum of the new executable and verifies it matches.
3. If configured, verifies the signature with a public key.
4. Creates a new file, /path/to/.target.new with the TargetMode with the contents of the updated file
5. Renames /path/to/target to /path/to/.target.old
6. Renames /path/to/.target.new to /path/to/target
7. If the final rename is successful, deletes /path/to/.target.old, returns no error. On Windows, the removal of /path/to/target.old always fails, so instead Apply hides the old file instead.
8. If the final rename fails, attempts to roll back by renaming /path/to/.target.old back to /path/to/target.
func BaseHTTPRequest ¶
BaseHTTPRequest is a wrapper around http.NewRequest with a header that holds the ops version.
func BuildImage ¶
BuildImage builds a unikernel image for user supplied ELF binary.
func BuildImageFromPackage ¶
BuildImageFromPackage builds nanos image using a package
func BuildManifest ¶
BuildManifest builds manifest using config
func BuildPackageManifest ¶
BuildPackageManifest builds manifest using package
func BuildRequestForArchiveUpload ¶
func BuildRequestForArchiveUpload(namespace, name string, pkg Package, archiveLocation string, private bool) (*http.Request, error)
BuildRequestForArchiveUpload builds the request to upload a package with the provided metadata
func Bytes2Human ¶
Bytes2Human parses bytes to other byte units as MegaByte and Gigabyte.
func CheckNanosVersionExists ¶
CheckNanosVersionExists verifies whether version exists in filesystem
func ClonePackage ¶
func ClonePackage(old string, newPkg string, version string, oldconfig *types.Config, newconfig *types.Config)
ClonePackage will cloned a package from ~/.ops/packages to ~/.ops/local_packages.
func CreateArchive ¶
CreateArchive compress files into an archive
func CreateDNSRecord ¶
func CreateDNSRecord(config *types.Config, aRecordIP string, dnsService DNSService) error
CreateDNSRecord does the necessary operations to create a DNS record without issues in an cloud provider
func CreatePackageFromRun ¶
CreatePackageFromRun builds a new package as if you were doing an 'ops run myprogram'
func CreateTarGz ¶
CreateTarGz builds a .tar.gz archive with the directory of the source as the root of the archive
func CustomRelTime ¶
func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
CustomRelTime formats a time into a relative string.
It takes two times two labels and a table of relative time formats. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
func DownloadCommonFiles ¶
func DownloadCommonFiles() error
DownloadCommonFiles dowloads common tarball files and extract them to common directory
func DownloadFile ¶
DownloadFile downloads file using URL
func DownloadFileWithProgress ¶
DownloadFileWithProgress downloads file using URL displaying progress counter
func DownloadNightlyImages ¶
DownloadNightlyImages downloads nightly build for nanos
func DownloadPackage ¶
DownloadPackage downloads package by identifier
func DownloadReleaseImages ¶
DownloadReleaseImages downloads nanos for particular release version arch defaults to x86-64 if empty
func ErrInstanceNotFound ¶
ErrInstanceNotFound creates new error stating instance with given name cannot be found
func ExtractNS ¶
ExtractNS extracts namespace from the package identifier of format <namespace>/<packageWithVersion> and returns the namespace and package with version
func ExtractPackage ¶
ExtractPackage extracts package in ops home. This function is currently over-loaded.
func GenerateImageName ¶
GenerateImageName generate image name
func GetElfFileInfo ¶
GetElfFileInfo returns an object with elf information of the path program
func GetLocalUsername ¶
func GetLocalUsername() string
GetLocalUsername gets the local username and return "" if not found
func GetNSPkgnameAndVersion ¶
GetNSPkgnameAndVersion gets the namespace, name and version from the pkg identifier
func GetOpsHome ¶
func GetOpsHome() string
GetOpsHome get ops directory path We store all ops related info, packages, images in this directory
func GetPackageManifestFile ¶
func GetPackageManifestFile() string
GetPackageManifestFile give path for package manifest file
func GetSizeInGb ¶
GetSizeInGb converts a string representation of a volume size to an integer number of GB
func GetUefiBoot ¶
GetUefiBoot retrieves UEFI bootloader file path, if found
func HasDebuggingSymbols ¶
HasDebuggingSymbols checks whether elf file has debugging symbols
func HomeDir ¶
HomeDir returns the home directory for the executing user. This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.
func IsDynamicLinked ¶
IsDynamicLinked checks whether elf file was linked dynamically
func IsInstanceNotFoundError ¶
IsInstanceNotFoundError checks if given error is an ErrInstanceNotFound
func LocalTimeStamp ¶
LocalTimeStamp gives local timestamp from download nightly build
func NightlyLocalFolder ¶
func NightlyLocalFolder() string
NightlyLocalFolder points to the latest nightly release url that is arch dependent upon flag set.
func NightlyReleaseURL ¶
func NightlyReleaseURL() string
NightlyReleaseURL points to the latest nightly release url that is arch dependent upon flag set.
func PackageManifestChanged ¶
PackageManifestChanged verifies if package manifest changed
func PrintVolumesList ¶
func PrintVolumesList(volumes *[]NanosVolume)
PrintVolumesList writes into console a table with volumes details
func RAMInBytes ¶
RAMInBytes parses a human-readable string representing an amount of RAM in bytes, kibibytes, mebibytes, gibibytes, or tebibytes and returns the number of bytes, or -1 if the string is unparseable. Units are case-insensitive, and the 'b' suffix is optional.
func RelTime ¶
RelTime formats a time into a relative string.
It takes two times and two labels. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"
func RemoteTimeStamp ¶
RemoteTimeStamp gives latest nightly build timestamp
func RollbackError ¶
RollbackError takes an error value returned by Apply and returns the error, if any, that occurred when attempting to roll back from a failed update. Applications should always call this function on any non-nil errors returned by Apply.
If no rollback was needed or if the rollback was successful, RollbackError returns nil, otherwise it returns the error encountered when trying to roll back.
func StoreCredentials ¶
func StoreCredentials(creds Credentials) error
StoreCredentials stores the credentials in the credential file. Overrides it if there is an existing one.
func Time2Human ¶
Time2Human formats a time into a relative string. Time(someT) -> "3 weeks ago"
func UpdateLocalRelease ¶
UpdateLocalRelease updates nanos version used on ops operations
func ValidateELF ¶
func ValidateELF(executablePath string)
ValidateELF validates ELF executable format given the file path
Types ¶
type APIMetadataRequest ¶
type APIMetadataRequest struct { Namespace string `json:"namespace"` PkgName string `json:"pkg_name"` Version string `json:"version"` Arch string `json:"arch"` }
APIMetadataRequest is payload sent to get metadata for a package
type CloudImage ¶
type CloudImage struct { ID string Name string Status string Size int64 Path string Created time.Time Tag string // could merge w/below Labels []string }
CloudImage abstracts images for various cloud providers
type CloudInstance ¶
type CloudInstance struct { ID string Name string Status string Created string // TODO: prob. should be datetime w/helpers for human formatting PrivateIps []string PublicIps []string Ports []string Image string }
CloudInstance represents the instance that widely use in different Cloud Providers. mainly used for formatting standard response from any cloud provider
func (CloudInstance) MarshalJSON ¶
func (c CloudInstance) MarshalJSON() ([]byte, error)
MarshalJSON ensures correct json serialization of potential null vals.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context captures required info for provider operation
func NewContext ¶
NewContext Create a new context for the given provider valid providers are "gcp", "aws" and "onprem"
type Credentials ¶
Credentials is the information that will be stored in the ~/.ops/credentials
func ReadCredsFromLocal ¶
func ReadCredsFromLocal() (*Credentials, error)
ReadCredsFromLocal gets the credentials from the credential file in the ops home returns an ErrCredentialsNotExist if the file doesn't exist. This means the user hasn't authenticated yet.
type DNSService ¶
type DNSService interface { FindOrCreateZoneIDByName(config *types.Config, name string) (string, error) DeleteZoneRecordIfExists(config *types.Config, zoneID string, recordName string) error CreateZoneRecord(config *types.Config, zoneID string, record *DNSRecord) error }
DNSService is an interface for DNS related operations
type JSONStore ¶
type JSONStore struct {
// contains filtered or unexported fields
}
JSONStore implements volumeStore TODO probably use a more established KV-store
func (*JSONStore) Delete ¶
func (s *JSONStore) Delete(id string) (NanosVolume, error)
Delete deletes volume of a given UUID
func (*JSONStore) Get ¶
func (s *JSONStore) Get(id string) (NanosVolume, error)
Get gets volume data of a given UUID
func (*JSONStore) GetAll ¶
func (s *JSONStore) GetAll() ([]NanosVolume, error)
GetAll gets all volume data
func (*JSONStore) Insert ¶
func (s *JSONStore) Insert(vol NanosVolume) error
Insert inserts volume data
func (*JSONStore) Update ¶
func (s *JSONStore) Update(v NanosVolume) error
Update updates a given volume
type Mirrorer ¶
type Mirrorer interface {
MirrorImage(ctx *Context, imageName, srcRegion, dstRegion string) (string, error)
}
Mirrorer is an interface that all provider which provider feature to copy an image from one region to another
type NanosVolume ¶
type NanosVolume struct { ID string `json:"id"` Name string `json:"name"` Label string `json:"label"` Data string `json:"data"` Size string `json:"size"` // this has extra meta in it that should be converted to just bytes Path string `json:"path"` AttachedTo string `json:"attached_to"` CreatedAt string `json:"created_at"` Status string `json:"status"` }
NanosVolume information for nanos-managed volume
func CreateLocalVolume ¶
func CreateLocalVolume(config *types.Config, name, data, provider string) (NanosVolume, error)
CreateLocalVolume creates volume on ops directory creates a volume named <name>:<uuid> where <uuid> is generated on creation also creates a symlink to volume label at <name> TODO investigate symlinked volume interaction with image
func (NanosVolume) MatchedByQueries ¶
func (v NanosVolume) MatchedByQueries(query map[string]string) bool
MatchedByQueries returns true if this volume matched one or more given query.
type Options ¶
type Options struct { // TargetPath defines the path to the file to update. // The empty string means 'the executable file of the running program'. TargetPath string // Create TargetPath replacement with this file mode. If zero, defaults to 0755. TargetMode os.FileMode // Checksum of the new binary to verify against. If nil, no checksum or signature verification is done. Checksum []byte // Public key to use for signature verification. If nil, no signature verification is done. PublicKey crypto.PublicKey // Signature to verify the updated file. If nil, no signature verification is done. Signature []byte // Use this hash function to generate the checksum. If not set, SHA256 is used. Hash crypto.Hash // Store the old executable file at this path after a successful update. // The empty string means the old executable file will be removed after the update. OldSavePath string }
Options for binary update
func (*Options) CheckPermissions ¶
CheckPermissions determines whether the process has the correct permissions to perform the requested update. If the update can proceed, it returns nil, otherwise it returns the error that would occur if an update were attempted.
func (*Options) SetPublicKeyPEM ¶
SetPublicKeyPEM is a convenience method to set the PublicKey property used for checking a completed update's signature by parsing a Public Key formatted as PEM data.
type Package ¶
type Package struct { Runtime string `json:"runtime"` Version string `json:"version"` Language string `json:"language"` Description string `json:"description,omitempty"` SHA256 string `json:"sha256"` Name string `json:"name"` Namespace string `json:"namespace"` Arch string `json:"arch"` }
Package is the definition of an OPS package.
func GetLocalPackageList ¶
GetLocalPackageList provides list of local packages
func GetPackageMetadata ¶
GetPackageMetadata get metadata for the package
type PackageIdentifier ¶
type PackageIdentifier struct { Name string `json:"name"` Namespace string `json:"namespace"` Version string `json:"version"` }
PackageIdentifier is used to identify a namespaced package
func ParseIdentifier ¶
func ParseIdentifier(identifier string) PackageIdentifier
ParseIdentifier parses a package identifier which looks like <namespace>/<pkg>:<version>
func (*PackageIdentifier) Match ¶
func (pkgidf *PackageIdentifier) Match(pkg Package) bool
Match matches a package with all the fields of this identifier
type PackageList ¶
PackageList contains a list of known packages.
func GetPackageList ¶
func GetPackageList(config *types.Config) (*PackageList, error)
GetPackageList provides list of packages
func SearchPackages ¶
func SearchPackages(q string) (*PackageList, error)
SearchPackages searches packages against pkghub
func (*PackageList) List ¶
func (pkglist *PackageList) List() []Package
List returns the package list
type Provider ¶
type Provider interface { Initialize(config *types.ProviderConfig) error BuildImage(ctx *Context) (string, error) BuildImageWithPackage(ctx *Context, pkgpath string) (string, error) CreateImage(ctx *Context, imagePath string) error ListImages(ctx *Context) error GetImages(ctx *Context) ([]CloudImage, error) DeleteImage(ctx *Context, imagename string) error ResizeImage(ctx *Context, imagename string, hbytes string) error SyncImage(config *types.Config, target Provider, imagename string) error CustomizeImage(ctx *Context) (string, error) CreateInstance(ctx *Context) error ListInstances(ctx *Context) error GetInstances(ctx *Context) ([]CloudInstance, error) GetInstanceByName(ctx *Context, name string) (*CloudInstance, error) DeleteInstance(ctx *Context, instancename string) error StopInstance(ctx *Context, instancename string) error StartInstance(ctx *Context, instancename string) error RebootInstance(ctx *Context, instancename string) error GetInstanceLogs(ctx *Context, instancename string) (string, error) PrintInstanceLogs(ctx *Context, instancename string, watch bool) error VolumeService }
Provider is an interface that provider must implement
type RelTimeMagnitude ¶
A RelTimeMagnitude struct contains a relative time point at which the relative format of time will switch to a new format string. A slice of these in ascending order by their "D" field is passed to CustomRelTime to format durations.
The Format field is a string that may contain a "%s" which will be replaced with the appropriate signed label (e.g. "ago" or "from now") and a "%d" that will be replaced by the quantity.
The DivBy field is the amount of time the time difference must be divided by in order to display correctly.
e.g. if D is 2*time.Minute and you want to display "%d minutes %s" DivBy should be time.Minute so whatever the duration is will be expressed in minutes.
type ValidateSuccessResponse ¶
type ValidateSuccessResponse struct {
Username string
}
ValidateSuccessResponse is the structure of the success response from validate api key endpoint
func ValidateAPIKey ¶
func ValidateAPIKey(apikey string) (*ValidateSuccessResponse, error)
ValidateAPIKey uses the api key provided and sends it to validate endpoint of packagehub if the response is a valid user then we return that or else error is returned.
type VolumeService ¶
type VolumeService interface { CreateVolume(ctx *Context, volumeName, data, provider string) (NanosVolume, error) GetAllVolumes(ctx *Context) (*[]NanosVolume, error) DeleteVolume(ctx *Context, volumeName string) error AttachVolume(ctx *Context, instanceName, volumeName string, attachID int) error DetachVolume(ctx *Context, instanceName, volumeName string) error }
VolumeService is an interface for volume related operations
type WriteCounter ¶
type WriteCounter struct {
// contains filtered or unexported fields
}
WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface and we can pass this into io.TeeReader() which will report progress on each write cycle.
func NewWriteCounter ¶
func NewWriteCounter(total int) *WriteCounter
NewWriteCounter creates new write counter