This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -7,14 +7,20 @@ import (
"strconv"
)
// Request struct for add compute instance
type ComputeAddRequest struct {
FlipGroupID uint64 `url:"flipgroupId"`
ComputeID uint64 `url:"computeId"`
// ID of the Floating IP group to add compute instance to
// Required: true
FLIPGroupID uint64 `url:"flipgroupId"`
// ID of the compute instance to add to this group
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (frq ComputeAddRequest) Validate() error {
if frq.FlipGroupID == 0 {
return errors.New("field FlipGroupID can not be empty or equal to 0")
func (frq ComputeAddRequest) validate() error {
if frq.FLIPGroupID == 0 {
return errors.New("field FLIPGroupID can not be empty or equal to 0")
}
if frq.ComputeID == 0 {
return errors.New("field ComputeID can not be empty or equal to 0")
@@ -23,12 +29,15 @@ func (frq ComputeAddRequest) Validate() error {
return nil
}
func (f FlipGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest) (bool, error) {
if err := req.Validate(); err != nil {
// ComputeAdd add compute instance to the Floating IP group
func (f FLIPGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudapi/flipgroup/computeAdd"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err

View File

@@ -7,14 +7,20 @@ import (
"strconv"
)
// Request struct for remove compute instance
type ComputeRemoveRequest struct {
FlipGroupID uint64 `url:"flipgroupId"`
ComputeID uint64 `url:"computeId"`
// ID of the Floating IP group to remove compute instance from
// Required: true
FLIPGroupID uint64 `url:"flipgroupId"`
// ID of the compute instance to remove
// Required: true
ComputeID uint64 `url:"computeId"`
}
func (frq ComputeRemoveRequest) Validate() error {
if frq.FlipGroupID == 0 {
return errors.New("field FlipGroupID can not be empty or equal to 0")
func (frq ComputeRemoveRequest) validate() error {
if frq.FLIPGroupID == 0 {
return errors.New("field FLIPGroupID can not be empty or equal to 0")
}
if frq.ComputeID == 0 {
return errors.New("field ComputeID can not be empty or equal to 0")
@@ -23,12 +29,15 @@ func (frq ComputeRemoveRequest) Validate() error {
return nil
}
func (f FlipGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest) (bool, error) {
if err := req.Validate(); err != nil {
// ComputeRemove remove compute instance from the Floating IP group
func (f FLIPGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudapi/flipgroup/computeRemove"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err

View File

@@ -9,17 +9,43 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for create FLIPGroup
type CreateRequest struct {
AccountID uint64 `url:"accountId"`
Name string `url:"name"`
NetType string `url:"netType"`
NetID uint64 `url:"netId"`
ClientType string `url:"clientType"`
IP string `url:"ip,omitempty"`
// Account ID
// Required: true
AccountID uint64 `url:"accountId"`
// FLIPGroup name
// Required: true
Name string `url:"name"`
// Network type
// Should be one of:
// - EXTNET
// - VINS
// Required: true
NetType string `url:"netType"`
// ID of external network or VINS
// Required: true
NetID uint64 `url:"netId"`
// Type of client
// - 'compute'
// - 'vins' (will be later)
// Required: true
ClientType string `url:"clientType"`
// IP address to associate with this group. If empty, the platform will autoselect IP address
// Required: false
IP string `url:"ip,omitempty"`
// Text description of this FLIPGorup instance
// Required: false
Description string `url:"desc,omitempty"`
}
func (frq CreateRequest) Validate() error {
func (frq CreateRequest) validate() error {
if frq.AccountID == 0 {
return errors.New("field AccountID can not be empty or equal to 0")
}
@@ -29,7 +55,6 @@ func (frq CreateRequest) Validate() error {
if frq.Name == "" {
return errors.New("field Name can not be empty")
}
validator := validators.StringInSlice(frq.NetType, []string{"EXTNET", "VINS"})
if !validator {
return errors.New("field Name can be only EXTNET or VINS")
@@ -42,21 +67,26 @@ func (frq CreateRequest) Validate() error {
return nil
}
func (f FlipGroup) Create(ctx context.Context, req CreateRequest) (*FlipGroupRecord, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/flipgroup/create"
fgRaw, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
// Create method will create a new FLIPGorup in the specified Account
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroup, error) {
err := req.validate()
if err != nil {
return nil, err
}
fg := &FlipGroupRecord{}
if err := json.Unmarshal(fgRaw, fg); err != nil {
url := "/cloudapi/flipgroup/create"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
return fg, nil
info := RecordFLIPGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -7,24 +7,30 @@ import (
"strconv"
)
// Request struct for delete FLIPGroup
type DeleteRequest struct {
FlipGroupID uint64 `url:"flipgroupId"`
// FLIPGroup ID
// Required: true
FLIPGroupID uint64 `url:"flipgroupId"`
}
func (frq DeleteRequest) Validate() error {
if frq.FlipGroupID == 0 {
return errors.New("field FlipGroupID can not be empty or equal to 0")
func (frq DeleteRequest) validate() error {
if frq.FLIPGroupID == 0 {
return errors.New("field FLIPGroupID can not be empty or equal to 0")
}
return nil
}
func (f FlipGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
if err := req.Validate(); err != nil {
// Delete method wil delete Floating IP group
func (f FLIPGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudapi/flipgroup/delete"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err

View File

@@ -7,26 +7,38 @@ import (
"strconv"
)
// Request struct for edit FLIPGroup
type EditRequest struct {
FlipGroupID uint64 `url:"flipgroupId"`
Name string `url:"name,omitempty"`
// FLIPGroup ID
// Required: true
FLIPGroupID uint64 `url:"flipgroupId"`
// FLIPGroup name
// Required: true
Name string `url:"name,omitempty"`
// FLIPGroup description
// Required: true
Description string `url:"desc,omitempty"`
}
func (frq EditRequest) Validate() error {
if frq.FlipGroupID == 0 {
return errors.New("field FlipGroupID can not be empty or equal to 0")
func (frq EditRequest) validate() error {
if frq.FLIPGroupID == 0 {
return errors.New("field FLIPGroupID can not be empty or equal to 0")
}
return nil
}
func (f FlipGroup) Edit(ctx context.Context, req EditRequest) (bool, error) {
if err := req.Validate(); err != nil {
// Edit edits FLIPGroup fields
func (f FLIPGroup) Edit(ctx context.Context, req EditRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
url := "/cloudapi/flipgroup/edit"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err

View File

@@ -1,15 +1,18 @@
// API to manage FLIPGroup instances
package flipgroup
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type FlipGroup struct {
// Structure for creating request to FLIPGroup
type FLIPGroup struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *FlipGroup {
return &FlipGroup{
// Builder for FLIPGroup endpoints
func New(client interfaces.Caller) *FLIPGroup {
return &FLIPGroup{
client,
}
}

View File

@@ -7,34 +7,41 @@ import (
"net/http"
)
// Request struct for get information about FLIPGroup
type GetRequest struct {
FlipGroupID uint64 `url:"flipgroupId"`
// FLIPGroup ID
// Required: true
FLIPGroupID uint64 `url:"flipgroupId"`
}
func (frq GetRequest) Validate() error {
if frq.FlipGroupID == 0 {
return errors.New("field FlipGroupID can not be empty or equal to 0")
func (frq GetRequest) validate() error {
if frq.FLIPGroupID == 0 {
return errors.New("field FLIPGroupID can not be empty or equal to 0")
}
return nil
}
func (f FlipGroup) Get(ctx context.Context, req GetRequest) (*FlipGroupItem, error) {
if err := req.Validate(); err != nil {
// Get gets details of the specified Floating IP group
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*ItemFLIPGroup, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/flipgroup/get"
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
fg := &FlipGroupItem{}
err = json.Unmarshal(res, fg)
info := ItemFLIPGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return fg, nil
return &info, nil
}

View File

@@ -6,22 +6,32 @@ import (
"net/http"
)
// Request struct for get list FLIPGroup available to the current user
type ListRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (f FlipGroup) List(ctx context.Context, req ListRequest) (FlipGroupList, error) {
// List gets list FLIPGroup managed cluster instances available to the current user
func (f FLIPGroup) List(ctx context.Context, req ListRequest) (ListFLIPGroups, error) {
url := "/cloudapi/flipgroup/list"
fgListRaw, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
fgList := FlipGroupList{}
if err := json.Unmarshal(fgListRaw, &fgList); err != nil {
list := ListFLIPGroups{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return fgList, nil
return list, nil
}

View File

@@ -1,40 +1,103 @@
package flipgroup
type FlipGroupRecord struct {
// Main information about FLIPGroup
type RecordFLIPGroup struct {
// Default GW
DefaultGW string `json:"defaultGW"`
ID uint64 `json:"id"`
IP string `json:"ip"`
Name string `json:"name"`
Netmask uint64 `json:"netmask"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Name
Name string `json:"name"`
// Network mask
NetMask uint64 `json:"netmask"`
}
type FlipGroupItem struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
ClientIDs []uint64 `json:"clientIds"`
ClientType string `json:"clientType"`
ConnID uint64 `json:"connId"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
Description string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
IP string `json:"ip"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
NetID uint64 `json:"netId"`
NetType string `json:"netType"`
Network string `json:"network"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
// Detailed information about FLIPGroup
type ItemFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// List of client IDs
ClientIDs []uint64 `json:"clientIds"`
// Client type
ClientType string `json:"clientType"`
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// 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"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// 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"`
}
type FlipGroupList []FlipGroupItem
// List of FLIPGroup
type ListFLIPGroups []ItemFLIPGroup