Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul qemu disks merge #255

Merged
merged 122 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
339baf9
feat: add parsing of qemu disks into struct
Tinyblargon Feb 15, 2023
a4ec1a1
feat: Add Disks parameter in ConfigQemu struct
Tinyblargon Feb 16, 2023
5fc83d2
feat: Map Qemu Disks to api values
Tinyblargon Feb 16, 2023
a89a72e
style: put in alphabetical order
Tinyblargon Feb 16, 2023
8e45a16
feat: Add serial key to disks
Tinyblargon Feb 16, 2023
4967e1b
docs: Add TODO
Tinyblargon Feb 16, 2023
7f697ad
test: add test for QemuDiskSerial.Validate
Tinyblargon Feb 16, 2023
4454dca
refactor: Add enum and validate allowed values
Tinyblargon Feb 16, 2023
327c98a
fix: typo
Tinyblargon Feb 16, 2023
aec9e6d
feat: Add enum for QemuDiskFormat and validate allowed values
Tinyblargon Feb 16, 2023
01714f4
feat: Add enum for QemuDiskAsyncIO and validate allowed values
Tinyblargon Feb 16, 2023
79d897d
fix: change setting name in error message
Tinyblargon Feb 16, 2023
0281935
refactor: Add Json keys
Tinyblargon Feb 16, 2023
aab856e
feat: Map QemuCdRom to API values
Tinyblargon Feb 16, 2023
1322606
feat: create logic for creating, updating, migrating and deleting disks
Tinyblargon Mar 2, 2023
9fce801
refactor: remove errors that always return nil
Tinyblargon Mar 2, 2023
3f356ba
docs: typos and capitalization
Tinyblargon Mar 2, 2023
6671092
refactor: make variable camelCase
Tinyblargon Mar 2, 2023
b9b36c1
refactor: change array to string
Tinyblargon Mar 2, 2023
f8864f3
refactor: change mapping of qemu api parameters
Tinyblargon Mar 2, 2023
a2bb827
mark `ConfigQemu.QemuDisks` as Deprecated
Tinyblargon Mar 2, 2023
967e9fd
Make `ConfigQemu.BootDisk` read only
Tinyblargon Mar 2, 2023
5063776
Mark func as Deprecated
Tinyblargon Mar 2, 2023
214163e
Mark func as Deprecated
Tinyblargon Mar 2, 2023
8ec657c
fix: return error instead of printing it
Tinyblargon Mar 2, 2023
7113ce2
feat: added `UpdateAdvanced` and `Update`
Tinyblargon Mar 2, 2023
1cc8b06
feat: Map passthrough disk to api
Tinyblargon Mar 10, 2023
5644d23
feat: map cloud-init disk to api
Tinyblargon Mar 10, 2023
4e7d7be
refactor: change logic for when a disk needs to be deleted
Tinyblargon Mar 10, 2023
92dd6f5
feat: Make Size property read only
Tinyblargon Mar 11, 2023
00f4653
refactor: Put in alphabetical order
Tinyblargon Mar 11, 2023
7c58c80
Add TODO for future refactors
Tinyblargon Mar 11, 2023
309c179
refactor: QemuDiskBandwidth struct
Tinyblargon Mar 11, 2023
1864a51
refactor: consolidate code for creating/updating disks
Tinyblargon Mar 12, 2023
d338e78
fix: decoding of disk id
Tinyblargon Mar 12, 2023
1d567af
refactor: remove unnecessary function
Tinyblargon Mar 12, 2023
de31a18
feat: make id optional
Tinyblargon Mar 12, 2023
b594866
feat: add disk resizing
Tinyblargon Mar 12, 2023
1665b1b
Commit missing changes
Tinyblargon Mar 12, 2023
a05ef20
Add TODO
Tinyblargon Mar 12, 2023
bd13540
refactor: remove dead code
Tinyblargon Mar 12, 2023
56949b2
refactor: put in alphabetical order
Tinyblargon Mar 12, 2023
343c2c8
fix: panic
Tinyblargon Mar 12, 2023
a988d64
fix: bugs caused by conditionals
Tinyblargon Mar 12, 2023
90e6dba
feat: add new Iso setting
Tinyblargon Mar 12, 2023
c9718e1
refactor: change post to put
Tinyblargon Mar 12, 2023
2ab9812
feat: logic for node migration
Tinyblargon Mar 12, 2023
c0f9785
refactor: move converting from api to struct into its own function
Tinyblargon Mar 12, 2023
6395895
refactor: put in alphabetical order
Tinyblargon Mar 12, 2023
645cac6
refactor: extract to func
Tinyblargon Mar 13, 2023
02dd49a
feat: change to pointer
Tinyblargon Mar 13, 2023
297dc14
fix: typo
Tinyblargon Mar 13, 2023
34ea692
feat: add Validator for `QemuDiskBandwidth` and sub types
Tinyblargon Mar 14, 2023
5412645
feat: add Validate func for `IsoFile`
Tinyblargon Mar 14, 2023
40731aa
feat: add Validate func for `QemuCdRom`
Tinyblargon Mar 14, 2023
65ea0b2
feat: make format optional
Tinyblargon Mar 14, 2023
3d39fd5
feat: allow for empty case
Tinyblargon Mar 14, 2023
f5c740e
fix: format should never be empty
Tinyblargon Mar 14, 2023
9ef20ed
feat: add Validate func for `QemuCloudInitDisk`
Tinyblargon Mar 14, 2023
e9d6cc1
fix: remove empty case
Tinyblargon Mar 14, 2023
01808d2
fix: allow for empty case
Tinyblargon Mar 14, 2023
ddfe866
refactor: make code more reusable
Tinyblargon Mar 14, 2023
1c1908c
fix: check correct value
Tinyblargon Mar 14, 2023
cb072a6
feat: add `Disk` property to `qemuDisk`
Tinyblargon Mar 15, 2023
7952dd3
refactor: make `QemuDiskFormat` required
Tinyblargon Mar 15, 2023
1a3d4ed
refactor: make `QemuDiskFormat` required
Tinyblargon Mar 15, 2023
3a188d7
test: match exact error
Tinyblargon Mar 15, 2023
ddf2acf
test: match exact error
Tinyblargon Mar 15, 2023
d1f36ec
test: match exact error
Tinyblargon Mar 15, 2023
d7b9fae
refactor: make `0` default instad of `nil`
Tinyblargon Mar 15, 2023
25658bf
test: match exact error
Tinyblargon Mar 15, 2023
fa66b8b
test: match exact error
Tinyblargon Mar 15, 2023
70f05b0
test: match exact error
Tinyblargon Mar 15, 2023
3ee90fc
test: match exact error
Tinyblargon Mar 15, 2023
5e46b85
refactor: create const for errors
Tinyblargon Mar 15, 2023
ab1df95
test: name all test cases
Tinyblargon Mar 15, 2023
8ac0792
feat: add Validat func for `ConfigQemu.Disks`
Tinyblargon Mar 16, 2023
1fe52d4
refactor: update json keys
Tinyblargon Mar 16, 2023
3bf2888
fix: not checking for duplicate cloudinit disk
Tinyblargon Mar 16, 2023
651d645
Add TODO
Tinyblargon Mar 16, 2023
199a7d1
refactor: move defaults to seperate fuction
Tinyblargon Mar 16, 2023
f42049a
refactor: move defaults to seperate fuction
Tinyblargon Mar 16, 2023
c1438e2
refactor: remove pointer inside func
Tinyblargon Mar 16, 2023
221764a
fix: item not initialized before use
Tinyblargon Mar 16, 2023
70d2895
fix: discard not set to true
Tinyblargon Mar 16, 2023
e2022c7
fix: make replicate true by default
Tinyblargon Mar 16, 2023
813adfa
fix: CdRom not properly converted to struct
Tinyblargon Mar 16, 2023
d8cbbdc
fix: missing `Replicate` on `QemuVirtIOPassthrough`
Tinyblargon Mar 17, 2023
8dab836
test: add test for mapping `ConfigQemu.Disks` from Api values
Tinyblargon Mar 17, 2023
c36bc0f
refactor: disk migration
Tinyblargon Mar 18, 2023
fda1d50
fix: format not set when creating and updating disk
Tinyblargon Mar 18, 2023
19a17f6
refactor: format only needs to be set during disk creation
Tinyblargon Mar 19, 2023
670277e
refactor: seperate disk marking logic for mapping logic
Tinyblargon Mar 19, 2023
42f007e
refactor: rename struct
Tinyblargon Mar 20, 2023
b168399
refactor: make `Id` a value that is only returned
Tinyblargon Mar 20, 2023
c04f9e3
test: add test
Tinyblargon Mar 20, 2023
75c1484
test: remove TODO
Tinyblargon Mar 20, 2023
34b6ee8
feat: add custom type and validate func
Tinyblargon Mar 20, 2023
429c0d7
refactor: cahange update flow
Tinyblargon Mar 20, 2023
65996e1
refactor: add new `ConfigQemu{}.Create` func
Tinyblargon Mar 20, 2023
6a66cf1
docs: add comment
Tinyblargon Mar 20, 2023
cebcfff
refactor: move `VmRef` nilCheck to new func
Tinyblargon Mar 23, 2023
0ca2aff
feat: add func for checking if a key exists in an `[]interface{map[st…
Tinyblargon Mar 23, 2023
0304fcc
feat: check if the Qemu guest has pending changes, and reboot if allowed
Tinyblargon Mar 24, 2023
9bc0393
refactor: disks can be enlarged while QemuGuest is live
Tinyblargon Mar 24, 2023
54467a6
Add TODO for CloudInit and basic logic
Tinyblargon Mar 24, 2023
36cb3b6
fix: panic
Tinyblargon Mar 25, 2023
af6fde3
feat: add support for linked clones
Tinyblargon Mar 27, 2023
56d9951
refactor: remove unused option
Tinyblargon Apr 2, 2023
0de34f7
fix: disks get updated when nothing changes
Tinyblargon Apr 2, 2023
d5c4ec3
feat: Add setting for iops burst duration
Tinyblargon Apr 3, 2023
7265307
refactor: rename `Data` to `MBps`
Tinyblargon Apr 3, 2023
131d690
Merge branch 'master' into Overhaul-Qemu-Disks-Merge
Tinyblargon Apr 3, 2023
e2755e4
fix: merge conflicts
Tinyblargon Apr 3, 2023
29ce746
refactor: make `LinkedVmId` part of `ConfigQemu`
Tinyblargon Apr 4, 2023
d941f39
fix: API can return disk size in TerraBytes
Tinyblargon Apr 4, 2023
c11acf1
refactor: change custom type to uint
Tinyblargon Apr 5, 2023
df89185
refactor: use map instad of 2D string array
Tinyblargon Apr 6, 2023
32f91d0
Merge branch 'Telmate:master' into Overhaul-Qemu-Disks-Merge
Tinyblargon May 1, 2023
c8e3d98
Make func private
Tinyblargon May 2, 2023
e185126
Restore Deprecated functions
Tinyblargon May 2, 2023
9fa3565
Remove unused variables
Tinyblargon May 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func (vmr *VmRef) HaGroup() string {
return vmr.haGroup
}

func (vmr *VmRef) nilCheck() error {
if vmr == nil {
return errors.New("vm reference may not be nil")
}
return nil
}

func NewVmRef(vmId int) (vmr *VmRef) {
vmr = &VmRef{vmId: vmId, node: "", vmType: ""}
return
Expand Down Expand Up @@ -703,7 +710,7 @@ func (c *Client) RollbackQemuVm(vmr *VmRef, snapshot string) (exitStatus string,
return RollbackSnapshot(c, vmr, snapshot)
}

// SetVmConfig - send config options
// DEPRECATED SetVmConfig - send config options
func (c *Client) SetVmConfig(vmr *VmRef, params map[string]interface{}) (exitStatus interface{}, err error) {
return c.PostWithTask(params, "/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/config")
}
Expand Down Expand Up @@ -743,6 +750,7 @@ func (c *Client) MigrateNode(vmr *VmRef, newTargetNode string, online bool) (exi
}

// ResizeQemuDisk allows the caller to increase the size of a disk by the indicated number of gigabytes
// TODO Deprecate once LXC is able to resize disk by itself (qemu can already do this)
func (c *Client) ResizeQemuDisk(vmr *VmRef, disk string, moreSizeGB int) (exitStatus interface{}, err error) {
size := fmt.Sprintf("+%dG", moreSizeGB)
return c.ResizeQemuDiskRaw(vmr, disk, size)
Expand All @@ -753,6 +761,7 @@ func (c *Client) ResizeQemuDisk(vmr *VmRef, disk string, moreSizeGB int) (exitSt
// your desired size with a '+' character it will ADD size to the disk. If you just specify the size by
// itself it will do an absolute resizing to the specified size. Permitted suffixes are K, M, G, T
// to indicate order of magnitude (kilobyte, megabyte, etc). Decrease of disk size is not permitted.
// TODO Deprecate once LXC is able to resize disk by itself (qemu can already do this)
func (c *Client) ResizeQemuDiskRaw(vmr *VmRef, disk string, size string) (exitStatus interface{}, err error) {
// PUT
//disk:virtio0
Expand Down Expand Up @@ -793,6 +802,7 @@ func (c *Client) MoveLxcDisk(vmr *VmRef, disk string, storage string) (exitStatu
return
}

// DEPRECATED use MoveQemuDisk() instead.
// MoveQemuDisk - Move a disk from one storage to another
func (c *Client) MoveQemuDisk(vmr *VmRef, disk string, storage string) (exitStatus interface{}, err error) {
if disk == "" {
Expand Down
37 changes: 37 additions & 0 deletions proxmox/config_guest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package proxmox

import (
"strconv"
)

// All code LXC and Qemu have in common should be placed here.

// Check if there are any pending changes that require a reboot to be applied.
func GuestHasPendingChanges(vmr *VmRef, client *Client) (bool, error) {
params, err := pendingGuestConfigFromApi(vmr, client)
if err != nil {
return false, err
}
return keyExists(params, "pending"), nil
}

// Reboot the specified guest
func GuestReboot(vmr *VmRef, client *Client) (err error) {
_, err = client.ShutdownVm(vmr)
if err != nil {
return
}
_, err = client.StartVm(vmr)
return
}

func pendingGuestConfigFromApi(vmr *VmRef, client *Client) ([]interface{}, error) {
err := vmr.nilCheck()
if err != nil {
return nil, err
}
if err = client.CheckVmRef(vmr); err != nil {
return nil, err
}
return client.GetItemConfigInterfaceArray("/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/pending", "Guest", "PENDING CONFIG")
}
Loading