forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.go
149 lines (129 loc) · 4.65 KB
/
schedule.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
146
147
148
149
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"reflect"
"github.com/stmcginnis/gofish/common"
)
// DayOfWeek is the days of the week.
type DayOfWeek string
const (
// MondayDayOfWeek Monday.
MondayDayOfWeek DayOfWeek = "Monday"
// TuesdayDayOfWeek Tuesday.
TuesdayDayOfWeek DayOfWeek = "Tuesday"
// WednesdayDayOfWeek Wednesday.
WednesdayDayOfWeek DayOfWeek = "Wednesday"
// ThursdayDayOfWeek Thursday.
ThursdayDayOfWeek DayOfWeek = "Thursday"
// FridayDayOfWeek Friday.
FridayDayOfWeek DayOfWeek = "Friday"
// SaturdayDayOfWeek Saturday.
SaturdayDayOfWeek DayOfWeek = "Saturday"
// SundayDayOfWeek Sunday.
SundayDayOfWeek DayOfWeek = "Sunday"
// EveryDayOfWeek shall be the only member in the array.
EveryDayOfWeek DayOfWeek = "Every"
)
// MonthOfYear is the months of the year.
type MonthOfYear string
const (
// JanuaryMonthOfYear January.
JanuaryMonthOfYear MonthOfYear = "January"
// FebruaryMonthOfYear February.
FebruaryMonthOfYear MonthOfYear = "February"
// MarchMonthOfYear March.
MarchMonthOfYear MonthOfYear = "March"
// AprilMonthOfYear April.
AprilMonthOfYear MonthOfYear = "April"
// MayMonthOfYear May.
MayMonthOfYear MonthOfYear = "May"
// JuneMonthOfYear June.
JuneMonthOfYear MonthOfYear = "June"
// JulyMonthOfYear July.
JulyMonthOfYear MonthOfYear = "July"
// AugustMonthOfYear August.
AugustMonthOfYear MonthOfYear = "August"
// SeptemberMonthOfYear September.
SeptemberMonthOfYear MonthOfYear = "September"
// OctoberMonthOfYear October.
OctoberMonthOfYear MonthOfYear = "October"
// NovemberMonthOfYear November.
NovemberMonthOfYear MonthOfYear = "November"
// DecemberMonthOfYear December.
DecemberMonthOfYear MonthOfYear = "December"
// EveryMonthOfYear shall be the only member in the array.
EveryMonthOfYear MonthOfYear = "Every"
)
// Schedule shall schedule a series of occurrences.
type Schedule struct {
common.Entity
// EnabledDaysOfMonth shall contain the days of the month when scheduled occurrences are enabled, for enabled days
// of week and months of year. If the array contains a single value of '0', or if the property is not present, all
// days of the month shall be enabled.
EnabledDaysOfMonth []int
// EnabledDaysOfWeek shall be enabled.
EnabledDaysOfWeek []DayOfWeek
// EnabledIntervals shall be an ISO 8601 conformant interval specifying when occurrences are enabled.
EnabledIntervals []string
// EnabledMonthsOfYear shall contain the months of the year when scheduled occurrences are enabled, for enabled
// days of week and days of month. If not present, all months of the year shall be enabled.
EnabledMonthsOfYear []MonthOfYear
// InitialStartTime shall contain the date and time when the initial occurrence is scheduled to occur.
InitialStartTime string
// Lifetime shall contain a Redfish Duration that describes the time after provisioning when the schedule expires.
Lifetime string
// MaxOccurrences shall contain the maximum number of scheduled occurrences.
MaxOccurrences int
// RecurrenceInterval shall contain the duration between consecutive occurrences.
RecurrenceInterval string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
// UnmarshalJSON unmarshals a Schedule object from the raw JSON.
func (schedule *Schedule) UnmarshalJSON(b []byte) error {
type temp Schedule
var t struct {
temp
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*schedule = Schedule(t.temp)
// Extract the links to other entities for later
// This is a read/write object, so we need to save the raw object data for later
schedule.rawData = b
return nil
}
// Update commits updates to this object's properties to the running system.
func (schedule *Schedule) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Schedule)
original.UnmarshalJSON(schedule.rawData)
readWriteFields := []string{
"EnabledDaysOfMonth",
"EnabledDaysOfWeek",
"EnabledIntervals",
"EnabledMonthsOfYear",
"InitialStartTime",
"Lifetime",
"MaxOccurrences",
"RecurrenceInterval",
}
originalElement := reflect.ValueOf(original).Elem()
currentElement := reflect.ValueOf(schedule).Elem()
return schedule.Entity.Update(originalElement, currentElement, readWriteFields)
}
// GetSchedule will get a Schedule instance from the service.
func GetSchedule(c common.Client, uri string) (*Schedule, error) {
return common.GetObject[Schedule](c, uri)
}
// ListReferencedSchedules gets the collection of Schedule from
// a provided reference.
func ListReferencedSchedules(c common.Client, link string) ([]*Schedule, error) {
return common.GetCollectionObjects[Schedule](c, link)
}