88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
|
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
|
||
|
}
|