Skip to content

Commit

Permalink
feat: support for adding, removing, updating machines/devices Workloa…
Browse files Browse the repository at this point in the history
…d Annotations
  • Loading branch information
sachin120 committed Jan 4, 2024
1 parent 7be8be8 commit b8a3c16
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ type Device interface {
Get(systemID string) (*entity.Device, error)
Update(systemID string, deviceParams *entity.DeviceUpdateParams) (*entity.Device, error)
Delete(systemID string) error
SetWorkloadAnnotations(systemID string, params map[string]string) (*entity.Device, error)
}
1 change: 1 addition & 0 deletions api/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ type Machine interface {
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)
}
15 changes: 15 additions & 0 deletions client/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,18 @@ func (d *Device) Update(systemID string, deviceParams *entity.DeviceUpdateParams
func (d *Device) Delete(systemID string) error {

Check failure on line 47 in client/device.go

View workflow job for this annotation

GitHub Actions / lint

ST1016: methods on the same type should have the same receiver name (seen 1x "m", 4x "d") (stylecheck)
return d.client(systemID).Delete()
}

// SetWorkloadAnnotations add, modify or remove workload annotations for given Device
func (m *Device) SetWorkloadAnnotations(systemID string, params map[string]string) (*entity.Device, error) {
qsp := url.Values{}
for k, v := range params {
qsp.Add(k, v)
}

device := new(entity.Device)
err := m.client(systemID).Post("set_workload_annotations", qsp, func(data []byte) error {
return json.Unmarshal(data, &device)
})

return device, err
}
15 changes: 15 additions & 0 deletions client/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,18 @@ func (m *Machine) GetPowerState(systemID string) (*entity.MachinePowerState, err

return ps, err
}

// SetWorkloadAnnotations add, modify or remove workload annotations for given Machine
func (m *Machine) SetWorkloadAnnotations(systemID string, params map[string]string) (*entity.Machine, error) {
qsp := url.Values{}
for k, v := range params {
qsp.Add(k, v)
}

machine := new(entity.Machine)
err := m.client(systemID).Post("set_workload_annotations", qsp, func(data []byte) error {
return json.Unmarshal(data, &machine)
})

return machine, err
}

0 comments on commit b8a3c16

Please sign in to comment.