forked from canonical/lxd
/
status.go
68 lines (61 loc) · 1.59 KB
/
status.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
64
65
66
67
68
package shared
type StatusCode int
const (
OperationCreated StatusCode = 100
Started StatusCode = 101
Stopped StatusCode = 102
Running StatusCode = 103
Cancelling StatusCode = 104
Pending StatusCode = 105
Starting StatusCode = 106
Stopping StatusCode = 107
Aborting StatusCode = 108
Freezing StatusCode = 109
Frozen StatusCode = 110
Thawed StatusCode = 111
Error StatusCode = 112
Success StatusCode = 200
Failure StatusCode = 400
Cancelled StatusCode = 401
)
func (o StatusCode) String() string {
return map[StatusCode]string{
OperationCreated: "Operation created",
Started: "Started",
Stopped: "Stopped",
Running: "Running",
Cancelling: "Cancelling",
Pending: "Pending",
Success: "Success",
Failure: "Failure",
Cancelled: "Cancelled",
Starting: "Starting",
Stopping: "Stopping",
Aborting: "Aborting",
Freezing: "Freezing",
Frozen: "Frozen",
Thawed: "Thawed",
Error: "Error",
}[o]
}
func (o StatusCode) IsFinal() bool {
return int(o) >= 200
}
/*
* Create a StatusCode from an lxc.State code. N.B.: we accept an int instead
* of a lxc.State so that the shared code doesn't depend on lxc, which depends
* on liblxc, etc.
*/
func FromLXCState(state int) StatusCode {
return map[int]StatusCode{
1: Stopped,
2: Starting,
3: Running,
4: Stopping,
5: Aborting,
6: Freezing,
7: Frozen,
8: Thawed,
9: Error,
}[state]
}