Skip to content

Commit

Permalink
Add mahine Power On/Off Operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin120 committed Dec 21, 2023
1 parent 9a315a9 commit 9948340
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ type Machine interface {
Lock(systemID string, comment string) (*entity.Machine, error)
ClearDefaultGateways(systemID string) (*entity.Machine, error)
GetPowerParameters(systemID string) (map[string]interface{}, error)
PowerOn(systemID string) (*entity.Machine, error)
PowerOff(systemID string) (*entity.Machine, error)
GetPowerState(systemID string) (*entity.MachinePowerState, error)
}
27 changes: 27 additions & 0 deletions client/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,30 @@ func (m *Machine) GetPowerParameters(systemID string) (map[string]interface{}, e

return params, err
}

// PowerOn machine
func (m *Machine) PowerOn(systemID string) (*entity.Machine, error) {
machine := new(entity.Machine)
err := m.client(systemID).Post("power_on", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, machine)
})
return machine, err

Check failure on line 141 in client/machine.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

// PowerOff machine
func (m *Machine) PowerOff(systemID string) (*entity.Machine, error) {
machine := new(entity.Machine)
err := m.client(systemID).Post("power_off", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, machine)
})
return machine, err

Check failure on line 150 in client/machine.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

// GetPowerState of the machine
func (m *Machine) GetPowerState(systemID string) (*entity.MachinePowerState, error) {
ps := new(entity.MachinePowerState)
err := m.client(systemID).Get("query_power_state", url.Values{}, func(data []byte) error {
return json.Unmarshal(data, ps)
})
return ps, err

Check failure on line 159 in client/machine.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}
5 changes: 5 additions & 0 deletions entity/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ type MachineServiceSet struct {
StatusInfo string `json:"status_info,omitempty"`
}

// MachinePowerState represent current machines power state
type MachinePowerState struct {
State string `json:"state,omitempty"`
}

// MachineParams enumerates the parameters for the machine update operation
type MachineParams struct {
PowerType string `url:"power_type,omitempty"`
Expand Down

0 comments on commit 9948340

Please sign in to comment.