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