MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / parseVMConfig

Function parseVMConfig

pkg/api/vm_config.go:125–239  ·  view source on GitHub ↗

parseVMConfig parses the config API response into a VMConfig struct.

(vmType string, data map[string]interface{})

Source from the content-addressed store, hash-verified

123
124// parseVMConfig parses the config API response into a VMConfig struct.
125func parseVMConfig(vmType string, data map[string]interface{}) *VMConfig {
126 cfg := &VMConfig{}
127 if vmType == VMTypeQemu {
128 if v, ok := data["name"].(string); ok {
129 cfg.Name = v
130 }
131 }
132 if v, ok := data["hostname"].(string); ok {
133 cfg.Hostname = v
134 }
135 if v, ok := data["cores"].(float64); ok {
136 cfg.Cores = int(v)
137 }
138
139 if v, ok := data["sockets"].(float64); ok {
140 cfg.Sockets = int(v)
141 }
142 // Memory (MB) for both QEMU and LXC
143 if memRaw, ok := data["memory"]; ok {
144 switch v := memRaw.(type) {
145 case string:
146 // QEMU: memory is a string (MB)
147 if mb, err := strconv.Atoi(v); err == nil {
148 cfg.Memory = int64(mb) * 1024 * 1024
149 }
150 case float64:
151 // LXC: memory is a float (MB)
152 cfg.Memory = int64(v) * 1024 * 1024
153 case int:
154 cfg.Memory = int64(v) * 1024 * 1024
155 }
156 }
157
158 if v, ok := data["description"].(string); ok {
159 cfg.Description = v
160 }
161
162 if v, ok := data["tags"].(string); ok {
163 cfg.Tags = v
164 cfg.TagsExplicit = true
165 }
166
167 if v, ok := data["onboot"].(float64); ok {
168 b := v != 0
169 cfg.OnBoot = &b
170 }
171
172 if v, ok := data["onboot"].(string); ok {
173 b := v == "1" || strings.ToLower(v) == stringYes
174 cfg.OnBoot = &b
175 }
176
177 if vmType == VMTypeQemu {
178 if v, ok := data["cpu"].(string); ok {
179 cfg.CPUType = v
180 }
181
182 if v, ok := data["maxmem"].(float64); ok {

Callers 2

GetVMConfigMethod · 0.85

Calls 2

parseQEMUAgentEnabledFunction · 0.85
parseConfigSizeBytesFunction · 0.85

Tested by 1