diff --git a/vendor/github.com/ceph/go-ceph/rbd/admin/admin.go b/vendor/github.com/ceph/go-ceph/rbd/admin/admin.go new file mode 100644 index 000000000..955b3ef7d --- /dev/null +++ b/vendor/github.com/ceph/go-ceph/rbd/admin/admin.go @@ -0,0 +1,51 @@ +// +build !nautilus + +package admin + +import ( + "fmt" + + ccom "github.com/ceph/go-ceph/common/commands" +) + +// RBDAdmin is used to administrate rbd volumes and pools. +type RBDAdmin struct { + conn ccom.RadosCommander +} + +// NewFromConn creates an new management object from a preexisting +// rados connection. The existing connection can be rados.Conn or any +// type implementing the RadosCommander interface. +func NewFromConn(conn ccom.RadosCommander) *RBDAdmin { + return &RBDAdmin{conn} +} + +// LevelSpec values are used to identify RBD objects wherever Ceph APIs +// require a levelspec to select an image, pool, or namespace. +type LevelSpec struct { + spec string +} + +// NewLevelSpec is used to construct a LevelSpec given a pool and +// optional namespace and image names. +func NewLevelSpec(pool, namespace, image string) LevelSpec { + var s string + if image != "" && namespace != "" { + s = fmt.Sprintf("%s/%s/%s", pool, namespace, image) + } else if image != "" { + s = fmt.Sprintf("%s/%s", pool, image) + } else if namespace != "" { + s = fmt.Sprintf("%s/%s/", pool, namespace) + } else { + s = fmt.Sprintf("%s/", pool) + } + return LevelSpec{s} +} + +// NewRawLevelSpec returns a LevelSpec directly based on the spec string +// argument without constructing it from component values. This should only be +// used if NewLevelSpec can not create the levelspec value you want to pass to +// ceph. +func NewRawLevelSpec(spec string) LevelSpec { + return LevelSpec{spec} +} diff --git a/vendor/github.com/ceph/go-ceph/rbd/admin/doc.go b/vendor/github.com/ceph/go-ceph/rbd/admin/doc.go new file mode 100644 index 000000000..44d4fab6a --- /dev/null +++ b/vendor/github.com/ceph/go-ceph/rbd/admin/doc.go @@ -0,0 +1,10 @@ +/* +Package admin is a convenience layer to support the administration of +rbd volumes, snapshots, scheduling etc that is outside of the C api +for librbd. + +Unlike the rbd package this API does not map to APIs provided by +ceph libraries themselves. This API is not yet stable and is subject +to change. +*/ +package admin diff --git a/vendor/github.com/ceph/go-ceph/rbd/admin/msschedule.go b/vendor/github.com/ceph/go-ceph/rbd/admin/msschedule.go new file mode 100644 index 000000000..bbb7f0c91 --- /dev/null +++ b/vendor/github.com/ceph/go-ceph/rbd/admin/msschedule.go @@ -0,0 +1,170 @@ +// +build !nautilus + +package admin + +import ( + ccom "github.com/ceph/go-ceph/common/commands" + "github.com/ceph/go-ceph/internal/commands" +) + +// Interval of time between scheduled snapshots. Typically in the form +// . Exact content supported is defined internally on the ceph mgr. +type Interval string + +// StartTime is the time the snapshot schedule begins. Exact content supported +// is defined internally on the ceph mgr. +type StartTime string + +var ( + // NoInterval indicates no specific interval. + NoInterval = Interval("") + + // NoStartTime indicates no specific start time. + NoStartTime = StartTime("") +) + +// MirrorSnashotScheduleAdmin encapsulates management functions for +// ceph rbd mirror snapshot schedules. +type MirrorSnashotScheduleAdmin struct { + conn ccom.MgrCommander +} + +// MirrorSnashotSchedule returns a MirrorSnashotScheduleAdmin type for +// managing ceph rbd mirror snapshot schedules. +func (ra *RBDAdmin) MirrorSnashotSchedule() *MirrorSnashotScheduleAdmin { + return &MirrorSnashotScheduleAdmin{conn: ra.conn} +} + +// Add a new snapshot schedule to the given pool/image based on the supplied +// level spec. +// +// Similar To: +// rbd mirror snapshot schedule add +func (mss *MirrorSnashotScheduleAdmin) Add(l LevelSpec, i Interval, s StartTime) error { + m := map[string]string{ + "prefix": "rbd mirror snapshot schedule add", + "level_spec": l.spec, + "format": "json", + } + if i != NoInterval { + m["interval"] = string(i) + } + if s != NoStartTime { + m["start_time"] = string(s) + } + return commands.MarshalMgrCommand(mss.conn, m).NoData().End() +} + +// List the snapshot schedules based on the supplied level spec. +// +// Similar To: +// rbd mirror snapshot schedule list +func (mss *MirrorSnashotScheduleAdmin) List(l LevelSpec) ([]SnapshotSchedule, error) { + m := map[string]string{ + "prefix": "rbd mirror snapshot schedule list", + "level_spec": l.spec, + "format": "json", + } + return parseMirrorSnapshotScheduleList( + commands.MarshalMgrCommand(mss.conn, m)) +} + +type snapshotScheduleMap map[string]snapshotScheduleSubsection + +type snapshotScheduleSubsection struct { + Name string `json:"name"` + Schedule []ScheduleTerm `json:"schedule"` +} + +// ScheduleTerm represents the interval and start time component of +// a snapshot schedule. +type ScheduleTerm struct { + Interval Interval `json:"interval"` + StartTime StartTime `json:"start_time"` +} + +// SnapshotSchedule contains values representing an entire snapshot schedule +// for an image or pool. +type SnapshotSchedule struct { + Name string + LevelSpecID string + Schedule []ScheduleTerm +} + +func parseMirrorSnapshotScheduleList(res commands.Response) ( + []SnapshotSchedule, error) { + + var ss snapshotScheduleMap + if err := res.NoStatus().Unmarshal(&ss).End(); err != nil { + return nil, err + } + + var sched []SnapshotSchedule + for k, v := range ss { + sched = append(sched, SnapshotSchedule{ + Name: v.Name, + LevelSpecID: k, + Schedule: v.Schedule, + }) + } + return sched, nil +} + +// Remove a snapshot schedule matching the supplied arguments. +// +// Similar To: +// rbd mirror snapshot schedule remove +func (mss *MirrorSnashotScheduleAdmin) Remove( + l LevelSpec, i Interval, s StartTime) error { + + m := map[string]string{ + "prefix": "rbd mirror snapshot schedule remove", + "level_spec": l.spec, + "format": "json", + } + if i != NoInterval { + m["interval"] = string(i) + } + if s != NoStartTime { + m["start_time"] = string(s) + } + return commands.MarshalMgrCommand(mss.conn, m).NoData().End() +} + +// Status returns the status of the snapshot (eg. when it will next take place) +// matching the supplied level spec. +// +// Similar To: +// rbd mirror snapshot schedule status +func (mss *MirrorSnashotScheduleAdmin) Status(l LevelSpec) ([]ScheduledImage, error) { + m := map[string]string{ + "prefix": "rbd mirror snapshot schedule status", + "level_spec": l.spec, + "format": "json", + } + return parseMirrorSnapshotScheduleStatus( + commands.MarshalMgrCommand(mss.conn, m)) +} + +// ScheduleTime is the time a snapshot will occur. +type ScheduleTime string + +// ScheduledImage contains the item scheduled and when it will next occur. +type ScheduledImage struct { + Image string `json:"image"` + ScheduleTime ScheduleTime `json:"schedule_time"` +} + +type scheduledImageWrapper struct { + ScheduledImages []ScheduledImage `json:"scheduled_images"` +} + +func parseMirrorSnapshotScheduleStatus(res commands.Response) ( + []ScheduledImage, error) { + + var siw scheduledImageWrapper + if err := res.NoStatus().Unmarshal(&siw).End(); err != nil { + return nil, err + } + return siw.ScheduledImages, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 9b4ac7c3d..375d76323 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -59,6 +59,7 @@ github.com/ceph/go-ceph/internal/retry github.com/ceph/go-ceph/internal/timespec github.com/ceph/go-ceph/rados github.com/ceph/go-ceph/rbd +github.com/ceph/go-ceph/rbd/admin # github.com/cespare/xxhash/v2 v2.1.1 github.com/cespare/xxhash/v2 # github.com/container-storage-interface/spec v1.5.0