v1.12.9
This commit is contained in:
52
pkg/sdn/flips/create.go
Normal file
52
pkg/sdn/flips/create.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package flips
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
// Access Group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// ID of an external network port
|
||||
// Required: true
|
||||
ExtNetPortID string `url:"external_network_port_id" json:"external_network_port_id" validate:"required"`
|
||||
|
||||
// ID of a logical network port
|
||||
// Required: true
|
||||
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||||
|
||||
// ID of a router
|
||||
// Required: true
|
||||
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Create creates a floating ip
|
||||
func (fi FloatingIPs) Create(ctx context.Context, req CreateRequest) (*RecordFloatingIP, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/create"
|
||||
|
||||
res, err := fi.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordFloatingIP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
51
pkg/sdn/flips/delete.go
Normal file
51
pkg/sdn/flips/delete.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package flips
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest to delete a floating ip
|
||||
type DeleteRequest struct {
|
||||
// ID of a floating IP
|
||||
// Required: true
|
||||
FloatingIPID string `url:"floating_ip_id" json:"floating_ip_id" validate:"required"`
|
||||
|
||||
// Version ID
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// Force delete
|
||||
// Required: false
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
}
|
||||
|
||||
// Delete a floating ip
|
||||
func (fi FloatingIPs) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/delete"
|
||||
|
||||
res, err := fi.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if string(res) == "" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/sdn/flips/filter.go
Normal file
42
pkg/sdn/flips/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package flips
|
||||
|
||||
// FilterByID returns FloatingIPsList with specified ID.
|
||||
func (fil FloatingIPsList) FilterByID(id string) FloatingIPsList {
|
||||
predicate := func(fi RecordFloatingIP) bool {
|
||||
return fi.ID == id
|
||||
}
|
||||
|
||||
return fil.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns FloatingIPsList with specified AccessGroupName.
|
||||
func (fil FloatingIPsList) FilterByAccessGroupName(name string) FloatingIPsList {
|
||||
predicate := func(fi RecordFloatingIP) bool {
|
||||
return fi.AccessGroupName == name
|
||||
}
|
||||
|
||||
return fil.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering FloatingIPsList based on a user-specified predicate.
|
||||
func (fil FloatingIPsList) FilterFunc(predicate func(fi RecordFloatingIP) bool) FloatingIPsList {
|
||||
var result FloatingIPsList
|
||||
|
||||
for _, acc := range fil.Objects {
|
||||
if predicate(acc) {
|
||||
result.Objects = append(result.Objects, acc)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first element.
|
||||
// If none was found, returns an empty struct.
|
||||
func (fil FloatingIPsList) FindOne() RecordFloatingIP {
|
||||
if len(fil.Objects) == 0 {
|
||||
return RecordFloatingIP{}
|
||||
}
|
||||
|
||||
return fil.Objects[0]
|
||||
}
|
||||
196
pkg/sdn/flips/filter_test.go
Normal file
196
pkg/sdn/flips/filter_test.go
Normal file
@@ -0,0 +1,196 @@
|
||||
package flips
|
||||
|
||||
import "testing"
|
||||
|
||||
var testFloatingIPs = FloatingIPsList{
|
||||
Objects: []RecordFloatingIP{
|
||||
{
|
||||
AccessGroupID: "testid",
|
||||
AccessGroupName: "testname",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
ExternalNetworkPort: ExternalNetworkPort{
|
||||
AccessGroupID: "somegroup",
|
||||
AccessGroupName: "somename",
|
||||
Comment: "some comment",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
ExternalNetworkID: "someid",
|
||||
ID: "someid",
|
||||
IPv4: "someipv4",
|
||||
MAC: "somemac",
|
||||
VersionID: 1111111111111,
|
||||
},
|
||||
ID: "someid",
|
||||
LogicalPort: LogicalPort{
|
||||
ID: "someid",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
AdapterMAC: "somemac",
|
||||
AddressDetection: false,
|
||||
Description: "some description",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
Hypervisor: "hypervisor",
|
||||
HypervisorDisplayName: "hypervisor display name",
|
||||
UniqueIdentifier: "someid",
|
||||
VersionID: 1111111111111,
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
},
|
||||
Router: Router{
|
||||
ID: "someid",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111111,
|
||||
},
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111111,
|
||||
},
|
||||
{
|
||||
AccessGroupID: "testid3",
|
||||
AccessGroupName: "testname3",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
ExternalNetworkPort: ExternalNetworkPort{
|
||||
AccessGroupID: "somegroup",
|
||||
AccessGroupName: "somename",
|
||||
Comment: "some comment",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
ExternalNetworkID: "someid2",
|
||||
ID: "someid",
|
||||
IPv4: "someipv4",
|
||||
MAC: "somemac",
|
||||
VersionID: 1111111111112,
|
||||
},
|
||||
ID: "someid2",
|
||||
LogicalPort: LogicalPort{
|
||||
ID: "someid2",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
AdapterMAC: "somemac",
|
||||
AddressDetection: false,
|
||||
Description: "some description",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
Hypervisor: "hypervisor",
|
||||
HypervisorDisplayName: "hypervisor display name",
|
||||
UniqueIdentifier: "someid",
|
||||
VersionID: 1111111111112,
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
},
|
||||
Router: Router{
|
||||
ID: "someid2",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111112,
|
||||
},
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111112,
|
||||
},
|
||||
{
|
||||
AccessGroupID: "testid3",
|
||||
AccessGroupName: "testname3",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
ExternalNetworkPort: ExternalNetworkPort{
|
||||
AccessGroupID: "somegroup",
|
||||
AccessGroupName: "somename",
|
||||
Comment: "some comment",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
ExternalNetworkID: "someid3",
|
||||
ID: "someid3",
|
||||
IPv4: "someipv4",
|
||||
MAC: "somemac",
|
||||
VersionID: 1111111111113,
|
||||
},
|
||||
ID: "someid3",
|
||||
LogicalPort: LogicalPort{
|
||||
ID: "someid3",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
AdapterMAC: "somemac",
|
||||
AddressDetection: false,
|
||||
Description: "some description",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
Hypervisor: "hypervisor",
|
||||
HypervisorDisplayName: "hypervisor display name",
|
||||
UniqueIdentifier: "someid",
|
||||
VersionID: 1111111111113,
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
},
|
||||
Router: Router{
|
||||
ID: "someid3",
|
||||
AccessGroupID: "someid",
|
||||
AccessGroupName: "somename",
|
||||
CreatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
DisplayName: "some display name",
|
||||
Enabled: true,
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111113,
|
||||
},
|
||||
UpdatedAt: "2025-09-23T08:05:59.271458Z",
|
||||
VersionID: 1111111111113,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := testFloatingIPs.FilterByID("someid").FindOne()
|
||||
|
||||
if actual.ID != "someid" {
|
||||
t.Fatal("actual:", actual.ID, "> expected: someid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := testFloatingIPs.FilterByAccessGroupName("testname").FindOne()
|
||||
|
||||
if actual.AccessGroupName != "testname" {
|
||||
t.Fatal("actual:", actual.AccessGroupID, ">> expected: testname")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := testFloatingIPs.FilterFunc(func(rfi RecordFloatingIP) bool {
|
||||
return rfi.VersionID == 1111111111111
|
||||
})
|
||||
|
||||
if len(actual.Objects) != 1 || actual.Objects[0].ID != "someid" {
|
||||
t.Fatal("Expected 1 policy with version ID 1111111111111, found:", len(actual.Objects))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneWithResults(t *testing.T) {
|
||||
result := testFloatingIPs.FilterByID("someid").FindOne()
|
||||
if result.ID != "someid" {
|
||||
t.Fatal("Expected someid, got:", result.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneEmpty(t *testing.T) {
|
||||
emptyList := FloatingIPsList{}
|
||||
result := emptyList.FindOne()
|
||||
|
||||
if result.ID != "" || result.AccessGroupID != "" {
|
||||
t.Fatal("Expected empty FloatingIP, got:", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIDNotFound(t *testing.T) {
|
||||
actual := testFloatingIPs.FilterByID("nonex")
|
||||
|
||||
if len(actual.Objects) != 0 {
|
||||
t.Fatal("Expected 0 policies, found:", len(actual.Objects))
|
||||
}
|
||||
}
|
||||
18
pkg/sdn/flips/flips.go
Normal file
18
pkg/sdn/flips/flips.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API Actor API for managing SDN floating IPs
|
||||
package flips
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to floating IPs
|
||||
type FloatingIPs struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for floating IPs endpoints
|
||||
func New(client interfaces.Caller) *FloatingIPs {
|
||||
return &FloatingIPs{
|
||||
client,
|
||||
}
|
||||
}
|
||||
46
pkg/sdn/flips/get.go
Normal file
46
pkg/sdn/flips/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package flips
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// ID of a floating IP
|
||||
// Required: true
|
||||
FloatingIPID string `url:"floating_ip_id" json:"floating_ip_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets a floating ip details as a RecordFloatingIP struct
|
||||
func (fi FloatingIPs) Get(ctx context.Context, req GetRequest) (*RecordFloatingIP, error) {
|
||||
res, err := fi.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordFloatingIP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
|
||||
}
|
||||
|
||||
// GetRaw gets a floating ip details as an array of bytes
|
||||
func (fi FloatingIPs) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/get"
|
||||
|
||||
res, err := fi.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
104
pkg/sdn/flips/list.go
Normal file
104
pkg/sdn/flips/list.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package flips
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// List of floating ips
|
||||
type ListRequest struct {
|
||||
// Filter by access group ID
|
||||
// Required: false
|
||||
AccessGroupID string `url:"access_group_id,omitempty" json:"access_group_id,omitempty"`
|
||||
|
||||
//Is the external network enabled
|
||||
// Required: false
|
||||
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Filter by Pv4 of the associated external network port
|
||||
// Required: false
|
||||
ExternalNetworkPortIPv4 string `url:"external_network_port_ipv4,omitempty" json:"external_network_port_ipv4,omitempty"`
|
||||
|
||||
// Filter by IP of the associated logical port binding
|
||||
// Required: false
|
||||
LogicalPortBindingIP string `url:"logical_port_binding_ip,omitempty" json:"logical_port_binding_ip,omitempty"`
|
||||
|
||||
// Display name of the associated logical port
|
||||
// Required: false
|
||||
LogicalPortDisplayName string `url:"logical_port_display_name,omitempty" json:"logical_port_display_name,omitempty"`
|
||||
|
||||
// Filter by display name of the associated external network
|
||||
// Required: false
|
||||
ExternalNetworkDisplayName string `url:"external_network_display_name,omitempty" json:"external_network_display_name,omitempty"`
|
||||
|
||||
// Filter by display name of the associated router
|
||||
// Required: false
|
||||
RouterDisplayName string `url:"router_display_name,omitempty" json:"router_display_name,omitempty"`
|
||||
|
||||
// Updated at lower bound (greater than or equal to)
|
||||
// Required: false
|
||||
UpdatedFrom string `url:"updated_from,omitempty" json:"updated_from,omitempty"`
|
||||
|
||||
// Updated at upper bound (less than)
|
||||
// Required: false
|
||||
UpdatedTo string `url:"updated_to,omitempty" json:"updated_to,omitempty"`
|
||||
|
||||
// Created at lower bound (greater than or equal to)
|
||||
// Required: false
|
||||
CreatedFrom string `url:"created_from,omitempty" json:"created_from,omitempty"`
|
||||
|
||||
// Created at upper bound (less than)
|
||||
// Required: false
|
||||
CreatedTo string `url:"created_to,omitempty" json:"created_to,omitempty"`
|
||||
|
||||
// Page number for pagination
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of results per page
|
||||
// Required: false
|
||||
PerPage uint64 `url:"per_page,omitempty" json:"per_page,omitempty"`
|
||||
|
||||
// Field to sort by (enabled, created_at, updated_at, external_network_port_ipv4, logical_port_binding_ip, logical_port_display_name, external_network_display_name, router_display_name)
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
|
||||
// Sort order (asc/desc)
|
||||
// Required: false
|
||||
SortOrder string `url:"sort_order,omitempty" json:"sort_order,omitempty"`
|
||||
}
|
||||
|
||||
// List of floating ips
|
||||
func (fi FloatingIPs) List(ctx context.Context, req ListRequest) (*FloatingIPsList, error) {
|
||||
res, err := fi.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
objects := []RecordFloatingIP{}
|
||||
|
||||
err = json.Unmarshal(res, &objects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := FloatingIPsList{Objects: objects}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all floating ips as an array of bytes
|
||||
func (fi FloatingIPs) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/list"
|
||||
|
||||
res, err := fi.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
145
pkg/sdn/flips/models.go
Normal file
145
pkg/sdn/flips/models.go
Normal file
@@ -0,0 +1,145 @@
|
||||
package flips
|
||||
|
||||
// List of floating ips
|
||||
type FloatingIPsList struct {
|
||||
Objects []RecordFloatingIP
|
||||
}
|
||||
|
||||
// Main info about a floating ip
|
||||
type RecordFloatingIP struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Created at
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
||||
// Details of an external network port
|
||||
ExternalNetworkPort ExternalNetworkPort `json:"external_network_port"`
|
||||
|
||||
// ID of a floating IP
|
||||
ID string `json:"id"`
|
||||
|
||||
// Details of a logical port
|
||||
LogicalPort LogicalPort `json:"logical_port"`
|
||||
|
||||
// Details of a router
|
||||
Router Router `json:"router"`
|
||||
|
||||
// Updated at
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
// Version ID
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
// Info about a router
|
||||
type Router struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Created at
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Display name
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Is a security policy enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// Updated at
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
// Version ID
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
// Info about a logical port
|
||||
type LogicalPort struct {
|
||||
|
||||
// ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Adapter MAC
|
||||
AdapterMAC string `json:"adapter_mac"`
|
||||
|
||||
// Is address detected
|
||||
AddressDetection bool `json:"address_detection"`
|
||||
|
||||
// Description
|
||||
Description string `json:"description"`
|
||||
|
||||
// Created at
|
||||
CreatedAt string `json:"created_at"`
|
||||
|
||||
// Display name
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Is a logical port enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// Hypervisor
|
||||
Hypervisor string `json:"hypervisor"`
|
||||
|
||||
// Hypervisor display name
|
||||
HypervisorDisplayName string `json:"hypervisor_display_name"`
|
||||
|
||||
// Unique identifier
|
||||
UniqueIdentifier string `json:"unique_identifier"`
|
||||
|
||||
// Updated at
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
|
||||
// Version ID
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
|
||||
// Details of external network ports
|
||||
type ExternalNetworkPort struct {
|
||||
// Access group ID
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
|
||||
// Access group name
|
||||
AccessGroupName string `json:"access_group_name"`
|
||||
|
||||
// Comment
|
||||
Comment string `json:"comment"`
|
||||
|
||||
// Display name
|
||||
DisplayName string `json:"display_name"`
|
||||
|
||||
// Is a security policy enabled
|
||||
Enabled bool `json:"enabled"`
|
||||
|
||||
// External network ID
|
||||
ExternalNetworkID string `json:"external_network_id"`
|
||||
|
||||
// ID
|
||||
ID string `json:"id"`
|
||||
|
||||
// IP v4
|
||||
IPv4 string `json:"ipv4"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Version ID
|
||||
VersionID uint64 `json:"version_id"`
|
||||
}
|
||||
57
pkg/sdn/flips/update.go
Normal file
57
pkg/sdn/flips/update.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package flips
|
||||
|
||||
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 a floating ip
|
||||
type UpdateRequest struct {
|
||||
// ID of a floating IP
|
||||
// Required: true
|
||||
FloatingIPID string `url:"floating_ip_id" json:"floating_ip_id" validate:"required"`
|
||||
|
||||
// Version ID
|
||||
// Required: true
|
||||
VersionID uint64 `url:"version_id" json:"version_id" validate:"required"`
|
||||
|
||||
// ID of an external network port
|
||||
// Required: true
|
||||
ExtNetPortID string `url:"external_network_port_id" json:"external_network_port_id" validate:"required"`
|
||||
|
||||
// ID of a logical network port
|
||||
// Required: true
|
||||
LogicalPortID string `url:"logical_port_id" json:"logical_port_id" validate:"required"`
|
||||
|
||||
// ID of a router
|
||||
// Required: true
|
||||
RouterID string `url:"router_id" json:"router_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Update updates a floating ip
|
||||
func (fi FloatingIPs) Update(ctx context.Context, req UpdateRequest) (*RecordFloatingIP, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/floating_ip/update"
|
||||
|
||||
res, err := fi.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordFloatingIP{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
Reference in New Issue
Block a user