v1.12.9
This commit is contained in:
62
pkg/sdn/netobjgroups/create.go
Normal file
62
pkg/sdn/netobjgroups/create.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package netobjgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create a network object group
|
||||
type CreateRequest struct {
|
||||
// Access Group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Logical ports bindings
|
||||
// Required: false
|
||||
LogicalPortsBindings []LogicalPortsBindings `url:"logical_ports_binding,omitempty" json:"logical_ports_bindings,omitempty" validate:"omitempty,dive"`
|
||||
}
|
||||
type LogicalPortsBindings struct {
|
||||
// Port ID
|
||||
// Required: true
|
||||
PortID string `url:"port_id" json:"port_id" validate:"required"`
|
||||
|
||||
// Port version
|
||||
// Required: true
|
||||
PortVersion int64 `url:"port_version" json:"port_version" validate:"required"`
|
||||
}
|
||||
|
||||
// Create creates a network object group
|
||||
func (nog NetworkObjectGroups) Create(ctx context.Context, req CreateRequest) (*RecordNetObjGroup, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/network_object_group/create"
|
||||
|
||||
res, err := nog.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordNetObjGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user