github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/state/storage_ops.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package state 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/mgo/v3/txn" 9 "github.com/juju/names/v5" 10 ) 11 12 type addStorageForUnitOperation struct { 13 sb *storageBackend 14 u *Unit 15 storageName string 16 storageConstraints StorageConstraints 17 18 // The list of storage tags after a the operation succeeds. 19 tags []names.StorageTag 20 } 21 22 // Build implements ModelOperation. 23 func (op *addStorageForUnitOperation) Build(attempt int) ([]txn.Op, error) { 24 if attempt > 0 { 25 if err := op.u.Refresh(); err != nil { 26 return nil, errors.Annotatef(err, "adding %q storage to %s", op.storageName, op.u) 27 } 28 } 29 30 tags, ops, err := op.sb.addStorageForUnitOps(op.u, op.storageName, op.storageConstraints) 31 if err != nil { 32 return nil, errors.Annotatef(err, "adding %q storage to %s", op.storageName, op.u) 33 } 34 35 op.tags = tags 36 return ops, nil 37 } 38 39 // Done implements ModelOperation. 40 func (op *addStorageForUnitOperation) Done(err error) error { return err }