incus-sentinel/incus/types.go

183 lines
4.8 KiB
Go
Raw Permalink Normal View History

2025-01-05 09:34:06 +00:00
package incus
import (
"time"
)
type InstanceSentinel struct {
Backup bool
Sync bool
BackupSchedule string
BackupNotifyURL string
SyncNotifyURL string
SyncSchedule string
SyncTargetRemote string
SyncTargetPool string
SyncTargetInstanceSuffix string
}
type Instance struct {
Architecture string `json:"architecture"`
Config map[string]string `json:"config"`
Devices map[string]interface{} `json:"devices"`
Ephemeral bool `json:"ephemeral"`
Profiles []string `json:"profiles"`
Stateful bool `json:"stateful"`
Description string `json:"description"`
CreatedAt time.Time `json:"created_at"`
Name string `json:"name"`
Status string `json:"status"`
StatusCode int `json:"status_code"`
LastUsedAt time.Time `json:"last_used_at"`
Location string `json:"location"`
Type string `json:"type"`
Project string `json:"project"`
}
func (i *Instance) Sentinel() InstanceSentinel {
s := InstanceSentinel{
Backup: false,
Sync: false,
BackupNotifyURL: "",
SyncNotifyURL: "",
BackupSchedule: "0 6 * * *",
SyncSchedule: "0 6 * * *",
SyncTargetRemote: "",
SyncTargetPool: "pool0",
SyncTargetInstanceSuffix: "-cold",
}
if val, ok := i.Config["user.backup"]; ok {
s.Backup = val == "true"
}
if val, ok := i.Config["user.sync"]; ok {
s.Sync = val == "true"
}
if val, ok := i.Config["user.backup-notify-url"]; ok {
s.BackupNotifyURL = val
}
if val, ok := i.Config["user.sync-notify-url"]; ok {
s.SyncNotifyURL = val
}
if val, ok := i.Config["user.backup-schedule"]; ok {
s.BackupSchedule = val
}
if val, ok := i.Config["user.sync-schedule"]; ok {
s.SyncSchedule = val
}
if val, ok := i.Config["user.sync-target-remote"]; ok {
s.SyncTargetRemote = val
}
if val, ok := i.Config["user.sync-target-pool"]; ok {
s.SyncTargetPool = val
}
if val, ok := i.Config["user.sync-target-instance-suffix"]; ok {
s.SyncTargetInstanceSuffix = val
}
return s
}
2025-01-06 12:53:16 +00:00
type Pool struct {
Config map[string]string `json:"config"`
Description string `json:"description"`
Name string `json:"name"`
Driver string `json:"driver"`
UsedBy []string `json:"used_by"`
Status string `json:"status"`
Locations []string `json:"locations"`
}
type VolumeSentinel struct {
Backup bool
BackupMode string
Sync bool
BackupSchedule string
BackupNotifyURL string
SyncNotifyURL string
SyncSchedule string
SyncTargetRemote string
SyncTargetPool string
SyncTargetVolumeSuffix string
}
type Volume struct {
Config map[string]string `json:"config"`
Description string `json:"description"`
Name string `json:"name"`
Pool string `json:"pool"`
Type string `json:"type"`
UsedBy []string `json:"used_by"`
Location string `json:"location"`
ContentType string `json:"content_type"`
Project string `json:"project"`
CreatedAt time.Time `json:"created_at"`
}
func (v *Volume) Sentinel() VolumeSentinel {
s := VolumeSentinel{
Backup: false,
BackupMode: "dir", // dir or native
Sync: false,
BackupNotifyURL: "",
SyncNotifyURL: "",
BackupSchedule: "0 6 * * *",
SyncSchedule: "0 6 * * *",
SyncTargetRemote: "",
SyncTargetPool: "pool0",
SyncTargetVolumeSuffix: "-cold",
}
if val, ok := v.Config["user.backup"]; ok {
s.Backup = val == "true"
}
if val, ok := v.Config["user.backup-mode"]; ok {
if val == "native" || val == "dir" {
s.BackupMode = val
}
}
if val, ok := v.Config["user.sync"]; ok {
s.Sync = val == "true"
}
if val, ok := v.Config["user.backup-notify-url"]; ok {
s.BackupNotifyURL = val
}
if val, ok := v.Config["user.sync-notify-url"]; ok {
s.SyncNotifyURL = val
}
if val, ok := v.Config["user.backup-schedule"]; ok {
s.BackupSchedule = val
}
if val, ok := v.Config["user.sync-schedule"]; ok {
s.SyncSchedule = val
}
if val, ok := v.Config["user.sync-target-remote"]; ok {
s.SyncTargetRemote = val
}
if val, ok := v.Config["user.sync-target-pool"]; ok {
s.SyncTargetPool = val
}
if val, ok := v.Config["user.sync-target-instance-suffix"]; ok {
s.SyncTargetVolumeSuffix = val
}
return s
}