forked from stmcginnis/gofish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobservice.go
91 lines (78 loc) · 2.63 KB
/
jobservice.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
//
// SPDX-License-Identifier: BSD-3-Clause
//
package redfish
import (
"encoding/json"
"time"
"github.com/stmcginnis/gofish/common"
)
// JobServiceCapabilities shall contain properties that describe the
// capabilities or supported features of this implementation of a job service.
type JobServiceCapabilities struct {
// MaxJobs shall contain the maximum number of jobs supported by the
// implementation.
MaxJobs int
// MaxSteps shall contain the maximum number of steps supported by a
// single job instance.
MaxSteps int
// Scheduling shall indicate whether the Schedule property within the job
// supports scheduling of jobs.
Scheduling bool
}
// JobService shall represent a job service for a Redfish implementation.
type JobService struct {
common.Entity
// ODataContext is the odata context.
ODataContext string `json:"@odata.context"`
// ODataType is the odata type.
ODataType string `json:"@odata.type"`
// DateTime shall contain the current date and time setting for the job
// service.
DateTime time.Time
// Description provides a description of this resource.
Description string
// jobs shall contain a link to a resource collection of type JobCollection.
jobs string
// log shall contain a link to a resource of type LogService that this
// job service uses.
log string
// ServiceCapabilities shall contain properties that describe the
// capabilities or supported features of this implementation of a job
// service.
ServiceCapabilities JobServiceCapabilities
// ServiceEnabled shall indicate whether this service is enabled.
ServiceEnabled bool
// Status shall contain any status or health properties of the resource.
Status common.Status
}
// UnmarshalJSON unmarshals a JobService object from the raw JSON.
func (jobservice *JobService) UnmarshalJSON(b []byte) error {
type temp JobService
var t struct {
temp
Jobs common.Link
Log common.Link
}
err := json.Unmarshal(b, &t)
if err != nil {
return err
}
*jobservice = JobService(t.temp)
// Extract the links to other entities for later
jobservice.jobs = t.Jobs.String()
jobservice.log = t.Log.String()
return nil
}
// GetJobService will get a JobService instance from the service.
func GetJobService(c common.Client, uri string) (*JobService, error) {
return common.GetObject[JobService](c, uri)
}
// Jobs gets the collection of jobs of this job service
func (jobservice *JobService) Jobs() ([]*Job, error) {
return ListReferencedJobs(jobservice.GetClient(), jobservice.jobs)
}
// Log gets the LogService instance for this job service
func (jobservice *JobService) Log() (*LogService, error) {
return GetLogService(jobservice.GetClient(), jobservice.log)
}