2018-08-16 21:05:21 +02:00
|
|
|
package pdu
|
2018-06-20 20:20:37 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *FilesystemVersion) RelName() string {
|
2018-08-30 11:51:47 +02:00
|
|
|
zv, err := v.ZFSFilesystemVersion()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-06-20 20:20:37 +02:00
|
|
|
return zv.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v FilesystemVersion_VersionType) ZFSVersionType() zfs.VersionType {
|
|
|
|
switch v {
|
|
|
|
case FilesystemVersion_Snapshot:
|
|
|
|
return zfs.Snapshot
|
|
|
|
case FilesystemVersion_Bookmark:
|
|
|
|
return zfs.Bookmark
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unexpected v.Type %#v", v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 11:51:47 +02:00
|
|
|
func FilesystemVersionFromZFS(fsv *zfs.FilesystemVersion) *FilesystemVersion {
|
2018-06-20 20:20:37 +02:00
|
|
|
var t FilesystemVersion_VersionType
|
|
|
|
switch fsv.Type {
|
|
|
|
case zfs.Bookmark:
|
|
|
|
t = FilesystemVersion_Bookmark
|
|
|
|
case zfs.Snapshot:
|
|
|
|
t = FilesystemVersion_Snapshot
|
|
|
|
default:
|
|
|
|
panic("unknown fsv.Type: " + fsv.Type)
|
|
|
|
}
|
|
|
|
return &FilesystemVersion{
|
2018-08-25 21:30:25 +02:00
|
|
|
Type: t,
|
|
|
|
Name: fsv.Name,
|
|
|
|
Guid: fsv.Guid,
|
2018-06-20 20:20:37 +02:00
|
|
|
CreateTXG: fsv.CreateTXG,
|
2018-08-25 21:30:25 +02:00
|
|
|
Creation: fsv.Creation.Format(time.RFC3339),
|
2018-06-20 20:20:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-29 19:00:45 +02:00
|
|
|
func FilesystemVersionCreation(t time.Time) string {
|
|
|
|
return t.Format(time.RFC3339)
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:06:00 +02:00
|
|
|
func (v *FilesystemVersion) CreationAsTime() (time.Time, error) {
|
|
|
|
return time.Parse(time.RFC3339, v.Creation)
|
|
|
|
}
|
|
|
|
|
2018-08-16 21:05:21 +02:00
|
|
|
// implement fsfsm.FilesystemVersion
|
|
|
|
func (v *FilesystemVersion) SnapshotTime() time.Time {
|
|
|
|
t, err := v.CreationAsTime()
|
|
|
|
if err != nil {
|
|
|
|
panic(err) // FIXME
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2018-08-30 11:51:47 +02:00
|
|
|
func (v *FilesystemVersion) ZFSFilesystemVersion() (*zfs.FilesystemVersion, error) {
|
|
|
|
ct, err := v.CreationAsTime()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2018-06-20 20:20:37 +02:00
|
|
|
}
|
|
|
|
return &zfs.FilesystemVersion{
|
2018-08-25 21:30:25 +02:00
|
|
|
Type: v.Type.ZFSVersionType(),
|
|
|
|
Name: v.Name,
|
|
|
|
Guid: v.Guid,
|
2018-06-20 20:20:37 +02:00
|
|
|
CreateTXG: v.CreateTXG,
|
2018-08-25 21:30:25 +02:00
|
|
|
Creation: ct,
|
2018-08-30 11:51:47 +02:00
|
|
|
}, nil
|
2018-08-16 21:05:21 +02:00
|
|
|
}
|