Files
decort-golang-sdk/pkg/cloudapi/vins/ip_reserve.go

58 lines
1.5 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package vins
import (
"context"
"net/http"
2022-12-22 17:56:47 +03:00
2023-03-17 12:54:34 +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
// IPReserveRequest struct for IP reserve
2022-10-03 16:56:47 +03:00
type IPReserveRequest struct {
2022-12-22 17:56:47 +03:00
// VINS ID
// Required: true
2023-03-24 17:09:30 +03:00
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
2022-12-22 17:56:47 +03:00
// Type of the reservation
// Should be one of:
// - DHCP
// - VIP
// - EXCLUDE
// Required: true
2023-03-24 17:09:30 +03:00
Type string `url:"type" json:"type" validate:"vinsType"`
2022-12-22 17:56:47 +03:00
// IP address to use. Non-empty string is required for type "EXCLUDE".
// Ignored for types "DHCP" and "VIP".
// Required: false
2023-03-01 19:05:53 +03:00
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
2022-12-22 17:56:47 +03:00
// MAC address to associate with IP reservation.
// Ignored for type "EXCLUDE",
// non-empty string is required for "DHCP" and "VIP"
// Required: false
2023-03-01 19:05:53 +03:00
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
2022-12-22 17:56:47 +03:00
// ID of the compute, associated with this reservation of type "DHCP".
// Ignored for other types
// Required: false
2023-03-01 19:05:53 +03:00
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
2022-10-03 16:56:47 +03:00
}
2022-12-22 17:56:47 +03:00
// IPReserve creates reservation on ViNS DHCP
2022-10-03 16:56:47 +03:00
func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, error) {
2024-04-16 14:26:06 +03:00
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 "", validators.ValidationErrors(validators.GetErrors(err))
2022-10-03 16:56:47 +03:00
}
url := "/cloudapi/vins/ipReserve"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}