-
Notifications
You must be signed in to change notification settings - Fork 64
/
qemu_rtc.go
65 lines (53 loc) · 1.5 KB
/
qemu_rtc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package qemu
import (
"strings"
"time"
)
type QemuRTCBaseType string
const (
QemuRTCBaseUtc = QemuRTCBaseType("utc")
QemuRTCBaseLocaltime = QemuRTCBaseType("localtime")
QemuRTCBaseCustom = QemuRTCBaseType("custom")
)
type QemuRTCClockType string
const (
QemuRTCClockHost = QemuRTCClockType("host")
QemuRTCClockRt = QemuRTCClockType("rt")
QemuRTCClockVm = QemuRTCClockType("vm")
)
type QemuRTCDriftFixType string
const (
QemuRTCDriftFixNone = QemuRTCDriftFixType("none")
QemuRTCDriftFixSlew = QemuRTCDriftFixType("slew")
)
type QemuRTC struct {
Base QemuRTCBaseType `json:"base,omitempty"`
BaseDatetime time.Time `json:"base_datetime,omitempty"`
Clock QemuRTCClockType `json:"clock,omitempty"`
DriftFix QemuRTCDriftFixType `json:"drift_fix,omitempty"`
}
func (qr QemuRTC) String() string {
if qr.Base == "" {
return ""
}
var ret strings.Builder
ret.WriteString("base=")
if qr.Base == QemuRTCBaseCustom {
ret.WriteString(qr.BaseDatetime.String())
} else if qr.Base != "" {
ret.WriteString(string(qr.Base))
}
if qr.Clock != "" {
ret.WriteString(",clock=")
ret.WriteString(string(qr.Clock))
}
if qr.DriftFix != "" {
ret.WriteString(",driftfix=")
ret.WriteString(string(qr.DriftFix))
}
return ret.String()
}