This commit is contained in:
2023-09-18 14:13:55 +03:00
parent 4d9b8fc9d8
commit df8b045e77
16 changed files with 413 additions and 281 deletions

View File

@@ -36,7 +36,7 @@ type CreateInRGRequest struct {
// Number of pre created reservations
// Required: false
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
}
// CreateInRG creates VINS in resource group level

View File

@@ -397,9 +397,11 @@ type NATConfig struct {
Network string `json:"network"`
// List NAT rules
Rules ListNATRules `json:"rules"`
Rules ListNATRulesConfig `json:"rules"`
}
type ListNATRulesConfig []ItemNATRule
// Main information about GW
type RecordGW struct {
// CKey
@@ -570,9 +572,6 @@ type RecordVINS struct {
// Main information about VNF device
VNFDev RecordVNFDev `json:"VNFDev"`
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
@@ -582,12 +581,24 @@ type RecordVINS struct {
// List of VINS computes
Computes ListVINSComputes `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Default QOS
DefaultQOS QOS `json:"defaultQos"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`

View File

@@ -3,7 +3,7 @@ package k8ci
// FilterByID returns ListK8CI with specified ID.
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.RecordK8CI.ID == id
return ikc.RecordK8CIList.ID == id
}
return lkc.FilterFunc(predicate)
@@ -12,7 +12,7 @@ func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
// FilterByName returns ListK8CI with specified Name.
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
predicate := func(ikc ItemK8CI) bool {
return ikc.RecordK8CI.Name == name
return ikc.RecordK8CIList.Name == name
}
return lkc.FilterFunc(predicate)

View File

@@ -6,7 +6,7 @@ var k8ciItems = ListK8CI{
Data: []ItemK8CI{
{
CreatedTime: 123902139,
RecordK8CI: RecordK8CI{
RecordK8CIList: RecordK8CIList{
Description: "",
GID: 0,
GUID: 1,
@@ -17,7 +17,7 @@ var k8ciItems = ListK8CI{
MaxMasterCount: 2,
MaxWorkerCount: 3,
Name: "purple_snake",
SharedWith: []interface{}{},
SharedWith: []uint64{},
Status: "ENABLED",
Version: "1",
WorkerDriver: "KVM_X86",
@@ -26,7 +26,7 @@ var k8ciItems = ListK8CI{
},
{
CreatedTime: 123902232,
RecordK8CI: RecordK8CI{
RecordK8CIList: RecordK8CIList{
Description: "",
GID: 0,
GUID: 2,
@@ -37,7 +37,7 @@ var k8ciItems = ListK8CI{
MaxMasterCount: 3,
MaxWorkerCount: 5,
Name: "green_giant",
SharedWith: []interface{}{},
SharedWith: []uint64{},
Status: "DISABLED",
Version: "2",
WorkerDriver: "KVM_X86",
@@ -46,7 +46,7 @@ var k8ciItems = ListK8CI{
},
{
CreatedTime: 123902335,
RecordK8CI: RecordK8CI{
RecordK8CIList: RecordK8CIList{
Description: "",
GID: 0,
GUID: 3,
@@ -57,7 +57,7 @@ var k8ciItems = ListK8CI{
MaxMasterCount: 5,
MaxWorkerCount: 9,
Name: "magenta_cloud",
SharedWith: []interface{}{},
SharedWith: []uint64{},
Status: "ENABLED",
Version: "3",
WorkerDriver: "KVM_X86",

View File

@@ -1,11 +1,11 @@
package k8ci
// Main information about K8CI
// Main information about K8CI in List
type ItemK8CI struct {
// Created time
CreatedTime uint64 `json:"createdTime"`
// Detailed information about K8CI
RecordK8CI
RecordK8CIList
}
// List K8CI
@@ -17,7 +17,55 @@ type ListK8CI struct {
EntryCount uint64 `json:"entryCount"`
}
// Detailed information about K8CI
// Detailed information about K8CI in List
type RecordK8CIList struct {
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Load balancer image ID
LBImageID uint64 `json:"lbImageId"`
// Master driver
MasterDriver string `json:"masterDriver"`
// Master image ID
MasterImageID uint64 `json:"masterImageId"`
// Max master count
MaxMasterCount uint64 `json:"maxMasterCount"`
// Max worker count
MaxWorkerCount uint64 `json:"maxWorkerCount"`
// Name
Name string `json:"name"`
// Shared with
SharedWith []uint64 `json:"sharedWith"`
// Status
Status string `json:"status"`
// Version
Version string `json:"version"`
// Worker driver
WorkerDriver string `json:"workerDriver"`
// Worker image ID
WorkerImageID uint64 `json:"workerImageId"`
}
// Detailed information about K8CI
type RecordK8CI struct {
// Description
Description string `json:"desc"`
@@ -52,8 +100,11 @@ type RecordK8CI struct {
// Name
Name string `json:"name"`
//NetworkPlugins
NetworkPlugins []string `json:"networkPlugins"`
// Shared with
SharedWith []interface{} `json:"sharedWith"`
SharedWith []uint64 `json:"sharedWith"`
// Status
Status string `json:"status"`

View File

@@ -2,12 +2,24 @@ package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
type Route struct {
// Destination network
Destination string `url:"destination" json:"destination" validate:"required"`
//Destination network mask in 255.255.255.255 format
Netmask string `url:"netmask" json:"netmask" validate:"required"`
//Next hop host, IP address from ViNS ID free IP pool
Gateway string `url:"gateway" json:"gateway" validate:"required"`
}
// Request struct for create VINS in account
type CreateInAccountRequest struct {
// VINS name
@@ -34,11 +46,20 @@ type CreateInAccountRequest struct {
// Required: false
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
// List of static routes, each item must have destination, netmask, and gateway fields
// Required: false
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
type wrapperCreateRequestInAcc struct {
CreateInAccountRequest
Routes []string `url:"routes,omitempty"`
}
// CreateInAccount creates VINS in account level
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -48,9 +69,31 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
}
}
var routes []string
if len(req.Routes) != 0 {
routes = make([]string, 0, len(req.Routes))
for r := range req.Routes {
b, err := json.Marshal(req.Routes[r])
if err != nil {
return 0, err
}
routes = append(routes, string(b))
}
} else {
routes = []string{"[]"}
}
reqWrapped := wrapperCreateRequestInAcc{
CreateInAccountRequest: req,
Routes: routes,
}
url := "/cloudbroker/vins/createInAccount"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}

View File

@@ -2,6 +2,7 @@ package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -36,13 +37,22 @@ type CreateInRGRequest struct {
// Number of pre created reservations
// Required: false
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
// List of static routes, each item must have destination, netmask, and gateway fields
// Required: false
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
type wrapperCreateRequestInRG struct {
CreateInRGRequest
Routes []string `url:"routes,omitempty"`
}
// CreateInRG creates VINS in resource group level
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
err := validators.ValidateRequest(req)
@@ -51,10 +61,31 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
return 0, validators.ValidationError(validationError)
}
}
var routes []string
if len(req.Routes) != 0 {
routes = make([]string, 0, len(req.Routes))
for r := range req.Routes {
b, err := json.Marshal(req.Routes[r])
if err != nil {
return 0, err
}
routes = append(routes, string(b))
}
} else {
routes = []string{"[]"}
}
reqWrapped := wrapperCreateRequestInRG{
CreateInRGRequest: req,
Routes: routes,
}
url := "/cloudbroker/vins/createInRG"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}

View File

@@ -345,7 +345,7 @@ type NATConfig struct {
Network string `json:"network"`
// Rules
Rules []interface{} `json:"rules"`
Rules []ItemNATRule `json:"rules"`
}
// Main information about NAT
@@ -357,7 +357,7 @@ type RecordNAT struct {
InfoVNF
}
// NAT/GW/NAT details
// DHCP/GW/NAT details
type InfoVNF struct {
// CKey
CKey string `json:"_ckey"`
@@ -368,9 +368,6 @@ type InfoVNF struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Config
Config NATConfig `json:"config"`
// CreatedTime
CreatedTime uint64 `json:"createdTime"`
@@ -401,6 +398,9 @@ type InfoVNF struct {
// Pure virtual
PureVirtual bool `json:"pureVirtual"`
// Routes
Routes ListRoutes `json:"routes"`
// Status
Status string `json:"status"`
@@ -411,6 +411,28 @@ type InfoVNF struct {
Type string `json:"type"`
}
type ListRoutes []ItemRoutes
type ItemRoutes struct {
//Compute Id
ComputeIds []uint64 `json:"computeIds"`
// Destination network
Destination string `json:"destination"`
//Next hop host, IP address from ViNS ID free IP pool
Gateway string `json:"gateway"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
//Destination network mask in 255.255.255.255 format
Netmask string `json:"netmask"`
}
// main information about VNF
type RecordVNFs struct {
// DHCP
@@ -428,12 +450,6 @@ type RecordVINS struct {
// VNF device
VNFDev VNFDev `json:"VNFDev"`
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`