v1.3.0
This commit is contained in:
@@ -3,37 +3,29 @@ package extnet
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for grant access
|
||||
type AccessAddRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (erq AccessAddRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessAdd grant access to external network for account ID
|
||||
func (e ExtNet) AccessAdd(ctx context.Context, req AccessAddRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/accessAdd"
|
||||
|
||||
@@ -3,37 +3,29 @@ package extnet
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove access
|
||||
type AccessRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId"`
|
||||
}
|
||||
|
||||
func (erq AccessRemoveRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// AccessRemove remove access from external network for account ID
|
||||
func (e ExtNet) AccessRemove(ctx context.Context, req AccessRemoveRequest) ([]uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/accessRemove"
|
||||
|
||||
@@ -2,33 +2,34 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create external network
|
||||
type CreateRequest struct {
|
||||
// External network name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Grid (platform) ID
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid"`
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// IP network CIDR
|
||||
// For example 192.168.0.0/24
|
||||
// Required: true
|
||||
IPCIDR string `url:"ipcidr" json:"ipcidr"`
|
||||
IPCIDR string `url:"ipcidr" json:"ipcidr" validate:"required"`
|
||||
|
||||
// External network gateway IP address
|
||||
// Required: true
|
||||
Gateway string `url:"gateway" json:"gateway"`
|
||||
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||
|
||||
// VLAN ID
|
||||
// Required: true
|
||||
VLANID uint64 `url:"vlanId" json:"vlanId"`
|
||||
VLANID uint64 `url:"vlanId" json:"vlanId" validate:"required"`
|
||||
|
||||
// List of DNS addresses
|
||||
// Required: false
|
||||
@@ -71,31 +72,13 @@ type CreateRequest struct {
|
||||
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
||||
}
|
||||
|
||||
func (erq CreateRequest) validate() error {
|
||||
if erq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if erq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
if erq.IPCIDR == "" {
|
||||
return errors.New("validation-error: field IPCIDR must be set")
|
||||
}
|
||||
if erq.Gateway == "" {
|
||||
return errors.New("validation-error: field Gateway must be set")
|
||||
}
|
||||
if erq.VLANID == 0 {
|
||||
return errors.New("validation-error: field VLANID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates new external network into platform
|
||||
func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/create"
|
||||
|
||||
@@ -2,16 +2,17 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update QOS
|
||||
type DefaultQOSUpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
@@ -26,19 +27,13 @@ type DefaultQOSUpdateRequest struct {
|
||||
EgressRate uint64 `url:"egress_rate,omitempty" json:"egress_rate,omitempty"`
|
||||
}
|
||||
|
||||
func (erq DefaultQOSUpdateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultQOSUpdate updates default qos values
|
||||
func (e ExtNet) DefaultQOSUpdate(ctx context.Context, req DefaultQOSUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/defaultQosUpdate"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for destroy
|
||||
type DestroyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DestroyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Destroy destroys external network
|
||||
func (e ExtNet) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/destroy"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for deploy network device
|
||||
type DeviceDeployRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceDeployRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceDeploy deploys network device for external network (make not virtual, "physical")
|
||||
func (e ExtNet) DeviceDeploy(ctx context.Context, req DeviceDeployRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceDeploy"
|
||||
|
||||
@@ -2,37 +2,29 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for migrate VNF
|
||||
type DeviceMigrateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Target stack ID to migrate to
|
||||
StackID uint64 `url:"stackId" json:"stackId"`
|
||||
}
|
||||
|
||||
func (erq DeviceMigrateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.StackID == 0 {
|
||||
return errors.New("validation-error: field StackID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
StackID uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceMigrate migrate external network VNF device
|
||||
func (e ExtNet) DeviceMigrate(ctx context.Context, req DeviceMigrateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceMigrate"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove network device
|
||||
type DeviceRemoveRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceRemoveRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceRemove removes network device of external network (make it virtual, not "physical")
|
||||
func (e ExtNet) DeviceRemove(ctx context.Context, req DeviceRemoveRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceRemove"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restart VNF device
|
||||
type DeviceRestartRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DeviceRestartRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DeviceRestart restarts external network VNF device
|
||||
func (e ExtNet) DeviceRestart(ctx context.Context, req DeviceRestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/deviceRestart"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable external network
|
||||
type DisableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq DisableRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables external network
|
||||
func (e ExtNet) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/disable"
|
||||
|
||||
@@ -2,35 +2,30 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set new DNS
|
||||
type DNSApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of DNS to apply
|
||||
// Required: false
|
||||
DNSList []string `url:"dns_list,omitempty" json:"dns_list,omitempty"`
|
||||
}
|
||||
|
||||
func (erq DNSApplyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DNSApply sets new DNS
|
||||
func (e ExtNet) DNSApply(ctx context.Context, req DNSApplyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/dnsApply"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for enable external network
|
||||
type EnableRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq EnableRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables external networks
|
||||
func (e ExtNet) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/enable"
|
||||
|
||||
@@ -3,30 +3,25 @@ package extnet
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq GetRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets external network details
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/get"
|
||||
|
||||
@@ -2,38 +2,30 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for exclude list IPs
|
||||
type IPsExcludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of IPs for exclude from external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips" json:"ips"`
|
||||
}
|
||||
|
||||
func (erq IPsExcludeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if len(erq.IPs) == 0 {
|
||||
return errors.New("validation-error: field IPs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
IPs []string `url:"ips" json:"ips" validate:"min=1"`
|
||||
}
|
||||
|
||||
// IPsExclude exclude list IPs from external network pool
|
||||
func (e ExtNet) IPsExclude(ctx context.Context, req IPsExcludeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsExclude"
|
||||
|
||||
@@ -2,45 +2,34 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for exclude range of IPs
|
||||
type IPsExcludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start" json:"ip_start"`
|
||||
IPStart string `url:"ip_start" json:"ip_start" validate:"required"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end" json:"ip_end"`
|
||||
}
|
||||
|
||||
func (erq IPsExcludeRangeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.IPStart == "" {
|
||||
return errors.New("validation-error: field IPStart must be set")
|
||||
}
|
||||
if erq.IPEnd == "" {
|
||||
return errors.New("validation-error: field IPEnd must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
IPEnd string `url:"ip_end" json:"ip_end" validate:"required"`
|
||||
}
|
||||
|
||||
// IPsExcludeRange exclude range of IPs from external network pool
|
||||
func (e ExtNet) IPsExcludeRange(ctx context.Context, req IPsExcludeRangeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsExcludeRange"
|
||||
|
||||
@@ -2,38 +2,30 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for include list IPs
|
||||
type IPsIncludeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of IPs for include to external network
|
||||
// Required: true
|
||||
IPs []string `url:"ips" json:"ips"`
|
||||
}
|
||||
|
||||
func (erq IPsIncludeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if len(erq.IPs) == 0 {
|
||||
return errors.New("validation-error: field IPs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
IPs []string `url:"ips" json:"ips" validate:"min=1"`
|
||||
}
|
||||
|
||||
// IPsInclude include list IPs to external network pool
|
||||
func (e ExtNet) IPsInclude(ctx context.Context, req IPsIncludeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsInclude"
|
||||
|
||||
@@ -2,45 +2,34 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for include range of IPs
|
||||
type IPsIncludeRangeRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// Starting IP
|
||||
// Required: true
|
||||
IPStart string `url:"ip_start" json:"ip_start"`
|
||||
IPStart string `url:"ip_start" json:"ip_start" validate:"required"`
|
||||
|
||||
// Ending IP
|
||||
// Required: true
|
||||
IPEnd string `url:"ip_end" json:"ip_end"`
|
||||
}
|
||||
|
||||
func (erq IPsIncludeRangeRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
if erq.IPStart == "" {
|
||||
return errors.New("validation-error: field IPStart must be set")
|
||||
}
|
||||
if erq.IPEnd == "" {
|
||||
return errors.New("validation-error: field IPEnd must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
IPEnd string `url:"ip_end" json:"ip_end" validate:"required"`
|
||||
}
|
||||
|
||||
// IPsIncludeRange include range of IPs to external network pool
|
||||
func (e ExtNet) IPsIncludeRange(ctx context.Context, req IPsIncludeRangeRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ipsIncludeRange"
|
||||
|
||||
@@ -2,35 +2,30 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set new NTP
|
||||
type NTPApplyRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// List of NTP to apply
|
||||
// Required: false
|
||||
NTPList []string `url:"ntp_list,omitempty" json:"ntp_list,omitempty"`
|
||||
}
|
||||
|
||||
func (erq NTPApplyRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NTPApply sets new NTP
|
||||
func (e ExtNet) NTPApply(ctx context.Context, req NTPApplyRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/ntpApply"
|
||||
|
||||
@@ -2,31 +2,26 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set external network as default
|
||||
type SetDefaultRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
}
|
||||
|
||||
func (erq SetDefaultRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
}
|
||||
|
||||
// SetDefault sets external network as default for platform
|
||||
func (e ExtNet) SetDefault(ctx context.Context, req SetDefaultRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/setDefault"
|
||||
|
||||
@@ -2,16 +2,17 @@ package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update external network
|
||||
type UpdateRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id" json:"net_id"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// New external network name
|
||||
// Required: false
|
||||
@@ -22,19 +23,13 @@ type UpdateRequest struct {
|
||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
}
|
||||
|
||||
func (erq UpdateRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates external network parameters
|
||||
func (e ExtNet) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/update"
|
||||
|
||||
Reference in New Issue
Block a user