v9.0.0
This commit is contained in:
61
pkg/cloudbroker/vins/nat_rule_add.go
Normal file
61
pkg/cloudbroker/vins/nat_rule_add.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// NATRuleAddRequest struct to create NAT rules
|
||||
type NATRuleAddRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||
|
||||
// Internal IP address to apply this rule to
|
||||
// Required: true
|
||||
IntIP string `url:"intIp" json:"intIp" validate:"required"`
|
||||
|
||||
// External IP start port to use for this rule
|
||||
// Required: true
|
||||
ExtPortStart uint64 `url:"extPortStart" json:"extPortStart" validate:"required"`
|
||||
|
||||
// Internal IP port number to use for this rule
|
||||
// Required: false
|
||||
IntPort uint64 `url:"intPort,omitempty" json:"intPort,omitempty"`
|
||||
|
||||
// External IP end port to use for this rule
|
||||
// Required: false
|
||||
ExtPortEnd uint64 `url:"extPortEnd,omitempty" json:"extPortEnd,omitempty"`
|
||||
|
||||
// IP protocol type
|
||||
// Should be one of:
|
||||
// - "tcp"
|
||||
// - "udp"
|
||||
// Required: false
|
||||
Proto string `url:"proto,omitempty" json:"proto,omitempty" validate:"omitempty,proto"`
|
||||
}
|
||||
|
||||
// NATRuleAdd creates NAT (port forwarding) rule on VINS
|
||||
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/natRuleAdd"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user