@@ -2,54 +2,26 @@ package cloudhypervisor
22
33import (
44 "path/filepath"
5- "time"
65
76 "github.com/cocoonstack/cocoon/config"
8- "github.com/cocoonstack/cocoon/utils "
7+ "github.com/cocoonstack/cocoon/hypervisor "
98)
109
11- // BinaryName returns the base name of the Cloud Hypervisor binary.
12- func (c * Config ) BinaryName () string { return filepath .Base (c .CHBinary ) }
13-
14- // PIDFileName returns the PID file name for the Cloud Hypervisor backend.
15- func (c * Config ) PIDFileName () string { return "ch.pid" }
16-
17- const (
18- defaultSocketWaitTimeout = 5 * time .Second
19- defaultTerminateGracePeriod = 5 * time .Second
20- )
21-
22- // Config holds Cloud Hypervisor specific configuration, embedding the global config.
10+ // Config holds Cloud Hypervisor specific configuration.
2311type Config struct {
24- * config. Config
12+ hypervisor. BaseConfig
2513}
2614
27- // EnsureDirs creates all static directories required by the Cloud Hypervisor backend.
28- func (c * Config ) EnsureDirs () error {
29- return utils .EnsureDirs (
30- c .dbDir (),
31- c .RunDir (),
32- c .LogDir (),
33- )
15+ // NewConfig creates a Config from a global config.
16+ func NewConfig (conf * config.Config ) * Config {
17+ return & Config {BaseConfig : hypervisor .NewBaseConfig (conf , "cloudhypervisor" )}
3418}
3519
36- // RunDir returns the top-level CH runtime directory.
37- func (c * Config ) RunDir () string { return filepath .Join (c .Config .RunDir , "cloudhypervisor" ) }
38-
39- // LogDir returns the top-level CH log directory.
40- func (c * Config ) LogDir () string { return filepath .Join (c .Config .LogDir , "cloudhypervisor" ) }
41-
42- // IndexFile returns the VM index store path.
43- func (c * Config ) IndexFile () string { return filepath .Join (c .dbDir (), "vms.json" ) }
44-
45- // IndexLock returns the VM index lock path.
46- func (c * Config ) IndexLock () string { return filepath .Join (c .dbDir (), "vms.lock" ) }
47-
48- // VMRunDir returns the per-VM runtime directory.
49- func (c * Config ) VMRunDir (vmID string ) string { return filepath .Join (c .RunDir (), vmID ) }
20+ // BinaryName returns the base name of the Cloud Hypervisor binary.
21+ func (c * Config ) BinaryName () string { return filepath .Base (c .CHBinary ) }
5022
51- // VMLogDir returns the per-VM log directory .
52- func (c * Config ) VMLogDir ( vmID string ) string { return filepath . Join ( c . LogDir (), vmID ) }
23+ // PIDFileName returns the PID file name for the Cloud Hypervisor backend .
24+ func (c * Config ) PIDFileName ( ) string { return "ch.pid" }
5325
5426// COWRawPath returns the path for the OCI COW raw disk.
5527func (c * Config ) COWRawPath (vmID string ) string {
@@ -63,24 +35,5 @@ func (c *Config) OverlayPath(vmID string) string {
6335
6436// CidataPath returns the path for the cloud-init NoCloud cidata disk.
6537func (c * Config ) CidataPath (vmID string ) string {
66- return filepath .Join (c .VMRunDir (vmID ), "cidata.img" )
38+ return filepath .Join (c .VMRunDir (vmID ), cidataFile )
6739}
68-
69- // SocketWaitTimeout returns the configured socket wait timeout or the default.
70- func (c * Config ) SocketWaitTimeout () time.Duration {
71- if c .SocketWaitTimeoutSeconds > 0 {
72- return time .Duration (c .SocketWaitTimeoutSeconds ) * time .Second
73- }
74- return defaultSocketWaitTimeout
75- }
76-
77- // TerminateGracePeriod returns the configured SIGTERM→SIGKILL grace period or the default.
78- func (c * Config ) TerminateGracePeriod () time.Duration {
79- if c .TerminateGracePeriodSeconds > 0 {
80- return time .Duration (c .TerminateGracePeriodSeconds ) * time .Second
81- }
82- return defaultTerminateGracePeriod
83- }
84-
85- func (c * Config ) dir () string { return filepath .Join (c .RootDir , "cloudhypervisor" ) }
86- func (c * Config ) dbDir () string { return filepath .Join (c .dir (), "db" ) }
0 commit comments