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.
63 lines
1.6 KiB
63 lines
1.6 KiB
|
4 days ago
|
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
|
||
|
|
}
|