Debian Codegraph @

api/block/v1alpha1/snapshot_utils.go

raw symbols SCIP
1 package blockscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/
2
3 import (
4 "timescip-go gomod github.com/golang/go/src go1.17 time/"
5
6 "github.com/scaleway/scaleway-sdk-go/errorsscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/errors`/"
7 "github.com/scaleway/scaleway-sdk-go/internal/asyncscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/"
8 "github.com/scaleway/scaleway-sdk-go/scwscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/scw`/"
9 )
10
11 // WaitForSnapshotRequest is used by WaitForSnapshot method.
12 type WaitForSnapshotRequestscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest# struct {
13 SnapshotIDscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#SnapshotID. string
14 Zonescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#Zone. scwscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/scw`/.Zonescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/scw`/Zone#
15 Timeoutscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#Timeout. *timescip-go gomod github.com/golang/go/src go1.17 time/.Durationscip-go gomod github.com/golang/go/src go1.17 time/Duration#
16 RetryIntervalscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#RetryInterval. *timescip-go gomod github.com/golang/go/src go1.17 time/.Durationscip-go gomod github.com/golang/go/src go1.17 time/Duration#
17
18 // If set, will wait until this specific status has been reached or the
19 // snapshot has an error status. This is useful when we need to wait for
20 // the snapshot to transition from "in_use" to "available".
21 TerminalStatusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#TerminalStatus. *SnapshotStatusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatus#
22 }
23
24 // WaitForSnapshot wait for the snapshot to be in a "terminal state" before returning.
25 func (s *APIscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/API#) WaitForSnapshotscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/API#WaitForSnapshot().(req *WaitForSnapshotRequestscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#, opts ...scwscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/scw`/.RequestOptionscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/scw`/RequestOption#) (*Snapshotscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/Snapshot#, error) {
26 timeout := defaultTimeoutscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/defaultTimeout.
27 if req.Timeoutscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#Timeout. != nil {
28 timeout = *req.Timeoutscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#Timeout.
29 }
30 retryInterval := defaultRetryIntervalscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/defaultRetryInterval.
31 if req.RetryIntervalscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#RetryInterval. != nil {
32 retryInterval = *req.RetryIntervalscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#RetryInterval.
33 }
34
35 terminalStatus := map[SnapshotStatusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatus#]struct{}{
36 SnapshotStatusErrorscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatusError.: {},
37 SnapshotStatusLockedscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatusLocked.: {},
38 SnapshotStatusDeletedscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatusDeleted.: {},
39 }
40
41 if req.TerminalStatusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#TerminalStatus. != nil {
42 terminalStatus[*req.TerminalStatusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#TerminalStatus.] = struct{}{}
43 } else {
44 terminalStatus[SnapshotStatusAvailablescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatusAvailable.] = struct{}{}
45 terminalStatus[SnapshotStatusInUsescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/SnapshotStatusInUse.] = struct{}{}
46 }
47
48 snapshot, err := asyncscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/.WaitSyncscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/WaitSync().(&asyncscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/.WaitSyncConfigscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/WaitSyncConfig#{
49 Getscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/WaitSyncConfig#Get.: func() (interface{}, bool, error) {
50 res, err := s.GetSnapshotscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/API#GetSnapshot().(&GetSnapshotRequestscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/GetSnapshotRequest#{
51 SnapshotIDscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/GetSnapshotRequest#SnapshotID.: req.SnapshotIDscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#SnapshotID.,
52 Zonescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/GetSnapshotRequest#Zone.: req.Zonescip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/WaitForSnapshotRequest#Zone.,
53 }, opts...)
54 if err != nil {
55 return nil, false, err
56 }
57 _, isTerminal := terminalStatus[res.Statusscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/Snapshot#Status.]
58
59 return res, isTerminal, err
60 },
61 Timeoutscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/WaitSyncConfig#Timeout.: timeout,
62 IntervalStrategyscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/WaitSyncConfig#IntervalStrategy.: asyncscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/.LinearIntervalStrategyscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/internal/async`/LinearIntervalStrategy().(retryInterval),
63 })
64 if err != nil {
65 return nil, errorsscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/errors`/.Wrapscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/errors`/Wrap().(err, "waiting for snapshot failed")
66 }
67 return snapshot.(*Snapshotscip-go gomod github.com/scaleway/scaleway-sdk-go . `github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1`/Snapshot#), nil
68 }