...

Source file src/edge-infra.dev/pkg/sds/interlock/topic/host/kpower_payloads.go

Documentation: edge-infra.dev/pkg/sds/interlock/topic/host

     1  package host
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  type IPayload interface {
     8  	updateState(*State)
     9  }
    10  
    11  type postKpowerPayload struct {
    12  	OpType    OperationType `json:"type" binding:"required,oneof=REBOOT SHUTDOWN"`
    13  	Opts      Options       `json:"options"`
    14  	RequestID string
    15  }
    16  
    17  func (payload *postKpowerPayload) updateState(hostState *State) {
    18  	hostState.Kpower.Op.OpType = payload.OpType
    19  	hostState.Kpower.Op.Opts = payload.Opts
    20  	hostState.Kpower.Op.RequestID = payload.RequestID
    21  }
    22  
    23  type putKpowerPayload struct {
    24  	Status    PowerStatus `json:"status" binding:"required,oneof=RUNNING CORDONED DRAINED TERMINATED"`
    25  	Op        Operation   `json:"operation"`
    26  	Timestamp time.Time   `json:"timestamp,omitempty" time_format:"2006-01-02T15:04:05Z"`
    27  }
    28  
    29  func (payload *putKpowerPayload) updateState(hostState *State) {
    30  	timestamp := payload.Timestamp
    31  	if timestamp.IsZero() {
    32  		timestamp = time.Now()
    33  	}
    34  
    35  	hostState.Kpower.Status = payload.Status
    36  	hostState.Kpower.Timestamp = timestamp.Format(time.RFC3339)
    37  }
    38  

View as plain text