Files
decort-golang-sdk/pkg/cloudapi/disks/limitio.go

97 lines
2.7 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package disks
import (
"context"
"net/http"
"strconv"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// LimitIORequest struct for limit IO
2022-10-03 16:56:47 +03:00
type LimitIORequest struct {
2022-12-22 17:56:47 +03:00
// ID of the disk to limit
// Required: true
2023-03-24 17:09:30 +03:00
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Alias for total_iops_sec for backwards compatibility
// Required: false
2023-03-01 19:05:53 +03:00
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`
2022-12-22 17:56:47 +03:00
// TotalBytesSec
// Required: false
2023-03-01 19:05:53 +03:00
TotalBytesSec uint64 `url:"total_bytes_sec,omitempty" json:"total_bytes_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// ReadBytesSec
// Required: false
2023-03-01 19:05:53 +03:00
ReadBytesSec uint64 `url:"read_bytes_sec,omitempty" json:"read_bytes_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// WriteBytesSec
// Required: false
2023-03-01 19:05:53 +03:00
WriteBytesSec uint64 `url:"write_bytes_sec,omitempty" json:"write_bytes_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// TotalIOPSSec
// Required: false
2023-03-01 19:05:53 +03:00
TotalIOPSSec uint64 `url:"total_iops_sec,omitempty" json:"total_iops_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// ReadIOPSSec
// Required: false
2023-03-01 19:05:53 +03:00
ReadIOPSSec uint64 `url:"read_iops_sec,omitempty" json:"read_iops_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// WriteIOPSSec
// Required: false
2023-03-01 19:05:53 +03:00
WriteIOPSSec uint64 `url:"write_iops_sec,omitempty" json:"write_iops_sec,omitempty"`
2022-12-22 17:56:47 +03:00
// TotalBytesSecMax
// Required: false
2023-03-01 19:05:53 +03:00
TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty" json:"total_bytes_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// ReadBytesSecMax
// Required: false
2023-03-01 19:05:53 +03:00
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty" json:"read_bytes_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// WriteBytesSecMax
// Required: false
2023-03-01 19:05:53 +03:00
WriteBytesSecMax uint64 `url:"write_bytes_sec_max,omitempty" json:"write_bytes_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// TotalIOPSSecMax
// Required: false
2023-03-01 19:05:53 +03:00
TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty" json:"total_iops_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// ReadIOPSSecMax
// Required: false
2023-03-01 19:05:53 +03:00
ReadIOPSSecMax uint64 `url:"read_iops_sec_max,omitempty" json:"read_iops_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// WriteIOPSSecMax
// Required: false
2023-03-01 19:05:53 +03:00
WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty" json:"write_iops_sec_max,omitempty"`
2022-12-22 17:56:47 +03:00
// SizeIOPSSec
// Required: false
2023-03-01 19:05:53 +03:00
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty" json:"size_iops_sec,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// LimitIO limit IO for a certain disk
// total and read/write options are not allowed to be combined
// see http://libvirt.org/formatdomain.html#elementsDisks iotune section for more details
2022-10-03 16:56:47 +03:00
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-10-03 16:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return false, validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/disks/limitIO"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}