This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// AuditsRequest struct to get audits
type AuditsRequest struct {
// ID of the VINS
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// Audits gets audit records for the specified VINS object
func (v VINS) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/audits"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,105 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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"`
}
// CreateInAccountRequest struct to create VINS in account
type CreateInAccountRequest struct {
// VINS name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Grid ID
// Required: false
GID uint64 `url:"gid,omitempty" json:"gid,omitempty"`
// Private network IP CIDR
// Required: false
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// List of DNS ip address
// Required: false
DNSList []string `url:"dnsList" json:"dnsList,omitempty"`
// Number of pre created reservations
// 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"`
}
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)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
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 := "/cloudapi/vins/createInAccount"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,99 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateInRGRequest struct to create VINS in resource group
type CreateInRGRequest struct {
// VINS name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Private network IP CIDR
// Required: false
IPCIDR string `url:"ipcidr,omitempty" json:"ipcidr,omitempty"`
// External network ID
// Required: false
// -1 - not connect to extnet, 0 - auto select, 1+ - extnet ID
ExtNetID int64 `url:"extNetId" json:"extNetId"`
// External IP, related only for extNetId >= 0
// Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
// Description
// Required: false
Description string `url:"desc,omitempty" json:"desc,omitempty"`
// List of DNS ip address
// Required: false
DNSList []string `url:"dnsList" json:"dnsList,omitempty"`
// Number of pre created reservations
// 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"`
}
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)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
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 := "/cloudapi/vins/createInRG"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,50 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteRequest struct to delete VINS
type DeleteRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Set to True if you want force delete non-empty VINS.
// Primarily, VINS is considered non-empty if it has virtual machines connected to it,
// and force flag will detach them from the VINS being deleted.
// Otherwise method will return an error
// Required: false
Force bool `url:"force,omitempty" json:"force,omitempty"`
// Set to True if you want to destroy VINS and all linked resources, if any, immediately.
// Otherwise, they will be placed into recycle bin and could be restored later within the recycle bin's purge period
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
// Delete deletes VINS
func (v VINS) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/delete"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,62 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DisableEnableRequest struct to disable/enable VINS
type DisableEnableRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// Disable disables VINS
func (v VINS) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/disable"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
// Enable enables VINS
func (v VINS) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/enable"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,43 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DNSApplyRequest struct to apply new DNS list in VINS
type DNSApplyRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// List of DNS ip address
// Required: false
DNSList []string `url:"dnsList" json:"dnsList"`
}
// DNSApply applies new DNS list in VINS
func (v VINS) DNSApply(ctx context.Context, req DNSApplyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/dnsApply"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,46 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ExtNetConnectRequest struct to connect to external network
type ExtNetConnectRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// External network ID
// Required: false
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// Directly set IP address
// Required: false
IP string `url:"ip,omitempty" json:"ip,omitempty"`
}
// ExtNetConnect connect VINS to external network
func (v VINS) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/extNetConnect"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ExtNetDisconnectRequest struct to disconnect VINS from external network
type ExtNetDisconnectRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// ExtNetDisconnect disconnects VINS from external network
func (v VINS) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/extNetDisconnect"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,41 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ExtNetListRequest struct to get list of VINS external network connections
type ExtNetListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// ExtNetList shows list of VINS external network connections
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (*ListExtNets, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/extNetList"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := &ListExtNets{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,80 @@
package vins
// FilterByID returns ListVINS with specified ID.
func (lv ListVINS) FilterByID(id uint64) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.ID == id
}
return lv.FilterFunc(predicate)
}
// FilterByName returns ListVINS with specified Name.
func (lv ListVINS) FilterByName(name string) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.Name == name
}
return lv.FilterFunc(predicate)
}
// FilterByAccountID returns ListVINS with specified AccountID.
func (lv ListVINS) FilterByAccountID(accountID uint64) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.AccountID == accountID
}
return lv.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListVINS created by specified user.
func (lv ListVINS) FilterByCreatedBy(createdBy string) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.CreatedBy == createdBy
}
return lv.FilterFunc(predicate)
}
// FilterByUpdatedBy returns ListVINS updated by specified user.
func (lv ListVINS) FilterByUpdatedBy(updatedBy string) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.UpdatedBy == updatedBy
}
return lv.FilterFunc(predicate)
}
// FilterByDeletedBy returns ListVINS deleted by specified user.
func (lv ListVINS) FilterByDeletedBy(deletedBy string) ListVINS {
predicate := func(iv ItemVINS) bool {
return iv.DeletedBy == deletedBy
}
return lv.FilterFunc(predicate)
}
// FilterFunc allows filtering ListVINS based on a user-specified predicate.
func (lv ListVINS) FilterFunc(predicate func(ItemVINS) bool) ListVINS {
var result ListVINS
for _, item := range lv.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemVINS
// If none was found, returns an empty struct.
func (lv ListVINS) FindOne() ItemVINS {
if len(lv.Data) == 0 {
return ItemVINS{}
}
return lv.Data[0]
}

View File

@@ -0,0 +1,121 @@
package vins
import "testing"
var vinsItems = ListVINS{
Data: []ItemVINS{
{
AccountID: 1,
AccountName: "std",
CreatedBy: "sample_user_1@decs3o",
CreatedTime: 1676898844,
DeletedBy: "",
DeletedTime: 0,
ExternalIP: "",
ID: 1,
Name: "vins01",
Network: "192.168.1.0/24",
RGID: 7971,
RGName: "rg_01",
Status: "ENABLED",
UpdatedBy: "",
UpdatedTime: 0,
VXLANID: 3544,
},
{
AccountID: 2,
AccountName: "std2",
CreatedBy: "sample_user_1@decs3o",
CreatedTime: 1676898948,
DeletedBy: "",
DeletedTime: 0,
ExternalIP: "",
ID: 2,
Name: "vins02",
Network: "192.168.2.0/24",
RGID: 7972,
RGName: "rg_02",
Status: "ENABLED",
UpdatedBy: "",
UpdatedTime: 0,
VXLANID: 3545,
},
{
AccountID: 3,
AccountName: "std3",
CreatedBy: "sample_user_2@decs3o",
CreatedTime: 1676899026,
DeletedBy: "",
DeletedTime: 0,
ExternalIP: "",
ID: 3,
Name: "vins03",
Network: "192.168.3.0/24",
RGID: 7973,
RGName: "rg_03",
Status: "DISABLED",
UpdatedBy: "",
UpdatedTime: 0,
VXLANID: 3546,
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := vinsItems.FilterByID(2).FindOne()
if actual.ID != 2 {
t.Fatal("expected ID 2, found: ", actual.ID)
}
}
func TestFilterByName(t *testing.T) {
actual := vinsItems.FilterByName("vins01").FindOne()
if actual.Name != "vins01" {
t.Fatal("expected Name 'vins01', found: ", actual.Name)
}
}
func TestFilterByAccountID(t *testing.T) {
actual := vinsItems.FilterByAccountID(3).FindOne()
if actual.AccountID != 3 {
t.Fatal("expected AccountID 3, found: ", actual.AccountID)
}
}
func TestFilterByCreatedBy(t *testing.T) {
actual := vinsItems.FilterByCreatedBy("sample_user_1@decs3o")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.CreatedBy != "sample_user_1@decs3o" {
t.Fatal("expected CreatedBy 'sample_user_1@decs3o', found: ", item.CreatedBy)
}
}
}
func TestFilterFunc(t *testing.T) {
actual := vinsItems.FilterFunc(func(iv ItemVINS) bool {
return iv.RGID == 7971
}).
FindOne()
if actual.RGID != 7971 {
t.Fatal("expected RGID 7971, found: ", actual.RGID)
}
}
func TestSortByCreatedTime(t *testing.T) {
actual := vinsItems.SortByCreatedTime(false)
if actual.Data[0].CreatedTime != 1676898844 || actual.Data[2].CreatedTime != 1676899026 {
t.Fatal("expected ascending order, found descending")
}
}

46
pkg/cloudapi/vins/get.go Normal file
View File

@@ -0,0 +1,46 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get information about VINS
type GetRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// Get gets information about VINS by ID as a RecordVINS struct
func (v VINS) Get(ctx context.Context, req GetRequest) (*RecordVINS, error) {
res, err := v.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordVINS{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about VINS by ID as an array of bytes
func (v VINS) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/get"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

64
pkg/cloudapi/vins/ids.go Normal file
View File

@@ -0,0 +1,64 @@
package vins
// IDs gets array of VINSIDs from ListVINS struct
func (lv ListVINS) IDs() []uint64 {
res := make([]uint64, 0, len(lv.Data))
for _, v := range lv.Data {
res = append(res, v.ID)
}
return res
}
// IDs gets array of ExtNetIDs from ListExtNets struct
func (le ListExtNets) IDs() []uint64 {
res := make([]uint64, 0, len(le.Data))
for _, e := range le.Data {
res = append(res, e.ExtNetID)
}
return res
}
// IDs gets array of ComputeIDs from ListVINSComputes struct
func (lvc ListVINSComputes) IDs() []uint64 {
res := make([]uint64, 0, len(lvc))
for _, vc := range lvc {
res = append(res, vc.ID)
}
return res
}
// IDs gets array of NATRuleConfigIDs from ListNATRulesConfig struct
func (lnrc ListNATRulesConfig) IDs() []uint64 {
res := make([]uint64, 0, len(lnrc))
for _, nrc := range lnrc {
res = append(res, nrc.ID)
}
return res
}
// IDs gets array of NATRuleIDs from ListNATRules struct
func (lnr ListNATRules) IDs() []uint64 {
res := make([]uint64, 0, len(lnr.Data))
for _, nr := range lnr.Data {
res = append(res, nr.ID)
}
return res
}
// IDs gets array of StaticRouteIDs from ListStaticRoutes struct
func (lsr ListStaticRoutes) IDs() []uint64 {
res := make([]uint64, 0, len(lsr.Data))
for _, sr := range lsr.Data {
res = append(res, sr.ID)
}
return res
}
// IDs gets array of RouteIDs from ListRoutes struct
func (lr ListRoutes) IDs() []uint64 {
res := make([]uint64, 0, len(lr))
for _, r := range lr {
res = append(res, r.ID)
}
return res
}

View File

@@ -0,0 +1,40 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// IPListRequest struct for DHCP IP
type IPListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// IPList shows DHCP IP reservations on VINS
func (v VINS) IPList(ctx context.Context, req IPListRequest) (*ListIPs, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/ipList"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := &ListIPs{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,48 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// IPReleaseRequest struct for IP release
type IPReleaseRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// IP address
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// MAC address
// Required: false
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
}
// IPRelese delete IP reservation matched by specified IP & MAC address combination.
// If both IP and MAC address are empty strings, all IP reservations will be deleted.
func (v VINS) IPRelese(ctx context.Context, req IPReleaseRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/ipRelease"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,57 @@
package vins
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// IPReserveRequest struct for IP reserve
type IPReserveRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Type of the reservation
// Should be one of:
// - DHCP
// - VIP
// - EXCLUDE
// Required: true
Type string `url:"type" json:"type" validate:"vinsType"`
// IP address to use. Non-empty string is required for type "EXCLUDE".
// Ignored for types "DHCP" and "VIP".
// Required: false
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
// MAC address to associate with IP reservation.
// Ignored for type "EXCLUDE",
// non-empty string is required for "DHCP" and "VIP"
// Required: false
MAC string `url:"mac,omitempty" json:"mac,omitempty"`
// ID of the compute, associated with this reservation of type "DHCP".
// Ignored for other types
// Required: false
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
}
// IPReserve creates reservation on ViNS DHCP
func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/ipReserve"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

83
pkg/cloudapi/vins/list.go Normal file
View File

@@ -0,0 +1,83 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of VINSes
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by external network IP
// Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
// Find by VNF Device id
// Required: false
VNFDevId uint64 `url:"vnfdevId,omitempty" json:"vnfdevId,omitempty"`
// Include deleted
// Required: false
IncludeDeleted bool `url:"includeDeleted,omitempty" json:"includeDeleted,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of VINSes available for current user as a ListVINS struct
func (v VINS) List(ctx context.Context, req ListRequest) (*ListVINS, error) {
res, err := v.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of VINSes available for current user as an array of bytes
func (v VINS) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/list"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,76 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDeletedRequest struct to get list of deleted VINSes
type ListDeletedRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account ID
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by resource group id
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Find by external network IP
// Required: false
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
// Find by VNF Device id
// Required: false
VNFDevID uint64 `url:"vnfdevId,omitempty" json:"vnfdevId,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListDeleted gets list of deleted VINSes available for current user
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListVINS, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/listDeleted"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

822
pkg/cloudapi/vins/models.go Normal file
View File

@@ -0,0 +1,822 @@
package vins
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// External IP
ExternalIP string `json:"externalIP"`
// Extnet ID
ExtnetId uint64 `json:"extnetId"`
// Free IPs
FreeIPs int64 `json:"freeIPs"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Network
Network string `json:"network"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// VXLAN ID
VXLANID uint64 `json:"vxlanId"`
}
// List of VINSes
type ListVINS struct {
// Data
Data []ItemVINS `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List of VINSes search result
type SearchListVINS []ItemVINS
// Main information about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List of audits
type ListAudits []ItemAudit
// Main information about external network
type ItemExtNet struct {
// Default GW
DefaultGW string `json:"default_gw"`
// External network ID
ExtNetID uint64 `json:"ext_net_id"`
// IP
IP string `json:"ip"`
// Prefix len
PrefixLen uint64 `json:"prefixlen"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
}
// List of external networks
type ListExtNets struct {
// Data
Data []ItemExtNet `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about IP
type ItemIP struct {
// Client type
ClientType string `json:"clientType"`
// Domain name
DomainName string `json:"domainname"`
// Hostname
Hostname string `json:"hostname"`
// IP
IP string `json:"ip"`
// MAC
MAC string `json:"mac"`
// Type
Type string `json:"type"`
// Virtual machine ID
VMID uint64 `json:"vmId"`
}
// List of IPs
type ListIPs struct {
// Data
Data []ItemIP `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about VNF device
type RecordVNFDev struct {
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
// Capabilities
Capabilities []string `json:"capabilities"`
// Config
Config RecordVNFConfig `json:"config"`
// Config saved
ConfigSaved bool `json:"configSaved"`
// CustomPreConfig
CustomPreConfig bool `json:"customPrecfg"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// List of interfaces
Interfaces ListVNFInterfaces `json:"interfaces"`
// Lock status
LockStatus string `json:"lockStatus"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
// List of VINS IDs
VINS []uint64 `json:"vins"`
}
// VNF config
type RecordVNFConfig struct {
// MGMT
MGMT RecordMGMT `json:"mgmt"`
// Resources
Resources RecordResources `json:"resources"`
}
// Main information about MGMT
type RecordMGMT struct {
// IP address
IPAddress string `json:"ipaddr"`
// Password
Password string `json:"password"`
// SSH key
SSHKey string `json:"sshkey"`
// User
User string `json:"user"`
}
// Main information about resource
type RecordResources struct {
// Number of CPU
CPU uint64 `json:"cpu"`
// Number of RAM
RAM uint64 `json:"ram"`
// Stack ID
StackID uint64 `json:"stackId"`
// UUID
UUID string `json:"uuid"`
}
// Main information about VNF interface
type ItemVNFInterface struct {
// Bus number
BusNumber uint64 `json:"bus_number"`
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Default GW
DefGW string `json:"defGw"`
// Enabled
Enabled bool `json:"enabled"`
// FLIPGroup ID
FLIPGroupID uint64 `json:"flipgroupId"`
// GUID
GUID string `json:"guid"`
// IP address
IPAddress string `json:"ipAddress"`
// Listen SSH
ListenSSH bool `json:"listenSsh"`
// MAC
MAC string `json:"mac"`
// Maximum transmission unit
MTU uint64 `json:"mtu"`
// Libvirt Settings
LibvirtSettings LibvirtSettings `json:"libvirtSettings"`
// Name
Name string `json:"name"`
// Network type
NetID uint64 `json:"netId"`
// Network mask
NetMask uint64 `json:"netMask"`
// Network type
NetType string `json:"netType"`
// NodeID
NodeID int64 `json:"nodeId"`
// PCI slot
PCISlot int64 `json:"pciSlot"`
// QOS
QOS QOS `json:"qos"`
// Target
Target string `json:"target"`
// Type
Type string `json:"type"`
// List of VNF IDs
VNFs []uint64 `json:"vnfs"`
}
// Main information about QOS
type QOS struct {
// ERate
ERate uint64 `json:"eRate"`
// GUID
GUID string `json:"guid"`
// InBurst
InBurst uint64 `json:"inBurst"`
// InRate
InRate uint64 `json:"inRate"`
}
// List of VNF interfaces
type ListVNFInterfaces []ItemVNFInterface
// Main information about VINS compute
type ItemVINSCompute struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
}
// List of VINS computes
type ListVINSComputes []ItemVINSCompute
// Detailed information about VNF
type RecordVNFs struct {
// DHCP
DHCP RecordDHCP `json:"DHCP"`
// GW
GW RecordGW `json:"GW"`
// NAT
NAT RecordNAT `json:"NAT"`
}
// Main information about NAT
type RecordNAT struct {
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
// Config
Config NATConfig `json:"config"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Detailed information about devices
Devices RecordDevices `json:"devices"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Lock status
LockStatus string `json:"lockStatus"`
// Milestones
Milestones uint64 `json:"milestones"`
// Owner ID
OwnerID uint64 `json:"ownerId"`
// Owner type
OwnerType string `json:"ownerType"`
// Pure virtual
PureVirtual bool `json:"pureVirtual"`
// Routes
Routes ListRoutes `json:"routes"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
// NAT configuration
type NATConfig struct {
// Network mask
NetMask uint64 `json:"netmask"`
// Network
Network string `json:"network"`
// List NAT rules
Rules ListNATRulesConfig `json:"rules"`
}
type ListNATRulesConfig []ItemNATRule
// Main information about GW
type RecordGW struct {
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
// Config
Config RecordGWConfig `json:"config"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Detailed information about devices
Devices RecordDevices `json:"devices"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Lock status
LockStatus string `json:"lockStatus"`
// Milestones
Milestones uint64 `json:"milestones"`
// Owner ID
OwnerID uint64 `json:"ownerId"`
// Owner type
OwnerType string `json:"ownerType"`
// Pure virtual
PureVirtual bool `json:"pureVirtual"`
// Routes
Routes ListRoutes `json:"routes"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
// GW configuration
type RecordGWConfig struct {
// Default GW
DefaultGW string `json:"default_gw"`
// External network ID
ExtNetID uint64 `json:"ext_net_id"`
// External network IP
ExtNetIP string `json:"ext_net_ip"`
// External network mask
ExtNetMask uint64 `json:"ext_netmask"`
// QOS
QOS QOS `json:"qos"`
}
// Information about devices
type RecordDevices struct {
// Main information about primary device
Primary RecordPrimary `json:"primary"`
}
// Main information about primary device
type RecordPrimary struct {
// Device ID
DevID uint64 `json:"devId"`
// IFace01
IFace01 string `json:"iface01"`
// IFace02
IFace02 string `json:"iface02"`
}
// Main information about DHCP
type RecordDHCP struct {
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
// Config
Config RecordDHCPConfig `json:"config"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Detailed information about devices
Devices RecordDevices `json:"devices"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Lock status
LockStatus string `json:"lockStatus"`
// Milestones
Milestones uint64 `json:"milestones"`
// Owner ID
OwnerID uint64 `json:"ownerId"`
// Owner type
OwnerType string `json:"ownerType"`
// Pure virtual
PureVirtual bool `json:"pureVirtual"`
// Routes
Routes ListRoutes `json:"routes"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
// DHCP configuration
type RecordDHCPConfig struct {
// Default GW
DefaultGW string `json:"default_gw"`
// List of DNS
DNS []string `json:"dns"`
// IP end
IPEnd string `json:"ip_end"`
// IP start
IPStart string `json:"ip_start"`
// Lease
Lease uint64 `json:"lease"`
// Network mask
NetMask uint64 `json:"netmask"`
// Network
Network string `json:"network"`
// List of reservations
Reservations ListReservations `json:"reservations"`
}
// List of static routes
type ListStaticRoutes struct {
// Data
Data []ItemRoutes `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List of Routes
type ListRoutes []ItemRoutes
// Detailed information about Routes
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 string `json:"guid"`
// ID
ID uint64 `json:"id"`
//Destination network mask in 255.255.255.255 format
Netmask string `json:"netmask"`
}
// Detailed information about VINS
type RecordVINS struct {
// Main information about VNF device
VNFDev RecordVNFDev `json:"VNFDev"`
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// 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"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Lock status
LockStatus string `json:"lockStatus"`
// Manager ID
ManagerID uint64 `json:"managerId"`
// Manager type
ManagerType string `json:"managerType"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network mask
NetMask uint64 `json:"netMask"`
// Network
Network string `json:"network"`
// Pre reservaions number
PreReservaionsNum uint64 `json:"preReservationsNum"`
// Redundant
Redundant bool `json:"redundant"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// SecVNFDevID
SecVNFDevID uint64 `json:"secVnfDevId"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// User managed
UserManaged bool `json:"userManaged"`
// Main information about VNFs
VNFs RecordVNFs `json:"vnfs"`
// VXLAN ID
VXLANID uint64 `json:"vxlanId"`
}
// Information about libvirt settings
type LibvirtSettings struct {
// TX mode
TXMode string `json:"txmode"`
// IO event
IOEventFD string `json:"ioeventfd"`
// Event ID
EventIDx string `json:"event_idx"`
// Number of queues
Queues uint64 `json:"queues"`
// RX queue size
RXQueueSize uint64 `json:"rx_queue_size"`
// TX queue size
TXQueueSize uint64 `json:"tx_queue_size"`
// GUID
GUID string `json:"guid"`
}
// Main information about NAT rule
type ItemNATRule struct {
// ID
ID uint64 `json:"id"`
// Local IP
LocalIP string `json:"localIp"`
// Local port
LocalPort uint64 `json:"localPort"`
// Protocol
Protocol string `json:"protocol"`
// Public port end
PublicPortEnd uint64 `json:"publicPortEnd"`
// Public port start
PublicPortStart uint64 `json:"publicPortStart"`
// Virtual machine ID
VMID uint64 `json:"vmId"`
// Virtual machine name
VMName string `json:"vmName"`
}
// List of NAT rules
type ListNATRules struct {
// Data
Data []ItemNATRule `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about reservation
type ItemReservation struct {
// Client type
ClientType string `json:"clientType"`
// Description
Description string `json:"desc"`
// Domain name
DomainName string `json:"domainname"`
// Hostname
Hostname string `json:"hostname"`
// IP
IP string `json:"ip"`
// MAC
MAC string `json:"mac"`
// Type
Type string `json:"type"`
// Virtual machine ID
VMID uint64 `json:"vmId"`
}
// List of reservations
type ListReservations []ItemReservation

View File

@@ -0,0 +1,61 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// NATRuleAddRequest struct to create NAT rules
type NATRuleAddRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Internal IP address to apply this rule to
// Required: true
IntIP string `url:"intIp" json:"intIp" validate:"required"`
// External IP start port to use for this rule
// Required: true
ExtPortStart uint `url:"extPortStart" json:"extPortStart" validate:"required"`
// Internal IP port number to use for this rule
// Required: false
IntPort uint `url:"intPort,omitempty" json:"intPort,omitempty"`
// External IP end port to use for this rule
// Required: false
ExtPortEnd uint `url:"extPortEnd,omitempty" json:"extPortEnd,omitempty"`
// IP protocol type
// Should be one of:
// - "tcp"
// - "udp"
// Required: false
Proto string `url:"proto,omitempty" json:"proto,omitempty" validate:"omitempty,proto"`
}
// NATRuleAdd create NAT (port forwarding) rule on VINS
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/natRuleAdd"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,43 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// NATRuleDelRequest struct to delete NAT rule
type NATRuleDelRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// ID of the rule to delete.
// Pass -1 to clear all rules at once
// Required: true
RuleID int64 `url:"ruleId" json:"ruleId" validate:"required"`
}
// NATRuleDel deletes NAT (port forwarding) rule on VINS
func (v VINS) NATRuleDel(ctx context.Context, req NATRuleDelRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/natRuleDel"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,40 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// NATRuleListRequest struct to get list of NAT rules
type NATRuleListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// NATRuleList gets list of NAT (port forwarding) rules
func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (*ListNATRules, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/natRuleList"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := &ListNATRules{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,38 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RestoreRequest struct for restore
type RestoreRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// Restore restores VINS from recycle bin
func (v VINS) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/restore"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,45 @@
package vins
import (
"context"
"encoding/json"
"net/http"
)
// SearchRequest struct for search VINSes
type SearchRequest struct {
// ID of the account to search for the ViNSes
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// ID of the resource group to limit search to the specified RG level only
// Required: false
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
// Name of the ViNS to search for
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// If False, then VINSes having one of the statuses are not listed for
// Required: false
ShowAll bool `url:"show_all,omitempty" json:"show_all,omitempty"`
}
// Search searches VINSes
func (v VINS) Search(ctx context.Context, req SearchRequest) (SearchListVINS, error) {
url := "/cloudapi/vins/search"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := SearchListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,43 @@
package vins
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (lv ListVINS) Serialize(params ...string) (serialization.Serialized, error) {
if len(lv.Data) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lv, prefix, indent)
}
return json.Marshal(lv)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (iv ItemVINS) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(iv, prefix, indent)
}
return json.Marshal(iv)
}

View File

@@ -0,0 +1,60 @@
package vins
import "sort"
// SortByCreatedTime sorts ListVINS by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lv ListVINS) SortByCreatedTime(inverse bool) ListVINS {
if len(lv.Data) < 2 {
return lv
}
sort.Slice(lv.Data, func(i, j int) bool {
if inverse {
return lv.Data[i].CreatedTime > lv.Data[j].CreatedTime
}
return lv.Data[i].CreatedTime < lv.Data[j].CreatedTime
})
return lv
}
// SortByUpdatedTime sorts ListVINS by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lv ListVINS) SortByUpdatedTime(inverse bool) ListVINS {
if len(lv.Data) < 2 {
return lv
}
sort.Slice(lv.Data, func(i, j int) bool {
if inverse {
return lv.Data[i].UpdatedTime > lv.Data[j].UpdatedTime
}
return lv.Data[i].UpdatedTime < lv.Data[j].UpdatedTime
})
return lv
}
// SortByDeletedTime sorts ListVINS by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lv ListVINS) SortByDeletedTime(inverse bool) ListVINS {
if len(lv.Data) < 2 {
return lv
}
sort.Slice(lv.Data, func(i, j int) bool {
if inverse {
return lv.Data[i].DeletedTime > lv.Data[j].DeletedTime
}
return lv.Data[i].DeletedTime < lv.Data[j].DeletedTime
})
return lv
}

View File

@@ -0,0 +1,46 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StaticRouteAccessGrantRequest struct to grant access to static route to Compute/ViNS
type StaticRouteAccessGrantRequest struct {
// ViNS ID to grant access
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Route ID to grant access, can be found in staticRouteList
// Required: true
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
// List of Compute IDs to grant access to this route
// Required: false
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
}
// StaticRouteAccessGrant grants access to static route to Compute/ViNS
func (v VINS) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/staticRouteAccessGrant"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,46 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StaticRouteAccessRevokeRequest struct to revoke access to static route to Compute/ViNS
type StaticRouteAccessRevokeRequest struct {
// ViNS ID to revoke access
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Route ID to revoke access, can be found in staticRouteList
// Required: true
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
// List of Compute IDs to revoke access to this route
// Required: false
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
}
// StaticRouteAccessRevoke revokes access to static route to Compute/ViNS
func (v VINS) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/staticRouteAccessRevoke"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,54 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StaticRouteAddRequest struct to add static route
type StaticRouteAddRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Destination network
// Required: true
Destination string `url:"destination" json:"destination" validate:"required"`
// Destination network mask in 255.255.255.255 format
// Required: true
Netmask string `url:"netmask" json:"netmask" validate:"required"`
// Next hop host, IP address from ViNS ID free IP pool
// Required: true
Gateway string `url:"gateway" json:"gateway" validate:"required"`
// List of Compute IDs which have access to this route
// Required: false
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
}
// StaticRouteAdd adds new static route to ViNS
func (v VINS) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/staticRouteAdd"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,42 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StaticRouteDelRequest struct to remove static route from ViNS
type StaticRouteDelRequest struct {
// ViNS ID to remove static route from
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
// Route ID to remove, can be found in staticRouteList
// Required: true
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
}
// StaticRouteDel removes static route from ViNS
func (v VINS) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/staticRouteDel"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,40 @@
package vins
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// StaticRouteListRequest struct for static route list
type StaticRouteListRequest struct {
// ViNS ID to show list of static routes
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// StaticRouteList shows list of static routes for ViNS
func (v VINS) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/staticRouteList"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListStaticRoutes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

18
pkg/cloudapi/vins/vins.go Normal file
View File

@@ -0,0 +1,18 @@
// API Actor for managing VINS. This actor is a final API for endusers to manage VINS
package vins
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
)
// Structure for creating request to VINS
type VINS struct {
client interfaces.Caller
}
// Builder for VINS endpoints
func New(client interfaces.Caller) *VINS {
return &VINS{
client,
}
}

View File

@@ -0,0 +1,38 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// VNFDevRedeployRequest struct for redeploy VNFDevs
type VNFDevRedeployRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// VNFDevRedeploy redeploys VINS VNFDevs
func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/vnfdevRedeploy"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package vins
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// VNFDevRestartRequest struct for reboot VINSes primary VNF device
type VNFDevRestartRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
}
// VNFDevRestart reboots VINSes primary VNF device
func (v VINS) VNFDevRestart(ctx context.Context, req VNFDevRestartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/vins/vnfdevRestart"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}