-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtypes.go
More file actions
97 lines (80 loc) · 3.44 KB
/
Copy pathtypes.go
File metadata and controls
97 lines (80 loc) · 3.44 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package instances
import (
"time"
"github.com/onkernel/hypeman/lib/vmm"
)
// State represents the instance state
type State string
const (
StateStopped State = "Stopped" // No VMM, no snapshot
StateCreated State = "Created" // VMM created but not booted (CH native)
StateRunning State = "Running" // VM running (CH native)
StatePaused State = "Paused" // VM paused (CH native)
StateShutdown State = "Shutdown" // VM shutdown, VMM exists (CH native)
StateStandby State = "Standby" // No VMM, snapshot exists
)
// VolumeAttachment represents a volume attached to an instance
type VolumeAttachment struct {
VolumeID string // Volume ID
MountPath string // Mount path in guest
Readonly bool // Whether mounted read-only
Overlay bool // If true, create per-instance overlay for writes (requires Readonly=true)
OverlaySize int64 // Size of overlay disk in bytes (max diff from base)
}
// StoredMetadata represents instance metadata that is persisted to disk
type StoredMetadata struct {
// Identification
Id string // Auto-generated CUID2
Name string
Image string // OCI reference
// Resources (matching Cloud Hypervisor terminology)
Size int64 // Base memory in bytes
HotplugSize int64 // Hotplug memory in bytes
OverlaySize int64 // Overlay disk size in bytes
Vcpus int
// Configuration
Env map[string]string
NetworkEnabled bool // Whether instance has networking enabled (uses default network)
IP string // Assigned IP address (empty if NetworkEnabled=false)
MAC string // Assigned MAC address (empty if NetworkEnabled=false)
// Attached volumes
Volumes []VolumeAttachment // Volumes attached to this instance
// Timestamps (stored for historical tracking)
CreatedAt time.Time
StartedAt *time.Time // Last time VM was started
StoppedAt *time.Time // Last time VM was stopped
// Versions
KernelVersion string // Kernel version (e.g., "ch-v6.12.9")
CHVersion vmm.CHVersion // Cloud Hypervisor version
CHPID *int // Cloud Hypervisor process ID (may be stale after host restart)
// Paths
SocketPath string // Path to API socket
DataDir string // Instance data directory
// vsock configuration
VsockCID int64 // Guest vsock Context ID
VsockSocket string // Host-side vsock socket path
}
// Instance represents a virtual machine instance with derived runtime state
type Instance struct {
StoredMetadata
// Derived fields (not stored in metadata.json)
State State // Derived from socket + VMM query
HasSnapshot bool // Derived from filesystem check
}
// CreateInstanceRequest is the domain request for creating an instance
type CreateInstanceRequest struct {
Name string // Required
Image string // Required: OCI reference
Size int64 // Base memory in bytes (default: 1GB)
HotplugSize int64 // Hotplug memory in bytes (default: 3GB)
OverlaySize int64 // Overlay disk size in bytes (default: 10GB)
Vcpus int // Default 2
Env map[string]string // Optional environment variables
NetworkEnabled bool // Whether to enable networking (uses default network)
Volumes []VolumeAttachment // Volumes to attach at creation time
}
// AttachVolumeRequest is the domain request for attaching a volume (used for API compatibility)
type AttachVolumeRequest struct {
MountPath string
Readonly bool
}