Skip to content

Commit

Permalink
update reboot command (#14)
Browse files Browse the repository at this point in the history
* update reboot command

* update subcomponents var
  • Loading branch information
prinikasn authored Oct 12, 2023
1 parent 163c614 commit 4b7a79d
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,47 +155,43 @@ func (p *PingOperation) Execute(ctx context.Context, c *internal.Clients) ([]*sp

// RebootOperation represents the parameters of a Reboot operation.
type RebootOperation struct {
rebootMethod spb.RebootMethod
delay time.Duration
message string
subcomponents []*tpb.Path
force bool
req *spb.RebootRequest
ignoreUnavailableErr bool
waitForActive bool
}

// NewRebootOperation creates an empty RebootOperation.
func NewRebootOperation() *RebootOperation {
return &RebootOperation{}
return &RebootOperation{req: &spb.RebootRequest{}}
}

// RebootMethod specifies method to reboot.
func (r *RebootOperation) RebootMethod(rebootMethod spb.RebootMethod) *RebootOperation {
r.rebootMethod = rebootMethod
r.req.Method = rebootMethod
return r
}

// Delay specifies time in nanoseconds to wait before issuing reboot.
func (r *RebootOperation) Delay(delay time.Duration) *RebootOperation {
r.delay = delay
r.req.Delay = uint64(delay.Nanoseconds())
return r
}

// Message specifies informational reason for the reboot or cancel reboot.
func (r *RebootOperation) Message(message string) *RebootOperation {
r.message = message
r.req.Message = message
return r
}

// Subcomponents specifies the sub-components to reboot.
func (r *RebootOperation) Subcomponents(subcomponents []*tpb.Path) *RebootOperation {
r.subcomponents = subcomponents
r.req.Subcomponents = subcomponents
return r
}

// Force reboot if sanity checks fail.
func (r *RebootOperation) Force(force bool) *RebootOperation {
r.force = force
r.req.Force = force
return r
}

Expand All @@ -213,21 +209,15 @@ func (r *RebootOperation) WaitForActive(waitForActive bool) *RebootOperation {

// Execute performs the Reboot operation and will wait for rebootStatus to be active if waitForActive is set to true.
func (r *RebootOperation) Execute(ctx context.Context, c *internal.Clients) (*spb.RebootResponse, error) {
resp, err := c.System().Reboot(ctx, &spb.RebootRequest{
Method: r.rebootMethod,
Delay: uint64(r.delay.Nanoseconds()),
Message: r.message,
Subcomponents: r.subcomponents,
Force: r.force,
})
resp, err := c.System().Reboot(ctx, r.req)

if err != nil {
return nil, err
}

if r.waitForActive {
for {
rebootStatus, statusErr := c.System().RebootStatus(ctx, &spb.RebootStatusRequest{Subcomponents: r.subcomponents})
rebootStatus, statusErr := c.System().RebootStatus(ctx, &spb.RebootStatusRequest{Subcomponents: r.req.GetSubcomponents()})
var waitTime time.Duration

switch {
Expand Down

0 comments on commit 4b7a79d

Please sign in to comment.