-
Notifications
You must be signed in to change notification settings - Fork 468
/
Copy pathpool.go
63 lines (55 loc) · 1.9 KB
/
pool.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package libvirt
import (
"context"
"log"
libvirt "github.com/digitalocean/go-libvirt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
)
const (
poolStateConfExists = resourceStateConfExists
poolStateConfNotExists = resourceStateConfNotExists
)
func poolExistsStateRefreshFunc(virConn *libvirt.Libvirt, uuid libvirt.UUID) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
_, err := virConn.StoragePoolLookupByUUID(uuid)
if err != nil {
if isError(err, libvirt.ErrNoStoragePool) {
log.Printf("pool %v does not exist", uuidString(uuid))
return virConn, poolStateConfNotExists, nil
}
return virConn, poolStateConfNotExists, err
}
return virConn, poolStateConfExists, err
}
}
func waitForStatePoolExists(ctx context.Context, virConn *libvirt.Libvirt, uuid libvirt.UUID) error {
log.Printf("Waiting for pool %v to appear...", uuidString(uuid))
stateConf := &retry.StateChangeConf{
Pending: []string{poolStateConfNotExists},
Target: []string{poolStateConfExists},
Refresh: poolExistsStateRefreshFunc(virConn, uuid),
Timeout: resourceStateTimeout,
Delay: resourceStateDelay,
MinTimeout: resourceStateMinTimeout,
}
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}
// waitForStatePoolDeleted waits for a storage pool to be removed.
func waitForStatePoolDeleted(ctx context.Context, virConn *libvirt.Libvirt, uuid libvirt.UUID) error {
log.Printf("waiting for pool %v to be deleted...", uuidString(uuid))
stateConf := &retry.StateChangeConf{
Pending: []string{poolStateConfExists},
Target: []string{poolStateConfNotExists},
Refresh: poolExistsStateRefreshFunc(virConn, uuid),
Timeout: resourceStateTimeout,
Delay: resourceStateDelay,
MinTimeout: resourceStateMinTimeout,
}
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}