From 8ae105fd72656465c5b577ec6ef8ec7e5235cb38 Mon Sep 17 00:00:00 2001 From: sp-yduck Date: Thu, 20 Jul 2023 23:11:39 +0900 Subject: [PATCH] add get vm config --- api/qemu_type.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++ rest/qemu.go | 9 +++++ rest/qemu_test.go | 41 ++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 rest/qemu_test.go diff --git a/api/qemu_type.go b/api/qemu_type.go index a9420a8..1ad73b7 100644 --- a/api/qemu_type.go +++ b/api/qemu_type.go @@ -156,3 +156,89 @@ type VirtualMachineCreateOptions struct { // vm id VMID int `json:"vmid,omitempty"` } + +type VirtualMachineConfig struct { + // PVE Metadata + Digest string `json:"digest"` + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Meta string `json:"meta,omitempty"` + VMGenID string `json:"vmgenid,omitempty"` + Hookscript string `json:"hookscript,omitempty"` + Hotplug string `json:"hotplug,omitempty"` + Template int `json:"template,omitempty"` + + Tags string `json:"tags,omitempty"` + + Protection int `json:"protection,omitempty"` + Lock string `json:"lock,omitempty"` + + // Boot configuration + Boot string `json:"boot,omitempty"` + OnBoot int `json:"onboot,omitempty"` + + // Qemu general specs + OSType string `json:"ostype,omitempty"` + Machine string `json:"machine,omitempty"` + Args string `json:"args,omitempty"` + + // Qemu firmware specs + Bios string `json:"bios,omitempty"` + EFIDisk0 string `json:"efidisk0,omitempty"` + SMBios1 string `json:"smbios1,omitempty"` + Acpi int `json:"acpi,omitempty"` + + // Qemu CPU specs + Sockets int `json:"sockets,omitempty"` + Cores int `json:"cores,omitempty"` + CPU string `json:"cpu,omitempty"` + CPULimit int `json:"cpulimit,omitempty"` + CPUUnits int `json:"cpuunits,omitempty"` + Vcpus int `json:"vcpus,omitempty"` + Affinity string `json:"affinity,omitempty"` + + // Qemu memory specs + Numa int `json:"numa,omitempty"` + Memory int `json:"memory,omitempty"` + Hugepages string `json:"hugepages,omitempty"` + Balloon int `json:"balloon,omitempty"` + + // Other Qemu devices + VGA string `json:"vga,omitempty"` + SCSIHW string `json:"scsihw,omitempty"` + TPMState0 string `json:"tpmstate0,omitempty"` + Rng0 string `json:"rng0,omitempty"` + Audio0 string `json:"audio0,omitempty"` + + // Disk devices + Ide + + Scsi + + // Sata + // Virtio + // Unused + + // Network devices + Net + + // NUMA + // Host PCI devices HostPci + + // Serial devices + Serial + + // USB devices + // Parallel devices + // Cloud-init + CIType string `json:"citype,omitempty"` + CIUser string `json:"ciuser,omitempty"` + CIPassword string `json:"cipassword,omitempty"` + Nameserver string `json:"nameserver,omitempty"` + Searchdomain string `json:"searchdomain,omitempty"` + SSHKeys string `json:"sshkeys,omitempty"` + CICustom string `json:"cicustom,omitempty"` + + // Cloud-init interfaces + // IPConfig +} diff --git a/rest/qemu.go b/rest/qemu.go index 5e4ee9e..4a03a7c 100644 --- a/rest/qemu.go +++ b/rest/qemu.go @@ -46,3 +46,12 @@ func (c *RESTClient) DeleteVirtualMachine(node string, vmid int) (*string, error } return upid, nil } + +func (c *RESTClient) GetVirtualMachineConfig(node string, vmid int) (*api.VirtualMachineConfig, error) { + path := fmt.Sprintf("/nodes/%s/qemu/%d/config", node, vmid) + var config *api.VirtualMachineConfig + if err := c.Get(path, &config); err != nil { + return nil, err + } + return config, nil +} diff --git a/rest/qemu_test.go b/rest/qemu_test.go new file mode 100644 index 0000000..79e73ac --- /dev/null +++ b/rest/qemu_test.go @@ -0,0 +1,41 @@ +package rest + +import "github.com/sp-yduck/proxmox-go/api" + +func (s *TestSuite) TestGetVirtualMachines() { + nodeName := s.GetTestNode().Node + vms, err := s.restclient.GetVirtualMachines(nodeName) + if err != nil { + s.T().Fatalf("failed to get vms: %v", err) + } + s.T().Logf("get vms: %v", vms) +} + +func (s *TestSuite) GetTestVM() *api.VirtualMachine { + nodeName := s.GetTestNode().Node + vms, err := s.restclient.GetVirtualMachines(nodeName) + if err != nil { + s.T().Fatalf("failed to get vms: %v", err) + } + return vms[0] +} + +func (s *TestSuite) TestGetVirtualMachine() { + nodeName := s.GetTestNode().Node + vmid := s.GetTestVM().VMID + vm, err := s.restclient.GetVirtualMachine(nodeName, vmid) + if err != nil { + s.T().Fatalf("failed to get vm: %v", err) + } + s.T().Logf("get vm: %v", *vm) +} + +func (s *TestSuite) TestGetVirtualMachineConfig() { + nodeName := s.GetTestNode().Node + vmid := s.GetTestVM().VMID + config, err := s.restclient.GetVirtualMachineConfig(nodeName, vmid) + if err != nil { + s.T().Fatalf("failed to get vm: %v", err) + } + s.T().Logf("get vm config: %v", *config) +}