v1.16.0
This commit is contained in:
46
pkg/cloudbroker/qospolicy/create.go
Normal file
46
pkg/cloudbroker/qospolicy/create.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
// Account ID that owns QoS policy
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
|
||||
// QoS policy name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// QoS policy description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// Create creates a new QoS policy
|
||||
func (qp QoSPolicy) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/create"
|
||||
|
||||
res, err := qp.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
94
pkg/cloudbroker/qospolicy/create_rule.go
Normal file
94
pkg/cloudbroker/qospolicy/create_rule.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRuleRequest struct {
|
||||
// ID of the parent QoS policy this rule belongs to
|
||||
// Required: true
|
||||
QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
|
||||
|
||||
// QoS policy rule description
|
||||
// Default: ""
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Rule priority in OVS (higher number = higher priority)
|
||||
// Possible values: [0, 65535]
|
||||
// Required: true
|
||||
Priority *uint64 `url:"priority" json:"priority" validate:"required,min=0,max=65535"`
|
||||
|
||||
// Traffic direction
|
||||
// Possible values: outbound
|
||||
// Required: true
|
||||
Direction string `url:"direction" json:"direction" validate:"required,oneof=outbound"`
|
||||
|
||||
// IP protocol to match
|
||||
// Possible values: tcp, udp, icmp
|
||||
// Required: true
|
||||
Protocol string `url:"protocol" json:"protocol" validate:"required,oneof=tcp udp icmp"`
|
||||
|
||||
// Priority Code Point. L2 marking
|
||||
// Possible values: [0, 7]
|
||||
// Required: false
|
||||
PCPTag *uint64 `url:"pcp_tag,omitempty" json:"pcp_tag,omitempty" validate:"required_without_all=DSCPValue,omitempty,min=0,max=7"`
|
||||
|
||||
// DSCP value (0-63). L3 marking
|
||||
// Possible values: [0, 63]
|
||||
// Required: false
|
||||
DSCPValue *uint64 `url:"dscp_value,omitempty" json:"dscp_value,omitempty" validate:"required_without_all=PCPTag,omitempty,min=0,max=63"`
|
||||
|
||||
// Source IP address for traffic filtering
|
||||
// Required: false
|
||||
SrcIP string `url:"src_ip,omitempty" json:"src_ip,omitempty"`
|
||||
|
||||
// Destination IP address for traffic filtering
|
||||
// Required: false
|
||||
DstIP string `url:"dst_ip,omitempty" json:"dst_ip,omitempty"`
|
||||
|
||||
// Source MAC address for traffic filtering
|
||||
// Required: false
|
||||
SrcMAC string `url:"src_mac,omitempty" json:"src_mac,omitempty" validate:"omitempty,mac"`
|
||||
|
||||
// Destination MAC address for traffic filtering
|
||||
// Required: false
|
||||
DstMAC string `url:"dst_mac,omitempty" json:"dst_mac,omitempty" validate:"omitempty,mac"`
|
||||
|
||||
// Source port for traffic filtering (TCP/UDP only)
|
||||
// Possible values: [1, 65535]
|
||||
// Required: false
|
||||
SrcPort uint64 `url:"src_port,omitempty" json:"src_port,omitempty" validate:"omitempty,min=1,max=65535"`
|
||||
|
||||
// Destination port for traffic filtering (TCP/UDP only)
|
||||
// Possible values: [1, 65535]
|
||||
// Required: false
|
||||
DstPort uint64 `url:"dst_port,omitempty" json:"dst_port,omitempty" validate:"omitempty,min=1,max=65535"`
|
||||
}
|
||||
|
||||
// CreateRule creates a new rule for a QoS policy
|
||||
func (qp QoSPolicy) CreateRule(ctx context.Context, req CreateRuleRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/create_rule"
|
||||
|
||||
res, err := qp.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/cloudbroker/qospolicy/delete.go
Normal file
37
pkg/cloudbroker/qospolicy/delete.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
// QoS policy ID
|
||||
// Required: true
|
||||
QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/delete"
|
||||
|
||||
res, err := qp.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
41
pkg/cloudbroker/qospolicy/delete_rule.go
Normal file
41
pkg/cloudbroker/qospolicy/delete_rule.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type DeleteRuleRequest struct {
|
||||
// ID of the QoS policy
|
||||
// Required: true
|
||||
QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
|
||||
|
||||
// ID of the rule to delete
|
||||
// Required: true
|
||||
RuleID uint64 `url:"rule_id" json:"rule_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) DeleteRule(ctx context.Context, req DeleteRuleRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/delete_rule"
|
||||
|
||||
res, err := qp.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
89
pkg/cloudbroker/qospolicy/filter.go
Normal file
89
pkg/cloudbroker/qospolicy/filter.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package qospolicy
|
||||
|
||||
// FilterByID returns ListQoSPolicies with specified ID
|
||||
func (lqp ListQoSPolicies) FilterByID(id uint64) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.ID == id
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListQoSPolicies with specified Name
|
||||
func (lqp ListQoSPolicies) FilterByName(name string) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.Name == name
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListQoSPolicies with specified AccountID
|
||||
func (lqp ListQoSPolicies) FilterByAccountID(accountID uint64) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.AccountID == accountID
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListQoSPolicies with specified Status
|
||||
func (lqp ListQoSPolicies) FilterByStatus(status string) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.Status == status
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDescription returns ListQoSPolicies with specified Description
|
||||
func (lqp ListQoSPolicies) FilterByDescription(description string) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.Description == description
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListQoSPolicies with specified CreatedBy
|
||||
func (lqp ListQoSPolicies) FilterByCreatedBy(createdBy string) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListQoSPolicies with specified UpdatedBy
|
||||
func (lqp ListQoSPolicies) FilterByUpdatedBy(updatedBy string) ListQoSPolicies {
|
||||
predicate := func(iqp ItemQoSPolicy) bool {
|
||||
return iqp.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lqp.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListQoSPolicies based on a user-specified predicate
|
||||
func (lqp ListQoSPolicies) FilterFunc(predicate func(ItemQoSPolicy) bool) ListQoSPolicies {
|
||||
var result ListQoSPolicies
|
||||
|
||||
for _, item := range lqp.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemQoSPolicy
|
||||
// If none was found, returns an empty struct
|
||||
func (lqp ListQoSPolicies) FindOne() ItemQoSPolicy {
|
||||
if len(lqp.Data) == 0 {
|
||||
return ItemQoSPolicy{}
|
||||
}
|
||||
|
||||
return lqp.Data[0]
|
||||
}
|
||||
97
pkg/cloudbroker/qospolicy/filter_test.go
Normal file
97
pkg/cloudbroker/qospolicy/filter_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package qospolicy
|
||||
|
||||
import "testing"
|
||||
|
||||
var qosPolicies = ListQoSPolicies{
|
||||
Data: []ItemQoSPolicy{
|
||||
{
|
||||
ID: 1,
|
||||
AccountID: 1,
|
||||
Name: "qos1",
|
||||
Description: "some desc",
|
||||
Status: "ENABLED",
|
||||
CreatedBy: "user",
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
AccountID: 3,
|
||||
Name: "qos3",
|
||||
Description: "some desc",
|
||||
Status: "ENABLED",
|
||||
CreatedBy: "anotheruser",
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
AccountID: 3,
|
||||
Name: "qos5",
|
||||
Description: "some other desc",
|
||||
Status: "DISABLED",
|
||||
CreatedBy: "anotheruser",
|
||||
UpdatedBy: "user",
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := qosPolicies.FilterByID(1).FindOne()
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := qosPolicies.FilterByName("qos3").FindOne()
|
||||
if actual.Name != "qos3" {
|
||||
t.Fatal("expected Name qos3, found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDescription(t *testing.T) {
|
||||
actual := qosPolicies.FilterByDescription("some desc")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Description != "some desc" {
|
||||
t.Fatal("expected Description 'some desc', found: ", item.Description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByAccountID(t *testing.T) {
|
||||
actual := qosPolicies.FilterByAccountID(1).FindOne()
|
||||
if actual.AccountID != 1 {
|
||||
t.Fatal("expected AccountID 1, found: ", actual.AccountID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := qosPolicies.FilterByStatus("DISABLED").FindOne()
|
||||
if actual.Status != "DISABLED" {
|
||||
t.Fatal("expected Status DISABLED, found: ", actual.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := qosPolicies.FilterByCreatedBy("anotheruser")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedBy != "anotheruser" {
|
||||
t.Fatal("expected CreatedBy 'anotheruser', found: ", item.CreatedBy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByUpdatedBy(t *testing.T) {
|
||||
actual := qosPolicies.FilterByUpdatedBy("user").FindOne()
|
||||
if actual.UpdatedBy != "user" {
|
||||
t.Fatal("expected UpdatedBy 'user', found: ", actual.UpdatedBy)
|
||||
}
|
||||
}
|
||||
43
pkg/cloudbroker/qospolicy/get.go
Normal file
43
pkg/cloudbroker/qospolicy/get.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// QoS policy ID
|
||||
// Required: true
|
||||
QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) Get(ctx context.Context, req GetRequest) (*RecordQoSPolicy, error) {
|
||||
res, err := qp.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordQoSPolicy{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/get"
|
||||
|
||||
res, err := qp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
88
pkg/cloudbroker/qospolicy/list.go
Normal file
88
pkg/cloudbroker/qospolicy/list.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package qospolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Find QoS policy by id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by account id
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||
|
||||
// Find by QoS policy name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by QoS policy description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Find by QoS policy status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by created after time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedMin uint64 `url:"created_min,omitempty" json:"created_min,omitempty"`
|
||||
|
||||
// Find by created before time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedMax uint64 `url:"created_max,omitempty" json:"created_max,omitempty"`
|
||||
|
||||
// Find by updated after time (unix timestamp)
|
||||
// Required: false
|
||||
UpdatedMin uint64 `url:"updated_min,omitempty" json:"updated_min,omitempty"`
|
||||
|
||||
// Find by updated before time (unix timestamp)
|
||||
// Required: false
|
||||
UpdatedMax uint64 `url:"updated_max,omitempty" json:"updated_max,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format ±<field>
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of QoS policies as a ListQoSPolicies struct
|
||||
func (qp QoSPolicy) List(ctx context.Context, req ListRequest) (*ListQoSPolicies, error) {
|
||||
res, err := qp.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListQoSPolicies{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of QoS policies as an array of bytes
|
||||
func (qp QoSPolicy) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/list"
|
||||
|
||||
res, err := qp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
122
pkg/cloudbroker/qospolicy/models.go
Normal file
122
pkg/cloudbroker/qospolicy/models.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package qospolicy
|
||||
|
||||
type ListQoSPolicies struct {
|
||||
// List
|
||||
Data []ItemQoSPolicy `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ItemQoSPolicy struct {
|
||||
// ID of the QoS policy
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// Account ID that owns the QoS policy
|
||||
AccountID uint64 `json:"account_id"`
|
||||
|
||||
// Name of the QoS policy
|
||||
Name string `json:"name"`
|
||||
|
||||
// Description of the QoS policy
|
||||
Description string `json:"description"`
|
||||
|
||||
// Status of the QoS policy
|
||||
Status string `json:"status"`
|
||||
|
||||
// Created at (unix timestamp)
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
|
||||
// Updated at (unix timestamp)
|
||||
UpdatedAt uint64 `json:"updated_at"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"created_by"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
|
||||
// List of rules
|
||||
Rules Rules `json:"rules"`
|
||||
}
|
||||
|
||||
type RecordQoSPolicy struct {
|
||||
// ID of the QoS policy
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// Account ID that owns the QoS policy
|
||||
AccountID uint64 `json:"account_id"`
|
||||
|
||||
// Name of the QoS policy
|
||||
Name string `json:"name"`
|
||||
|
||||
// Description of the QoS policy
|
||||
Description string `json:"description"`
|
||||
|
||||
// Status of the QoS policy
|
||||
Status string `json:"status"`
|
||||
|
||||
// Created at (unix timestamp)
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
|
||||
// Updated at (unix timestamp)
|
||||
UpdatedAt uint64 `json:"updated_at"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"created_by"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
|
||||
// List of rules
|
||||
Rules Rules `json:"rules"`
|
||||
}
|
||||
|
||||
type Rules []Rule
|
||||
|
||||
type Rule struct {
|
||||
// ID of the rule
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Description of the rule
|
||||
Description string `json:"description"`
|
||||
|
||||
// Rule priority in OVS (higher number = higher priority)
|
||||
Priority uint64 `json:"priority"`
|
||||
|
||||
// Traffic direction
|
||||
Direction string `json:"direction"`
|
||||
|
||||
// IP protocol
|
||||
Protocol string `json:"protocol"`
|
||||
|
||||
// Priority Code Point (0-7). L2 marking
|
||||
PCPTag uint64 `json:"pcp_tag"`
|
||||
|
||||
// DSCP value (0-63). L3 marking
|
||||
DSCPValue uint64 `json:"dscp_value"`
|
||||
|
||||
// Source IP address
|
||||
SrcIP string `json:"src_ip"`
|
||||
|
||||
// Destination IP address
|
||||
DstIP string `json:"dst_ip"`
|
||||
|
||||
// Source MAC address
|
||||
SrcMAC string `json:"src_mac"`
|
||||
|
||||
// Destination MAC address
|
||||
DstMAC string `json:"dst_mac"`
|
||||
|
||||
// Source port
|
||||
SrcPort uint64 `json:"src_port"`
|
||||
|
||||
// Destination port
|
||||
DstPort uint64 `json:"dst_port"`
|
||||
}
|
||||
15
pkg/cloudbroker/qospolicy/qos_policy.go
Normal file
15
pkg/cloudbroker/qospolicy/qos_policy.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package qospolicy
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to QoS policy
|
||||
type QoSPolicy struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for QoS policy endpoint
|
||||
func New(client interfaces.Caller) *QoSPolicy {
|
||||
return &QoSPolicy{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
39
pkg/cloudbroker/qospolicy/sorting.go
Normal file
39
pkg/cloudbroker/qospolicy/sorting.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package qospolicy
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedAt sorts ListQoSPolicies by the CreatedAt field in ascending order
|
||||
// If inverse param is set to true, the order is reversed
|
||||
func (lqp ListQoSPolicies) SortByCreatedAt(inverse bool) ListQoSPolicies {
|
||||
if len(lqp.Data) < 2 {
|
||||
return lqp
|
||||
}
|
||||
|
||||
sort.Slice(lqp.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lqp.Data[i].CreatedAt > lqp.Data[j].CreatedAt
|
||||
}
|
||||
|
||||
return lqp.Data[i].CreatedAt < lqp.Data[j].CreatedAt
|
||||
})
|
||||
|
||||
return lqp
|
||||
}
|
||||
|
||||
// SortByUpdatedAt sorts ListQoSPolicies by the UpdatedAt field in ascending order
|
||||
// If inverse param is set to true, the order is reversed
|
||||
func (lqp ListQoSPolicies) SortByUpdatedAt(inverse bool) ListQoSPolicies {
|
||||
if len(lqp.Data) < 2 {
|
||||
return lqp
|
||||
}
|
||||
|
||||
sort.Slice(lqp.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lqp.Data[i].UpdatedAt > lqp.Data[j].UpdatedAt
|
||||
}
|
||||
|
||||
return lqp.Data[i].UpdatedAt < lqp.Data[j].UpdatedAt
|
||||
})
|
||||
|
||||
return lqp
|
||||
}
|
||||
52
pkg/cloudbroker/qospolicy/update.go
Normal file
52
pkg/cloudbroker/qospolicy/update.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package qospolicy
|
||||
|
||||
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 UpdateRequest struct {
|
||||
// QoS policy ID
|
||||
// Required: true
|
||||
QoSPolicyID uint64 `url:"qos_policy_id" json:"qos_policy_id" validate:"required"`
|
||||
|
||||
// New QoS policy name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// New QoS policy description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) Update(ctx context.Context, req UpdateRequest) (*RecordQoSPolicy, error) {
|
||||
res, err := qp.UpdateRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordQoSPolicy{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (qp QoSPolicy) UpdateRaw(ctx context.Context, req UpdateRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/network_qos_policy/update"
|
||||
|
||||
res, err := qp.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user