From 2266c07e6583301db899661259cd760f2ef638ad Mon Sep 17 00:00:00 2001 From: Sachin Shingare Date: Thu, 4 Jan 2024 15:00:41 +0000 Subject: [PATCH] feat: support for adding, removing, updating machines/devices Workload Annotations --- api/device.go | 1 + api/machine.go | 1 + client/device.go | 15 +++++++++++++++ client/machine.go | 15 +++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/api/device.go b/api/device.go index 044296c..cdf048e 100644 --- a/api/device.go +++ b/api/device.go @@ -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) } diff --git a/api/machine.go b/api/machine.go index b75a513..4cd3930 100644 --- a/api/machine.go +++ b/api/machine.go @@ -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) } diff --git a/client/device.go b/client/device.go index 02aae7f..1964587 100644 --- a/client/device.go +++ b/client/device.go @@ -48,3 +48,18 @@ func (d *Device) Update(systemID string, deviceParams *entity.DeviceUpdateParams func (d *Device) Delete(systemID string) error { 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 +} diff --git a/client/machine.go b/client/machine.go index ef99fae..190b669 100644 --- a/client/machine.go +++ b/client/machine.go @@ -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 +}