You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/vins/ip_reserve.go

64 lines
1.6 KiB

3 years ago
package vins
import (
"context"
"net/http"
"strings"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
2 years ago
// IPReserveRequest struct for IP reserve
3 years ago
type IPReserveRequest struct {
// VINS ID
// Required: true
3 years ago
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
3 years ago
// Type of the reservation
// Should be one of:
// - DHCP
// - VIP
// - EXCLUDE
// Required: true
3 years ago
Type string `url:"type" json:"type" validate:"vinsType"`
3 years ago
// IP address to use. Non-empty string is required for type "EXCLUDE".
// Ignored for types "DHCP" and "VIP".
// Required: false
3 years ago
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
3 years ago
// MAC address to associate with IP reservation.
// Ignored for type "EXCLUDE",
// non-empty string is required for "DHCP" and "VIP"
// Required: false
3 years ago
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
3 years ago
// ID of the compute, associated with this reservation of type "DHCP".
// Ignored for other types
// Required: false
3 years ago
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
3 years ago
// Reason for action
// Required: false
3 years ago
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
3 years ago
}
// IPReserve creates reservation on ViNS DHCP
func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, error) {
3 years ago
err := validators.ValidateRequest(req)
3 years ago
if err != nil {
2 years ago
return "", validators.ValidationErrors(validators.GetErrors(err))
3 years ago
}
url := "/cloudbroker/vins/ipReserve"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}