forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskervice.go
67 lines (56 loc) · 1.81 KB
/
taskervice.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"time"
"github.com/stmcginnis/gofish/common"
)
// TaskService is used to represent the task service offered by the redfish API
type TaskService struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// Description provides a description of this resource.
Description string
// CompletedTaskOverWritePolicy how to handle the completed tasks.
CompletedTaskOverWritePolicy string
// DateTime system time.
DateTime time.Time
// LifeCycleEventOnTaskStateChange whether an event is reported when the task status is changed.
LifeCycleEventOnTaskStateChange bool
// ServiceEnabled indicates whether this service isenabled.
ServiceEnabled bool
// Status describes the status and health of a resource and its children.
Status common.Status
// tasks points towards the tasks store endpoint
tasks string
}
// UnmarshalJSON unmarshals a TaskService object from the raw JSON.
func (taskService *TaskService) UnmarshalJSON(b []byte) error {
type temp TaskService
var t struct {
temp
Tasks common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
// Extract the links to other entities for later
*taskService = TaskService(t.temp)
taskService.tasks = t.Tasks.String()
return nil
}
// GetTaskService will get a TaskService instance from the service.
func GetTaskService(c common.Client, uri string) (*TaskService, error) {
var taskService TaskService
return &taskService, taskService.Get(c, uri, &taskService)
}
// Tasks gets the collection of tasks of this task service
func (taskService *TaskService) Tasks() ([]*Task, error) {
return ListReferencedTasks(taskService.Client, taskService.tasks)
}