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

Feature: QemuDisk-WWN #270

Merged
merged 4 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 25 additions & 3 deletions proxmox/config_qemu_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ type qemuDisk struct {
Serial QemuDiskSerial
Size uint
// TODO custom type
Storage string // Only set for Disk
Type qemuDiskType
Storage string // Only set for Disk
Type qemuDiskType
WorldWideName QemuWorldWideName
}

const (
Expand Down Expand Up @@ -288,7 +289,9 @@ func (disk qemuDisk) mapToApiValues(vmID, LinkedVmId uint, currentStorage string
if disk.Type != virtIO && disk.EmulateSSD {
settings = settings + ",ssd=1"
}

if disk.WorldWideName != "" {
settings = settings + ",wwn=" + string(disk.WorldWideName)
}
return
}

Expand Down Expand Up @@ -418,6 +421,9 @@ func (qemuDisk) mapToStruct(diskData string, settings map[string]interface{}, li
if value, isSet := settings["ssd"]; isSet {
disk.EmulateSSD, _ = strconv.ParseBool(value.(string))
}
if value, isSet := settings["wwn"]; isSet {
disk.WorldWideName = QemuWorldWideName(value.(string))
}
return &disk
}

Expand All @@ -437,6 +443,9 @@ func (disk *qemuDisk) validate() (err error) {
if err = disk.Serial.Validate(); err != nil {
return
}
if err = disk.WorldWideName.Validate(); err != nil {
return
}
if disk.Disk {
// disk
if err = disk.Format.Validate(); err != nil {
Expand Down Expand Up @@ -1008,6 +1017,19 @@ type qemuUpdateChanges struct {
Resize []qemuDiskResize
}

type QemuWorldWideName string

const Error_QemuWorldWideName_Invalid string = "world wide name should be prefixed with 0x followed by 8 hexadecimal values"

var regexp_QemuWorldWideName = regexp.MustCompile(`^0x[0-9A-Fa-f]{16}$`)

func (wwn QemuWorldWideName) Validate() error {
if wwn == "" || regexp_QemuWorldWideName.MatchString(string(wwn)) {
return nil
}
return errors.New(Error_QemuWorldWideName_Invalid)
}

func diskSubtypeSet(set bool) error {
if set {
return errors.New(Error_QemuDisk_MutuallyExclusive)
Expand Down
148 changes: 77 additions & 71 deletions proxmox/config_qemu_disk_ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,40 @@ import (
)

type QemuIdeDisk struct {
AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"`
Backup bool `json:"backup"`
Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"`
Cache QemuDiskCache `json:"cache,omitempty"`
Discard bool `json:"discard"`
EmulateSSD bool `json:"emulatessd"`
Format QemuDiskFormat `json:"format"`
Id uint `json:"id"` //Id is only returned and setting it has no effect
LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect
Replicate bool `json:"replicate"`
Serial QemuDiskSerial `json:"serial,omitempty"`
Size uint `json:"size"`
Storage string `json:"storage"`
AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"`
Backup bool `json:"backup"`
Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"`
Cache QemuDiskCache `json:"cache,omitempty"`
Discard bool `json:"discard"`
EmulateSSD bool `json:"emulatessd"`
Format QemuDiskFormat `json:"format"`
Id uint `json:"id"` //Id is only returned and setting it has no effect
LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect
Replicate bool `json:"replicate"`
Serial QemuDiskSerial `json:"serial,omitempty"`
Size uint `json:"size"`
Storage string `json:"storage"`
WorldWideName QemuWorldWideName `json:"wwn"`
}

func (disk *QemuIdeDisk) convertDataStructure() *qemuDisk {
return &qemuDisk{
AsyncIO: disk.AsyncIO,
Backup: disk.Backup,
Bandwidth: disk.Bandwidth,
Cache: disk.Cache,
Discard: disk.Discard,
Disk: true,
EmulateSSD: disk.EmulateSSD,
Format: disk.Format,
Id: disk.Id,
LinkedDiskId: disk.LinkedDiskId,
Replicate: disk.Replicate,
Serial: disk.Serial,
Size: disk.Size,
Storage: disk.Storage,
Type: ide,
AsyncIO: disk.AsyncIO,
Backup: disk.Backup,
Bandwidth: disk.Bandwidth,
Cache: disk.Cache,
Discard: disk.Discard,
Disk: true,
EmulateSSD: disk.EmulateSSD,
Format: disk.Format,
Id: disk.Id,
LinkedDiskId: disk.LinkedDiskId,
Replicate: disk.Replicate,
Serial: disk.Serial,
Size: disk.Size,
Storage: disk.Storage,
Type: ide,
WorldWideName: disk.WorldWideName,
}
}

Expand Down Expand Up @@ -135,30 +137,32 @@ func (disks QemuIdeDisks) validate() (numberOfCloudInitDevices uint8, err error)
}

type QemuIdePassthrough struct {
AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"`
Backup bool `json:"backup"`
Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"`
Cache QemuDiskCache `json:"cache,omitempty"`
Discard bool `json:"discard"`
EmulateSSD bool `json:"emulatessd"`
File string `json:"file"`
Replicate bool `json:"replicate"`
Serial QemuDiskSerial `json:"serial,omitempty"`
Size uint `json:"size"` //size is only returned and setting it has no effect
AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"`
Backup bool `json:"backup"`
Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"`
Cache QemuDiskCache `json:"cache,omitempty"`
Discard bool `json:"discard"`
EmulateSSD bool `json:"emulatessd"`
File string `json:"file"`
Replicate bool `json:"replicate"`
Serial QemuDiskSerial `json:"serial,omitempty"`
Size uint `json:"size"` //size is only returned and setting it has no effect
WorldWideName QemuWorldWideName `json:"wwn"`
}

func (passthrough *QemuIdePassthrough) convertDataStructure() *qemuDisk {
return &qemuDisk{
AsyncIO: passthrough.AsyncIO,
Backup: passthrough.Backup,
Bandwidth: passthrough.Bandwidth,
Cache: passthrough.Cache,
Discard: passthrough.Discard,
EmulateSSD: passthrough.EmulateSSD,
File: passthrough.File,
Replicate: passthrough.Replicate,
Serial: passthrough.Serial,
Type: ide,
AsyncIO: passthrough.AsyncIO,
Backup: passthrough.Backup,
Bandwidth: passthrough.Bandwidth,
Cache: passthrough.Cache,
Discard: passthrough.Discard,
EmulateSSD: passthrough.EmulateSSD,
File: passthrough.File,
Replicate: passthrough.Replicate,
Serial: passthrough.Serial,
Type: ide,
WorldWideName: passthrough.WorldWideName,
}
}

Expand Down Expand Up @@ -225,32 +229,34 @@ func (QemuIdeStorage) mapToStruct(param string, LinkedVmId *uint) *QemuIdeStorag
}
if tmpDisk.File == "" {
return &QemuIdeStorage{Disk: &QemuIdeDisk{
AsyncIO: tmpDisk.AsyncIO,
Backup: tmpDisk.Backup,
Bandwidth: tmpDisk.Bandwidth,
Cache: tmpDisk.Cache,
Discard: tmpDisk.Discard,
EmulateSSD: tmpDisk.EmulateSSD,
Format: tmpDisk.Format,
Id: tmpDisk.Id,
LinkedDiskId: tmpDisk.LinkedDiskId,
Replicate: tmpDisk.Replicate,
Serial: tmpDisk.Serial,
Size: tmpDisk.Size,
Storage: tmpDisk.Storage,
AsyncIO: tmpDisk.AsyncIO,
Backup: tmpDisk.Backup,
Bandwidth: tmpDisk.Bandwidth,
Cache: tmpDisk.Cache,
Discard: tmpDisk.Discard,
EmulateSSD: tmpDisk.EmulateSSD,
Format: tmpDisk.Format,
Id: tmpDisk.Id,
LinkedDiskId: tmpDisk.LinkedDiskId,
Replicate: tmpDisk.Replicate,
Serial: tmpDisk.Serial,
Size: tmpDisk.Size,
Storage: tmpDisk.Storage,
WorldWideName: tmpDisk.WorldWideName,
}}
}
return &QemuIdeStorage{Passthrough: &QemuIdePassthrough{
AsyncIO: tmpDisk.AsyncIO,
Backup: tmpDisk.Backup,
Bandwidth: tmpDisk.Bandwidth,
Cache: tmpDisk.Cache,
Discard: tmpDisk.Discard,
EmulateSSD: tmpDisk.EmulateSSD,
File: tmpDisk.File,
Replicate: tmpDisk.Replicate,
Serial: tmpDisk.Serial,
Size: tmpDisk.Size,
AsyncIO: tmpDisk.AsyncIO,
Backup: tmpDisk.Backup,
Bandwidth: tmpDisk.Bandwidth,
Cache: tmpDisk.Cache,
Discard: tmpDisk.Discard,
EmulateSSD: tmpDisk.EmulateSSD,
File: tmpDisk.File,
Replicate: tmpDisk.Replicate,
Serial: tmpDisk.Serial,
Size: tmpDisk.Size,
WorldWideName: tmpDisk.WorldWideName,
}}
}

Expand Down
Loading