forked from lusis/go-rundeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
execution.go
126 lines (113 loc) · 4.24 KB
/
execution.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package rundeck
import "encoding/xml"
type Execution struct {
XMLName xml.Name `xml:"execution"`
ID string `xml:"id,attr"`
HRef string `xml:"href,attr"`
Status string `xml:"status,attr"`
Project string `xml:"project,attr"`
User string `xml:"user"`
DateEnded string `xml:"date-ended,omitempty"`
UnixTimeEnded int64 `xml:"date-ended,unixtime,attr,omitempty"`
DateStarted string `xml:"date-started,omitempty"`
UnixTimeStarted int64 `xml:"date-started,unixtime,attr,omitempty"`
Job *Job `xml:"job"`
Description string `xml:"description,omitempty"`
SuccessfulNodes Nodes `xml:"successfulNodes,omitempty"`
FailedNodes Nodes `xml:"failedNodes,omitempty"`
}
type ExecutionDateTime struct {
UnixTime int64 `xml:"unixtime,attr"`
}
type ExecutionOutput struct {
XMLName xml.Name `xml:"output"`
ID int64 `xml:"id"`
Offset int64 `xml:"offset"`
Completed bool `xml:"completed"`
ExecCompleted bool `xml:"execCompleted"`
HasFailedNodes bool `xml:"hasFailedNodes"`
ExecState string `xml:"execState"`
LastModified ExecutionDateTime `xml:"lastModified"`
ExecDuration int64 `xml:"execDuration"`
TotalSize int64 `xml:"totalSize"`
Entries ExecutionOutputEntries `xml:"entries"`
}
type ExecutionOutputEntries struct {
Entry []ExecutionOutputEntry `xml:"entry"`
}
type ExecutionOutputEntry struct {
XMLName xml.Name
Time string `xml:"time,attr"`
AbsoluteTime string `xml:"absolute_time,attr"`
Log string `xml:"log,attr"`
Level string `xml:"level,attr"`
User string `xml:"user,attr"`
Command string `xml:"command,attr"`
Stepctx string `xml:"stepctx,attr"`
Node string `xml:"node,attr"`
}
type ExecutionState struct {
XMLName xml.Name `xml:"result"`
Success bool `xml:"success,attr"`
ApiVersion int64 `xml:"apiversion,attr"`
StartTime string `xml:"executionState>startTime"`
StepCount int64 `xml:"executionState>stepCount"`
AllNodes []Node `xml:"executionState>allNodes>nodes>node,omitempty"`
TargetNodes []Node `xml:"executionState>targetNodes>nodes>node,omitempty"`
ExecutionID int64 `xml:"executionState>executionId"`
Completed bool `xml:"executionState>completed"`
UpdateTime string `xml:"executionState>updateTime,omitempty"`
Steps []ExecutionStep `xml:"executionState>steps>step,omitempty"`
Nodes []NodeWithSteps `xml:"executionState>nodes>node"`
}
type ExecutionAbort struct {
XMLName xml.Name `xml:"abort"`
Status string `xml:"status,attr"`
Execution struct {
HRef string `xml:"href,attr"`
Permalink string `xml:"permalink,attr"`
ID string `xml:"id,attr"`
Status string `xml:"status,attr"`
} `xml:"execution"`
}
func (c *RundeckClient) GetExecution(executionId string) (exec Execution, err error) {
var res []byte
var execs Executions
err = c.Get(&res, "execution/"+executionId, nil)
xmlerr := xml.Unmarshal(res, &execs)
if xmlerr != nil {
return exec, xmlerr
}
return execs.Executions[0], err
}
func (c *RundeckClient) GetExecutionState(executionId string) (ExecutionState, error) {
u := make(map[string]string)
var res []byte
var data ExecutionState
err := c.Get(&res, "execution/"+executionId+"/state", u)
xml.Unmarshal(res, &data)
return data, err
}
func (c *RundeckClient) GetExecutionOutput(executionId string) (ExecutionOutput, error) {
u := make(map[string]string)
var res []byte
var data ExecutionOutput
err := c.Get(&res, "execution/"+executionId+"/output", u)
xml.Unmarshal(res, &data)
return data, err
}
func (c *RundeckClient) DeleteExecution(id string) error {
return c.Delete("execution/"+id, nil)
}
func (c *RundeckClient) AbortExecution(id string) (ExecutionAbort, error) {
var res []byte
var exec ExecutionAbort
err := c.Get(&res, "execution/"+id+"/abort", nil)
if err != nil {
return exec, err
}
if xmlerr := xml.Unmarshal(res, &exec); xmlerr != nil {
return exec, xmlerr
}
return exec, nil
}