Skip to content

Commit 8ae105f

Browse files
committed
add get vm config
1 parent 9fdab94 commit 8ae105f

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

api/qemu_type.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,89 @@ type VirtualMachineCreateOptions struct {
156156
// vm id
157157
VMID int `json:"vmid,omitempty"`
158158
}
159+
160+
type VirtualMachineConfig struct {
161+
// PVE Metadata
162+
Digest string `json:"digest"`
163+
Name string `json:"name,omitempty"`
164+
Description string `json:"description,omitempty"`
165+
Meta string `json:"meta,omitempty"`
166+
VMGenID string `json:"vmgenid,omitempty"`
167+
Hookscript string `json:"hookscript,omitempty"`
168+
Hotplug string `json:"hotplug,omitempty"`
169+
Template int `json:"template,omitempty"`
170+
171+
Tags string `json:"tags,omitempty"`
172+
173+
Protection int `json:"protection,omitempty"`
174+
Lock string `json:"lock,omitempty"`
175+
176+
// Boot configuration
177+
Boot string `json:"boot,omitempty"`
178+
OnBoot int `json:"onboot,omitempty"`
179+
180+
// Qemu general specs
181+
OSType string `json:"ostype,omitempty"`
182+
Machine string `json:"machine,omitempty"`
183+
Args string `json:"args,omitempty"`
184+
185+
// Qemu firmware specs
186+
Bios string `json:"bios,omitempty"`
187+
EFIDisk0 string `json:"efidisk0,omitempty"`
188+
SMBios1 string `json:"smbios1,omitempty"`
189+
Acpi int `json:"acpi,omitempty"`
190+
191+
// Qemu CPU specs
192+
Sockets int `json:"sockets,omitempty"`
193+
Cores int `json:"cores,omitempty"`
194+
CPU string `json:"cpu,omitempty"`
195+
CPULimit int `json:"cpulimit,omitempty"`
196+
CPUUnits int `json:"cpuunits,omitempty"`
197+
Vcpus int `json:"vcpus,omitempty"`
198+
Affinity string `json:"affinity,omitempty"`
199+
200+
// Qemu memory specs
201+
Numa int `json:"numa,omitempty"`
202+
Memory int `json:"memory,omitempty"`
203+
Hugepages string `json:"hugepages,omitempty"`
204+
Balloon int `json:"balloon,omitempty"`
205+
206+
// Other Qemu devices
207+
VGA string `json:"vga,omitempty"`
208+
SCSIHW string `json:"scsihw,omitempty"`
209+
TPMState0 string `json:"tpmstate0,omitempty"`
210+
Rng0 string `json:"rng0,omitempty"`
211+
Audio0 string `json:"audio0,omitempty"`
212+
213+
// Disk devices
214+
Ide
215+
216+
Scsi
217+
218+
// Sata
219+
// Virtio
220+
// Unused
221+
222+
// Network devices
223+
Net
224+
225+
// NUMA
226+
// Host PCI devices HostPci
227+
228+
// Serial devices
229+
Serial
230+
231+
// USB devices
232+
// Parallel devices
233+
// Cloud-init
234+
CIType string `json:"citype,omitempty"`
235+
CIUser string `json:"ciuser,omitempty"`
236+
CIPassword string `json:"cipassword,omitempty"`
237+
Nameserver string `json:"nameserver,omitempty"`
238+
Searchdomain string `json:"searchdomain,omitempty"`
239+
SSHKeys string `json:"sshkeys,omitempty"`
240+
CICustom string `json:"cicustom,omitempty"`
241+
242+
// Cloud-init interfaces
243+
// IPConfig
244+
}

rest/qemu.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ func (c *RESTClient) DeleteVirtualMachine(node string, vmid int) (*string, error
4646
}
4747
return upid, nil
4848
}
49+
50+
func (c *RESTClient) GetVirtualMachineConfig(node string, vmid int) (*api.VirtualMachineConfig, error) {
51+
path := fmt.Sprintf("/nodes/%s/qemu/%d/config", node, vmid)
52+
var config *api.VirtualMachineConfig
53+
if err := c.Get(path, &config); err != nil {
54+
return nil, err
55+
}
56+
return config, nil
57+
}

rest/qemu_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package rest
2+
3+
import "github.com/sp-yduck/proxmox-go/api"
4+
5+
func (s *TestSuite) TestGetVirtualMachines() {
6+
nodeName := s.GetTestNode().Node
7+
vms, err := s.restclient.GetVirtualMachines(nodeName)
8+
if err != nil {
9+
s.T().Fatalf("failed to get vms: %v", err)
10+
}
11+
s.T().Logf("get vms: %v", vms)
12+
}
13+
14+
func (s *TestSuite) GetTestVM() *api.VirtualMachine {
15+
nodeName := s.GetTestNode().Node
16+
vms, err := s.restclient.GetVirtualMachines(nodeName)
17+
if err != nil {
18+
s.T().Fatalf("failed to get vms: %v", err)
19+
}
20+
return vms[0]
21+
}
22+
23+
func (s *TestSuite) TestGetVirtualMachine() {
24+
nodeName := s.GetTestNode().Node
25+
vmid := s.GetTestVM().VMID
26+
vm, err := s.restclient.GetVirtualMachine(nodeName, vmid)
27+
if err != nil {
28+
s.T().Fatalf("failed to get vm: %v", err)
29+
}
30+
s.T().Logf("get vm: %v", *vm)
31+
}
32+
33+
func (s *TestSuite) TestGetVirtualMachineConfig() {
34+
nodeName := s.GetTestNode().Node
35+
vmid := s.GetTestVM().VMID
36+
config, err := s.restclient.GetVirtualMachineConfig(nodeName, vmid)
37+
if err != nil {
38+
s.T().Fatalf("failed to get vm: %v", err)
39+
}
40+
s.T().Logf("get vm config: %v", *config)
41+
}

0 commit comments

Comments
 (0)