diff --git a/api/machine.go b/api/machine.go index 4cd3930..6fcf086 100644 --- a/api/machine.go +++ b/api/machine.go @@ -13,10 +13,17 @@ type Machine interface { Deploy(systemID string, params *entity.MachineDeployParams) (*entity.Machine, error) Release(systemID string, params *entity.MachineReleaseParams) (*entity.Machine, error) Lock(systemID string, comment string) (*entity.Machine, error) + Unlock(systemID string, comment string) (*entity.Machine, error) ClearDefaultGateways(systemID string) (*entity.Machine, error) GetPowerParameters(systemID string) (map[string]interface{}, error) PowerOn(systemID string, params *entity.MachinePowerOnParams) (*entity.Machine, error) PowerOff(systemID string, params *entity.MachinePowerOffParams) (*entity.Machine, error) GetPowerState(systemID string) (*entity.MachinePowerState, error) SetWorkloadAnnotations(systemID string, params map[string]string) (*entity.Machine, error) + RescueMode(systemID string) (*entity.Machine, error) + ExitRescueMode(systemID string) (*entity.Machine, error) + Abort(systemID string, comment string) (*entity.Machine, error) + MarkBroken(systemID string, comment string) (*entity.Machine, error) + MarkFixed(systemID string, comment string) (*entity.Machine, error) + GetToken(systemID string) (*entity.MachineToken, error) } diff --git a/api/machines.go b/api/machines.go index e06a8c4..f6a36cf 100644 --- a/api/machines.go +++ b/api/machines.go @@ -12,4 +12,5 @@ type Machines interface { Allocate(params *entity.MachineAllocateParams) (*entity.Machine, error) AcceptAll() error Release(systemID []string, comment string) error + ListAllocated() ([]entity.Machine, error) } diff --git a/client/machine.go b/client/machine.go index 190b669..cb427ff 100644 --- a/client/machine.go +++ b/client/machine.go @@ -112,6 +112,21 @@ func (m *Machine) Lock(systemID string, comment string) (*entity.Machine, error) return machine, err } +// Unlock marks a machine as ‘Unlocked’, to allow changes +func (m *Machine) Unlock(systemID string, comment string) (*entity.Machine, error) { + qsp := make(url.Values) + if comment != "" { + qsp.Set("comment", comment) + } + + machine := new(entity.Machine) + err := m.client(systemID).Post("unlock", qsp, func(data []byte) error { + return json.Unmarshal(data, machine) + }) + + return machine, err +} + // ClearDefaultGateways clears default gateways. func (m *Machine) ClearDefaultGateways(systemID string) (*entity.Machine, error) { machine := new(entity.Machine) @@ -186,3 +201,78 @@ func (m *Machine) SetWorkloadAnnotations(systemID string, params map[string]stri return machine, err } + +// RescueMode begins the rescue mode process on a given machine +func (m *Machine) RescueMode(systemID string) (*entity.Machine, error) { + machine := new(entity.Machine) + err := m.client(systemID).Post("rescue_mode", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, &machine) + }) + + return machine, err +} + +// ExitRescueMode exits the rescue mode process on a given machine +func (m *Machine) ExitRescueMode(systemID string) (*entity.Machine, error) { + machine := new(entity.Machine) + err := m.client(systemID).Post("exit_rescue_mode", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, &machine) + }) + + return machine, err +} + +// Abort aborts machine's current operation +func (m *Machine) Abort(systemID string, comment string) (*entity.Machine, error) { + qsp := make(url.Values) + if comment != "" { + qsp.Set("comment", comment) + } + + machine := new(entity.Machine) + err := m.client(systemID).Post("abort", qsp, func(data []byte) error { + return json.Unmarshal(data, machine) + }) + + return machine, err +} + +// MarkBroken marks a machine as ‘Broken’ +func (m *Machine) MarkBroken(systemID string, comment string) (*entity.Machine, error) { + qsp := make(url.Values) + if comment != "" { + qsp.Set("comment", comment) + } + + machine := new(entity.Machine) + err := m.client(systemID).Post("mark_broken", qsp, func(data []byte) error { + return json.Unmarshal(data, machine) + }) + + return machine, err +} + +// MarkFixed marks a machine as ‘Fixed’ +func (m *Machine) MarkFixed(systemID string, comment string) (*entity.Machine, error) { + qsp := make(url.Values) + if comment != "" { + qsp.Set("comment", comment) + } + + machine := new(entity.Machine) + err := m.client(systemID).Post("mark_fixed", qsp, func(data []byte) error { + return json.Unmarshal(data, machine) + }) + + return machine, err +} + +// GetToken gets the machine token for a given machine +func (m *Machine) GetToken(systemID string) (*entity.MachineToken, error) { + machineToken := new(entity.MachineToken) + err := m.client(systemID).Get("get_token", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, machineToken) + }) + + return machineToken, err +} diff --git a/client/machines.go b/client/machines.go index 7e9c008..7c4f4de 100644 --- a/client/machines.go +++ b/client/machines.go @@ -81,3 +81,13 @@ func (m *Machines) AcceptAll() error { qsp := url.Values{} return m.client().Post("accept_all", qsp, func(data []byte) error { return nil }) } + +// ListAllocated lists allocated machines +func (m *Machines) ListAllocated() ([]entity.Machine, error) { + machines := make([]entity.Machine, 0) + err := m.client().Get("list_allocated", url.Values{}, func(data []byte) error { + return json.Unmarshal(data, &machines) + }) + + return machines, err +} diff --git a/entity/machine.go b/entity/machine.go index dd8c5d2..491e5b0 100644 --- a/entity/machine.go +++ b/entity/machine.go @@ -197,6 +197,13 @@ type MachinePowerState struct { State string `json:"state,omitempty"` } +// MachineToken represents Machine token +type MachineToken struct { + TokenKey string `json:"token_key,omitempty"` + TokenSecret string `json:"token_secret,omitempty"` + ConsumerKey string `json:"consumer_key,omitempty"` +} + // MachineParams enumerates the parameters for the machine update operation type MachineParams struct { PowerType string `url:"power_type,omitempty"`