snapshot

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package snapshot documents the request and response payloads related to the snapshot daemon.

Index

Constants

View Source
const CatCompress = "cat"

CatCompress is to support the legacy 'no compression' option

View Source
const PathPrefix = "snapper"

PathPrefix is the root path for API endpoint.

Variables

This section is empty.

Functions

func Day

func Day(day int) func(*Schedule)

Day is an option setting function for the Schedule constructor. It sets the day used by a Monthly snapshot.

func DestinationStrings

func DestinationStrings() []string

DestinationStrings returns a slice of all String values of the enum

func EveryMinute

func EveryMinute() func(*Schedule)

EveryMinute is an option setting function for the Schedule constructor. This sets the schedule to match on every minute.

func Hour

func Hour(hour int) func(*Schedule)

Hour is an option setting function for the Schedule constructor. It sets the hour used by a Daily snapshot.

func IsTime

func IsTime(s Schedule, t time.Time) bool

IsTime returns true if the Schedule matches t.

func Keep

func Keep(n int) func(*Schedule)

Keep is an option setting function for the Schedule constructor. It sets the number of snapshots to keep.

func Minute

func Minute(minute int) func(*Schedule)

Minute is an option setting function for the Schedule constructor. It sets the minute used by an Hourly snapshot.

func Month

func Month(month time.Month) func(*Schedule)

Month is an option setting function for the Schedule constructor. It sets the month used by a Yearly snapshot.

func OptionStrings

func OptionStrings() []string

OptionStrings returns a slice of all String values of the enum

func ParseTagTime

func ParseTagTime(t string) (time.Time, error)

ParseTagTime returns the time.Time parsed from a timestamp string. The timestamp must be of the form YYYMMDDHHMM, otherwise an error is returned.

func PeriodStrings

func PeriodStrings() []string

PeriodStrings returns a slice of all String values of the enum

func TypeStrings

func TypeStrings() []string

TypeStrings returns a slice of all String values of the enum

func Weekday

func Weekday(weekday time.Weekday) func(*Schedule)

Weekday is an option setting function for the Schedule constructor. It sets the weekday used by a Weekly snapshot.

func YearDay

func YearDay(day int) func(*Schedule)

YearDay is an option setting function for the Schedule constructor. It sets the day of the year used by a Yearly snapshot.

Types

type AutoRequest

type AutoRequest struct {
	VM         *cloud.LockedInstance
	Hypervisor string
	Images     []ImageSpec
	// contains filtered or unexported fields
}

AutoRequest is a HyperCloud VM snapshot request.

func (AutoRequest) Finished

func (a AutoRequest) Finished() time.Time

Finished returns the time the request was finished.

func (AutoRequest) ID

func (a AutoRequest) ID() uint

ID return the ID of the request.

func (AutoRequest) Schedule

func (a AutoRequest) Schedule() Schedule

Schedule returns the request's snapshot schedule.

func (AutoRequest) Scheduled

func (a AutoRequest) Scheduled() time.Time

Scheduled returns the time the request was scheduled.

func (*AutoRequest) SetFinished

func (a *AutoRequest) SetFinished(t time.Time) Request

SetFinished sets the finished time of the request.

func (*AutoRequest) SetID

func (a *AutoRequest) SetID(id uint) Request

SetID sets the ID of the request.

func (*AutoRequest) SetSchedule

func (a *AutoRequest) SetSchedule(s Schedule) Request

SetSchedule sets the request's snapshot schedule.

func (*AutoRequest) SetScheduled

func (a *AutoRequest) SetScheduled(t time.Time) Request

SetScheduled sets the scheduled time of the request.

func (*AutoRequest) SetStarted

func (a *AutoRequest) SetStarted(t time.Time) Request

SetStarted sets the started time of the request.

func (AutoRequest) Started

func (a AutoRequest) Started() time.Time

Started returns the time the request was started.

func (AutoRequest) Tag

func (a AutoRequest) Tag() Tag

Tag returns the Tag that will be used when processing the request.

func (AutoRequest) VMID

func (a AutoRequest) VMID() int

VMID return the ID of the request's Virtual Machine.

type Destination

type Destination int

Destination of the Snapshot.

const (
	// Local means take snapshot of a HyperCloud VM.
	Local Destination = iota
	// Remote means copy a Local to a remote Ceph cluster.
	Remote
	// Archive means copy a Local to a remote S3 bucket.
	Archive
)

func DestinationString

func DestinationString(s string) (Destination, error)

DestinationString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func DestinationValues

func DestinationValues() []Destination

DestinationValues returns all values of the enum

func (Destination) IsADestination

func (i Destination) IsADestination() bool

IsADestination returns "true" if the value is listed in the enum definition. "false" otherwise

func (Destination) MarshalText

func (i Destination) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Destination

func (Destination) String

func (i Destination) String() string

func (*Destination) UnmarshalText

func (i *Destination) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Destination

type Image

type Image struct {
	Prefix   string `json:"prefix"`
	Template int    `json:"template"`
	VM       int    `json:"vm"`
	Disk     int    `json:"disk"`
}

Image is the name of a remote snapshot image.

func ParseImage

func ParseImage(s string) (Image, error)

ParseImage parses s to return an Image. The format is as follows:

PREFIX-TEMPLATE-VM-DISK

where

PREFIX is the name of the remote
TEMPLATE is the template ID
VM is the VM ID
DISK is the disk number

to support "persistent" disks, we also need to accept the format:

PREFIX-TEMPLATE

func (Image) String

func (i Image) String() string

String implements the Stringer interface for i.

type ImageSpec

type ImageSpec struct {
	Pool      string
	Namespace string
	Image     Image
}

ImageSpec describes the full location of an RBD image

func ParseImageSpec

func ParseImageSpec(s string) (ImageSpec, error)

ParseImageSpec parses s to return an ImageSpec.

valid formats for 's' are:

<image-name>
<pool-name>/<image-name>
<pool-name>/<namespace>/<image-name>

type ListArchiveResponse

type ListArchiveResponse struct {
	Snapshots []*pb.ListArchiveSnapshotsResponse `json:"snapshots"`
}

ListArchiveResponse is the response body for GET /snapper/archive.

type ListManualResponse

type ListManualResponse struct {
	Snapshots []*pb.ListManualSnapshotsResponse `json:"snapshots"`
}

ListManualResponse is the response body for GET /snapper/manual.

type ListRemoteResponse

type ListRemoteResponse struct {
	Snapshots []*pb.ListRemoteSnapshotsResponse `json:"snapshots"`
}

ListRemoteResponse is the response body for GET /snapper/remote.

type ListStackResponse

type ListStackResponse pb.ListStackResponse

ListStackResponse is the response body for GET /snapper/stack.

type ListStatusResponse

type ListStatusResponse struct {
	Snapshots []*pb.ListStatusResponse `json:"snapshots"`
}

ListStatusResponse is the response body for GET /snapper/status.

type ManualRequest

type ManualRequest struct {
	VM      int
	RBDName string
	// contains filtered or unexported fields
}

ManualRequest is the RBD information for the Request. A Request will have either a VMInfo or an RBDInfo.

func (ManualRequest) Finished

func (m ManualRequest) Finished() time.Time

Finished returns the time the request was finished.

func (ManualRequest) ID

func (m ManualRequest) ID() uint

ID return the ID of the request.

func (ManualRequest) Schedule

func (m ManualRequest) Schedule() Schedule

Schedule returns the request's snapshot schedule.

func (ManualRequest) Scheduled

func (m ManualRequest) Scheduled() time.Time

Scheduled returns the time the request was scheduled.

func (*ManualRequest) SetFinished

func (m *ManualRequest) SetFinished(t time.Time) Request

SetFinished sets the finished time of the request.

func (*ManualRequest) SetID

func (m *ManualRequest) SetID(id uint) Request

SetID sets the ID of the request.

func (*ManualRequest) SetSchedule

func (m *ManualRequest) SetSchedule(s Schedule) Request

SetSchedule sets the request's snapshot schedule.

func (*ManualRequest) SetScheduled

func (m *ManualRequest) SetScheduled(t time.Time) Request

SetScheduled sets the scheduled time of the request.

func (*ManualRequest) SetStarted

func (m *ManualRequest) SetStarted(t time.Time) Request

SetStarted sets the started time of the request.

func (ManualRequest) Started

func (m ManualRequest) Started() time.Time

Started returns the time the request was started.

func (ManualRequest) Tag

func (m ManualRequest) Tag() Tag

Tag returns the Tag that will be used when processing the request.

func (ManualRequest) VMID

func (m ManualRequest) VMID() int

VMID return the ID of the request's Virtual Machine.

type Option

type Option int

Option is a bitmask of settings for a Schedule.

const (
	PauseVM Option = 1 << iota
)

A Schedule may have one or more of the following Options.

func OptionString

func OptionString(s string) (Option, error)

OptionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func OptionValues

func OptionValues() []Option

OptionValues returns all values of the enum

func (Option) IsAOption

func (i Option) IsAOption() bool

IsAOption returns "true" if the value is listed in the enum definition. "false" otherwise

func (Option) MarshalText

func (i Option) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Option

func (Option) String

func (i Option) String() string

func (*Option) UnmarshalText

func (i *Option) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Option

type Period

type Period int

Period indicates the time interval of a snapshot.

const (
	Minutely Period
	Hourly
	Daily
	Weekly
	Monthly
	Yearly
)

Snapshots are taken at one of more of these intervals.

func PeriodString

func PeriodString(s string) (Period, error)

PeriodString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func PeriodValues

func PeriodValues() []Period

PeriodValues returns all values of the enum

func (Period) IsAPeriod

func (i Period) IsAPeriod() bool

IsAPeriod returns "true" if the value is listed in the enum definition. "false" otherwise

func (Period) IsValid

func (p Period) IsValid() bool

IsValid returns true if p is a known time Period.

func (Period) MarshalText

func (i Period) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Period

func (Period) String

func (i Period) String() string

func (*Period) UnmarshalText

func (i *Period) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Period

type Request

type Request interface {
	ID() uint
	Scheduled() time.Time
	Started() time.Time
	Finished() time.Time
	Schedule() Schedule
	Tag() Tag
	VMID() int
	SetID(uint) Request
	SetScheduled(time.Time) Request
	SetStarted(time.Time) Request
	SetFinished(time.Time) Request
	SetSchedule(Schedule) Request
}

Request abstracts the common attributes of ManualRequest and AutoRequest.

type Schedule

type Schedule struct {
	Destination Destination   `json:"destination"`
	Keep        int           `json:"keep"`
	Minutely    *float32      `json:"minutely,omitempty"`
	Minute      *int          `json:"minute,omitempty"`
	Hour        *int          `json:"hour,omitempty"`
	Weekday     *time.Weekday `json:"weekday,omitempty"`
	Day         *int          `json:"day,omitempty"`
	Month       *time.Month   `json:"month,omitempty"`
	YearDay     *int          `json:"yearday,omitempty"`
	Options     Option        `json:"options,omitempty"`
}

Schedule stores the time, destination, and number of snapshots to keep. All the time values are represented by pointers, and set only when used.

func NewSchedule

func NewSchedule(options ...func(*Schedule)) Schedule

NewSchedule returns and initialized Schedule. Use the option setting functions to set the time and other fields.

func (Schedule) IsTime

func (s Schedule) IsTime(t time.Time) bool

IsTime returns true if the SnapShotTime matches t.

func (Schedule) JSON

func (s Schedule) JSON() []byte

JSON returns the json representation of the Schedule.

func (Schedule) Matches

func (s Schedule) Matches(t *Schedule) bool

Matches returns true if both schedule are for the same time. It does not compare the Destination or Keep values.

func (Schedule) Period

func (s Schedule) Period() Period

Period returns the SnapshotPeriod of s. This is determined from which set of times are set.

func (Schedule) String

func (s Schedule) String() string

String implements the Stringer interface.

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(text []byte) error

UnmarshalJSON implements the Unmarshaler interface for s. Any missing time periods will get their default values. For example, a Hour snapshot with a missing Minute field will have Minute set to the top of the hour (0).

func (Schedule) When

func (s Schedule) When() when

When returns the time of the Schedule as a number in the Period. For example: an Hourly schedule returns the minute of the hour.

type Schedules

type Schedules []Schedule

Schedules is a set of snapshot schedules over every possible timing Period.

func Parse

func Parse(text string) (Schedules, error)

Parse parses the chronish lines for scheduling snapshot. Parsing is line oriented and the text can use "#" as comments. An example of the line format:

hourly:local=10,archive=3 daily:local=3,remote=3@10,remote=1@12 weekly:local=1@Tue [options:...]

See sched_test.go for more examples of the format.

func (Schedules) Daily

func (s Schedules) Daily() Schedules

Daily returns a slice of Daily snapshots in the schedule.

func (Schedules) Hourly

func (s Schedules) Hourly() Schedules

Hourly returns a slice of Hourly snapshots in the schedule.

func (Schedules) Minutely

func (s Schedules) Minutely() Schedules

Minutely returns a slice of Minutely snapshots in the schedule.

func (Schedules) Monthly

func (s Schedules) Monthly() Schedules

Monthly returns a slice of Monthly snapshots in the schedule.

func (Schedules) Sort

func (s Schedules) Sort()

Sort sorts the Schedules. This is used by the String() method.

func (Schedules) String

func (s Schedules) String() string

String implements the fmt.Stringer interface for the SnapshotSchedule.

func (Schedules) Weekly

func (s Schedules) Weekly() Schedules

Weekly returns a slice of Weekly snapshots in the schedule.

func (*Schedules) Yearly

func (s *Schedules) Yearly() Schedules

Yearly returns a slice of Yearly snapshots in the schedule.

type Service

type Service struct {
	*client.Client
	// contains filtered or unexported fields
}

Service owns the /snapper methods.

func NewService

func NewService(c *client.Client, path string) *Service

NewService returns a new Service for snapshot daemon operations.

func (Service) ArchiveSnapshots

func (s Service) ArchiveSnapshots(ctx context.Context) (*ListArchiveResponse, error)

ArchiveSnapshots returns the list of archive snapshots.

func (Service) ManualSnapshots

func (s Service) ManualSnapshots(ctx context.Context) (*ListManualResponse, error)

ManualSnapshots returns the list of manual snapshots.

func (Service) RemoteSnapshots

func (s Service) RemoteSnapshots(ctx context.Context) (*ListRemoteResponse, error)

RemoteSnapshots returns the list of remote snapshots.

func (Service) Stack

func (s Service) Stack(ctx context.Context) (*ListStackResponse, error)

Stack returns the runtime stack for all the goroutines of the snapshot daemon.

func (Service) Status

func (s Service) Status(ctx context.Context) (*ListStatusResponse, error)

Status returns the status of the snapshot daemon.

type Tag

type Tag struct {
	VM      int    // VM is used for HyperCloud snapshots (AKA local)
	RBD     string // RBD is used for Ceph snapshots (AKA manual)
	Period  Period
	Time    time.Time
	Version int
}

Tag is the named handle to uniquely name all snapshot images. The Time is the scheduled time, not the actual time the snapshot took place.

func ParseTag

func ParseTag(s string) (Tag, error)

ParseTag parses s to return a SnapshotTag.

func (Tag) ID

func (t Tag) ID() string

ID returns the either the VM number or RBD name for the Tag.

func (Tag) IsZero

func (t Tag) IsZero() bool

IsZero returns true if a tag hasn't been initialized and returns false if it has

func (Tag) MarshalText

func (t Tag) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for t.

func (Tag) Schedule

func (t Tag) Schedule() Schedule

Schedule returns a Schedule for the Tag based on it's time. The Schedules Destination and Keep values are the defaults since the Tag has no such information.

func (Tag) String

func (t Tag) String() string

String implements the Stringer interface for s. See ParseSnapshotTag for the format of this string.

func (Tag) Timestamp

func (t Tag) Timestamp() string

Timestamp returns the Time in the form YYYYMMDDHHMM.

func (Tag) Type

func (t Tag) Type() Type

Type returns the type of snapshot represented by t.

func (*Tag) UnmarshalText

func (t *Tag) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for t.

type Type

type Type int

Type indicates the type of Snapshot.

const (
	// AutoSnapshot is a Snapshot for a HyperCloud VM.
	AutoSnapshot Type = iota // auto
	// ManualSnapshot is a Snapshot for a Ceph RBD image. For example the
	// `hypercloud-dashboard` snapshot is done directly one the rbd image.
	ManualSnapshot // manual
)

func TypeString

func TypeString(s string) (Type, error)

TypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TypeValues

func TypeValues() []Type

TypeValues returns all values of the enum

func (Type) IsAType

func (i Type) IsAType() bool

IsAType returns "true" if the value is listed in the enum definition. "false" otherwise

func (Type) MarshalText

func (i Type) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Type

func (Type) String

func (i Type) String() string

func (*Type) UnmarshalText

func (i *Type) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Type

Jump to

Keyboard shortcuts

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