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.
55 lines
1.4 KiB
55 lines
1.4 KiB
package compute
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// ChangeIPRequest struct to change IP for network
|
|
type ChangeIPRequest struct {
|
|
// ID of compute instance
|
|
// Required: true
|
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
|
|
// Network type
|
|
// 'EXTNET' for connect to external network directly
|
|
// 'VINS' for connect to ViNS
|
|
// Required: true
|
|
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
|
|
|
// Network ID for connect to
|
|
// For EXTNET - external network ID
|
|
// For VINS - VINS ID
|
|
// Required: true
|
|
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
|
|
|
// IP address to which we will change the existing one, it must be from the same subnet
|
|
// Required: true
|
|
IPAddr string `url:"ipAddr" json:"ipAddr" validate:"required"`
|
|
}
|
|
|
|
// ChangeIP change reserved IP for compute instance
|
|
func (c Compute) ChangeIP(ctx context.Context, req ChangeIPRequest) (bool, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudapi/compute/changeIp"
|
|
|
|
res, err := c.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
|
|
}
|