Skip to content

Commit

Permalink
lxd/device/disk: Validate profile's device initial configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Din Music <din.music@canonical.com>
  • Loading branch information
MusicDin committed Aug 24, 2023
1 parent 35c00a7 commit 4f7f907
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lxd/device/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,43 @@ func (d *disk) validateConfig(instConf instance.ConfigReader) error {
}
}

// Extract initial configuration from the profile and validate them against appropriate storage driver.
// Currently initial configuration is only applicable to root disk devices.

initialConfig := make(map[string]string)
for k, v := range d.config {
if strings.Contains(k, "initial.") {
newKey := strings.TrimPrefix(k, "initial.")
initialConfig[newKey] = v
}
}

if len(initialConfig) > 0 {
if !shared.IsRootDiskDevice(d.config) {
return fmt.Errorf("Non-root disk device cannot contain initial.* configuration")
}

d.pool, err = storagePools.LoadByName(d.state, d.config["pool"])
if err != nil {
return err
}

// Create temporary volume definition.
vol := storageDrivers.NewVolume(
d.pool.Driver(),
d.pool.Name(),
storageDrivers.VolumeTypeImage,
storageDrivers.ContentTypeFS,
d.name,
initialConfig,
d.pool.Driver().Config())

err := d.pool.Driver().ValidateVolume(vol, false)
if err != nil {
return fmt.Errorf("Invalid initial device configuration: %v", err)
}
}

return nil
}

Expand Down

0 comments on commit 4f7f907

Please sign in to comment.