-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduled_tasks.go
145 lines (121 loc) · 3.69 KB
/
scheduled_tasks.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package goarubacloud
import (
"fmt"
"time"
)
const getScheduledOperationsPath = "GetScheduledOperations"
const addScheduledOperationPath = "SetAddServerScheduledOperation"
const updateScheduledOperationPath = "SetUpdateServerScheduledOperation"
const removeScheduledOperationPath = "SetRemoveServerScheduledOperation"
// ScheduledTasksService is an interface for interfacing with the cloud server actions
// endpoints of the Arubacloud API
type ScheduledTasksService interface {
List(*Interval) ([]ScheduledTask, *Response, error)
Add() (*Response, error)
Update(int) (*Response, error)
Delete(int) (*Response, error)
}
// ScheduledTasksServiceOp handles communication with the cloud server action related
// methods of the Arubacloud API.
type ScheduledTasksServiceOp struct {
client *Client
}
var _ ScheduledTasksService = &ScheduledTasksServiceOp{}
type ScheduledTask struct {
ServerId int
ServerName string
OperationType ScheduledTaskType
OperationParameter []interface{}
ScheduledOperationID int
ScheduledPlan ScheduledPlan
}
type ScheduledPlan struct {
FirstExecutionTime string
LastExecutionTime string
ScheduleDaysOfMonth interface{}
ScheduleEndDateTime interface{}
ScheduleFrequency interface{}
ScheduleFrequencyType int
ScheduleOperationLabel string
ScheduleStartDateTime string
ScheduleWeekDays []interface{}
ScheduledMontlyRecurrence interface{}
ScheduledOwnerType int
ScheduledPlanId int
ScheduledPlanStatus int
}
type ScheduledTaskType int
const (
SWITCH_ON ScheduledTaskType = 2
FORCE_SHUTDOWN ScheduledTaskType = 3
SWITCH_OFF ScheduledTaskType = 25
CREATE_SNAPSHOT ScheduledTaskType = 27
RESTORE_SNAPSHOT ScheduledTaskType = 28
DELETE_SNAPSHOT ScheduledTaskType = 29
)
// String returns the name of the Datacenter.
func (m ScheduledTaskType) String() string {
scheduled_task_types := map[ScheduledTaskType]string{
2: "Switch On",
3: "Force Shutdown",
25: "Switch Off",
27: "Create snapshot",
28: "Restore Snapshot",
29: "Delete snapshot",
}
return scheduled_task_types[m]
}
type scheduledTasksRoot struct {
ScheduledTasks []ScheduledTask `json:"Value"`
}
type Interval struct {
StartDate time.Time
EndDate time.Time
}
type ScheduledTaskCreateRequest struct {
ScheduledOperationTypes string
ScheduleOperationLabel string
ServerID int
ScheduleStartDateTime string
ScheduleEndDateTime string
ScheduleFrequencyType string
ScheduledPlanStatus string
ScheduledMontlyRecurrence string
}
type ScheduledTaskUpdateRequest struct {
SetUpdateServerScheduledOperation ScheduledTaskIdCreate `json:"SetUpdateServerScheduledOperation"`
}
type ScheduledTaskIdCreate struct {
ScheduledOperationId int
}
func (s ScheduledTasksServiceOp) List(interval *Interval) ([]ScheduledTask, *Response, error) {
data := struct {
StartDate string
EndDate string
}{
StartDate: fmt.Sprintf("/Date(%d)/", interval.StartDate.Unix()),
EndDate: fmt.Sprintf("/Date(%d)/", interval.EndDate.Unix()),
}
req, err := s.client.NewRequest(getScheduledOperationsPath, data)
if err != nil {
return nil, nil, err
}
root := new(scheduledTasksRoot)
resp, err := s.client.Do(req, root)
if err != nil {
return nil, resp, err
}
return root.ScheduledTasks, resp, err
}
func (s ScheduledTasksServiceOp) Add() (*Response, error) {
// Not implemented yet
return nil, nil
}
func (s ScheduledTasksServiceOp) Update(scheduledOperationId int) (*Response, error) {
// Not implemented yet
return nil, nil
}
func (s ScheduledTasksServiceOp) Delete(scheduledOperationId int) (*Response, error) {
// Not implemented yet
return nil, nil
}