Skip to content

Commit

Permalink
Merge pull request #277 from riverar/rafael/efidisk
Browse files Browse the repository at this point in the history
Add efidisk support to qemu config
  • Loading branch information
mleone87 committed Dec 6, 2023
2 parents 8b021db + 6f3ba46 commit 2ff04fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,15 @@ func (ConfigQemu) mapToStruct(params map[string]interface{}) (*ConfigQemu, error
}
}

// efidisk
if efidisk, isSet := params["efidisk0"].(string); isSet {
efiDiskConfMap := ParsePMConf(efidisk, "volume")
storageName, fileName := ParseSubConf(efiDiskConfMap["volume"].(string), ":")
efiDiskConfMap["storage"] = storageName
efiDiskConfMap["file"] = fileName
config.EFIDisk = efiDiskConfMap
}

return &config, nil
}

Expand Down Expand Up @@ -1208,7 +1217,26 @@ func NewConfigQemuFromApi(vmr *VmRef, client *Client) (config *ConfigQemu, err e
if err != nil {
return
}

if config.EFIDisk != nil {
storageContent, err := client.GetStorageContent(vmr, config.EFIDisk["storage"].(string))
if err != nil {
log.Fatal(err)
return nil, err
}

contents := storageContent["data"].([]interface{})
for content := range contents {
storageContentMap := contents[content].(map[string]interface{})
if storageContentMap["volid"] == config.EFIDisk["volume"].(string) {
config.EFIDisk["format"] = storageContentMap["format"].(string)
break
}
}
}

config.defaults()

// HAstate is return by the api for a vm resource type but not the HAgroup
err = client.ReadVMHA(vmr)
if err == nil {
Expand Down
11 changes: 11 additions & 0 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4503,6 +4503,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
}}}},
},
},
// EFI
{name: "EFI Disk",
input: map[string]interface{}{"efidisk0": "local-lvm:vm-1000-disk-0,efitype=2m,size=4M"},
output: &ConfigQemu{EFIDisk: map[string]interface{}{
"efitype": "2m",
"size": "4M",
"storage": "local-lvm",
"file": "vm-1000-disk-0",
"volume": "local-lvm:vm-1000-disk-0",
}},
},
}
for _, test := range tests {
t.Run(test.name, func(*testing.T) {
Expand Down

0 comments on commit 2ff04fa

Please sign in to comment.