MCPcopy
hub / github.com/lxc/incus / updateVolumeDescriptionOnly

Method updateVolumeDescriptionOnly

internal/server/storage/backend.go:4231–4281  ·  view source on GitHub ↗

updateVolumeDescriptionOnly is a helper function used when handling update requests for volumes that only allow their descriptions to be updated. If any config supplied differs from the current volume's config then an error is returned.

(projectName string, volName string, volType drivers.VolumeType, newDesc string, newConfig map[string]string, op *operations.Operation)

Source from the content-addressed store, hash-verified

4229// that only allow their descriptions to be updated. If any config supplied differs from the
4230// current volume's config then an error is returned.
4231func (b *backend) updateVolumeDescriptionOnly(projectName string, volName string, volType drivers.VolumeType, newDesc string, newConfig map[string]string, op *operations.Operation) error {
4232 volDBType, err := VolumeTypeToDBType(volType)
4233 if err != nil {
4234 return err
4235 }
4236
4237 // Get current config to compare what has changed.
4238 curVol, err := VolumeDBGet(b, projectName, volName, volType)
4239 if err != nil {
4240 return err
4241 }
4242
4243 if newConfig != nil {
4244 changedConfig, _ := b.detectChangedConfig(curVol.Config, newConfig)
4245 if len(changedConfig) != 0 {
4246 return errors.New("Volume config is not editable")
4247 }
4248 }
4249
4250 // Update the database if description changed. Use current config.
4251 if newDesc != curVol.Description {
4252 err = b.state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
4253 return tx.UpdateStoragePoolVolume(ctx, projectName, volName, volDBType, b.ID(), newDesc, curVol.Config)
4254 })
4255 if err != nil {
4256 return err
4257 }
4258 }
4259
4260 // Get content type.
4261 dbContentType, err := VolumeContentTypeNameToContentType(curVol.ContentType)
4262 if err != nil {
4263 return err
4264 }
4265
4266 contentType, err := VolumeDBContentTypeToContentType(dbContentType)
4267 if err != nil {
4268 return err
4269 }
4270
4271 // Validate config.
4272 vol := b.GetVolume(drivers.VolumeType(curVol.Type), contentType, volName, newConfig)
4273
4274 if !vol.IsSnapshot() {
4275 b.state.Events.SendLifecycle(projectName, lifecycle.StorageVolumeUpdated.Event(vol, string(vol.Type()), projectName, op, nil))
4276 } else {
4277 b.state.Events.SendLifecycle(projectName, lifecycle.StorageVolumeSnapshotUpdated.Event(vol, string(vol.Type()), projectName, op, nil))
4278 }
4279
4280 return nil
4281}
4282
4283// UpdateImage updates image config.
4284func (b *backend) UpdateImage(fingerprint, newDesc string, newConfig map[string]string, op *operations.Operation) error {

Callers 2

UpdateImageMethod · 0.95

Calls 14

detectChangedConfigMethod · 0.95
IDMethod · 0.95
GetVolumeMethod · 0.95
VolumeTypeTypeAlias · 0.92
VolumeTypeToDBTypeFunction · 0.85
VolumeDBGetFunction · 0.85
SendLifecycleMethod · 0.80
IsSnapshotMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected