v1.12.9
This commit is contained in:
135
pkg/sdn/logicalports/update.go
Normal file
135
pkg/sdn/logicalports/update.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package logicalports
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateRequest struct to update logical port
|
||||
type UpdateRequest struct {
|
||||
// ID of the logical port
|
||||
// Required: true
|
||||
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||||
|
||||
// ID of the version
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Adapter MAC
|
||||
// Required: true
|
||||
AdapterMAC string `url:"adapter_mac" json:"adapter_mac" validate:"required"`
|
||||
|
||||
// Description
|
||||
// Required: true
|
||||
Description string `url:"description" json:"description" validate:"required"`
|
||||
|
||||
// Display name
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
|
||||
// Enabled. True or False
|
||||
// Required: true
|
||||
Enabled interface{} `url:"enabled" json:"enabled" validate:"required,isBool"`
|
||||
|
||||
// Remove addresses
|
||||
// Required: false
|
||||
RemoveAddresses []string `url:"remove_addresses,omitempty" json:"remove_addresses,omitempty"`
|
||||
|
||||
// Hypervisor
|
||||
// Required: true
|
||||
Hypervisor string `url:"hypervisor" json:"hypervisor" validate:"required"`
|
||||
|
||||
// Port security. True or False
|
||||
// Required: true
|
||||
PortSecurity interface{} `url:"port_security" json:"port_security" validate:"required,isBool"`
|
||||
|
||||
// Is excluded from firewall. True or False
|
||||
// Required: true
|
||||
IsExcludedFromFirewall interface{} `url:"is_excluded_from_firewall" json:"is_excluded_from_firewall" validate:"required,isBool"`
|
||||
|
||||
// Segment ID
|
||||
// Required: true
|
||||
SegmentID string `url:"segment_id" json:"segment_id" validate:"required"`
|
||||
|
||||
// Update addresses
|
||||
// Required: false
|
||||
UpdateAddresses []UpdateAddress `url:"update_addresses,omitempty" json:"update_addresses,omitempty" validate:"dive"`
|
||||
|
||||
// Add addresses
|
||||
// Required: false
|
||||
AddAddresses []AddAddress `url:"add_addresses,omitempty" json:"add_addresses,omitempty" validate:"dive"`
|
||||
}
|
||||
|
||||
// UpdateAddress struct representing update address
|
||||
type UpdateAddress struct {
|
||||
// IP address
|
||||
// Required: true
|
||||
IP string `url:"ip" json:"ip" validate:"required"`
|
||||
|
||||
// IP type
|
||||
// Required: true
|
||||
IPType string `url:"ip_type" json:"ip_type" validate:"required,oneof=IPv4 IPv6"`
|
||||
|
||||
// Is discovered. True or False
|
||||
// Required: false
|
||||
IsDiscovered interface{} `url:"is_discovered,omitempty" json:"is_discovered,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Is primary. True or False
|
||||
// Required: true
|
||||
IsPrimary interface{} `url:"is_primary" json:"is_primary" validate:"required,isBool"`
|
||||
|
||||
// MAC address
|
||||
// Required: false
|
||||
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
|
||||
}
|
||||
|
||||
// AddAddress struct representing add address
|
||||
type AddAddress struct {
|
||||
// IP address
|
||||
// Required: true
|
||||
IP string `url:"ip" json:"ip" validate:"required"`
|
||||
|
||||
// IP type
|
||||
// Required: true
|
||||
IPType string `url:"ip_type" json:"ip_type" validate:"required,oneof=IPv4 IPv6"`
|
||||
|
||||
// Is discovered. True or False
|
||||
// Required: false
|
||||
IsDiscovered interface{} `url:"is_discovered,omitempty" json:"is_discovered,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Is primary. True or False
|
||||
// Required: true
|
||||
IsPrimary interface{} `url:"is_primary" json:"is_primary" validate:"required,isBool"`
|
||||
|
||||
// MAC address
|
||||
// Required: false
|
||||
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
|
||||
}
|
||||
|
||||
// Update updates a logical port
|
||||
func (i LogicalPorts) Update(ctx context.Context, req UpdateRequest) (*LogicalPort, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/logical_port/update"
|
||||
|
||||
res, err := i.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := LogicalPort{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user