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,11 +7,14 @@ import (
"net/http"
)
// Request struct for get audits
type AuditsRequest struct {
// ID of the VINS
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq AuditsRequest) Validate() error {
func (vrq AuditsRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,25 +22,26 @@ func (vrq AuditsRequest) Validate() error {
return nil
}
func (v VINS) Audits(ctx context.Context, req AuditsRequest) (VINSAuditsList, error) {
err := req.Validate()
// Audits gets audit records for the specified VINS object
func (v VINS) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/vins/audits"
auditsRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
audits := VINSAuditsList{}
list := ListAudits{}
err = json.Unmarshal(auditsRaw, &audits)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return audits, nil
return list, nil
}

View File

@@ -7,20 +7,37 @@ import (
"strconv"
)
// Request struct for create VINS in account
type CreateInAccountRequest struct {
Name string `url:"name"`
AccountID uint64 `url:"accountId"`
GID uint64 `url:"gid,omitempty"`
IPCidr string `url:"ipcidr,omitempty"`
Description string `url:"desc,omitempty"`
PreReservationsNum uint `url:"preReservationsNum,omitempty"`
// VINS name
// Required: true
Name string `url:"name"`
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
// Grid ID
// Required: false
GID uint64 `url:"gid,omitempty"`
// Private network IP CIDR
// Required: false
IPCIDR string `url:"ipcidr,omitempty"`
// Description
// Required: false
Description string `url:"desc,omitempty"`
// Number of pre created reservations
// Required: false
PreReservationsNum uint64 `url:"preReservationsNum,omitempty"`
}
func (vrq CreateInAccountRequest) Validate() error {
func (vrq CreateInAccountRequest) validate() error {
if vrq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if vrq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -28,8 +45,9 @@ func (vrq CreateInAccountRequest) Validate() error {
return nil
}
// CreateInAccount creates VINS in account level
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,21 +7,41 @@ import (
"strconv"
)
// Request struct for create VINS in resource group
type CreateInRGRequest struct {
Name string `url:"name"`
RGID uint64 `url:"rgId"`
IPCidr string `url:"ipcidr,omitempty"`
ExtNetID uint64 `url:"extNetId,omitempty"`
ExtIP string `url:"extIp,omitempty"`
Description string `url:"desc,omitempty"`
PreReservationsNum uint `url:"preReservationsNum,omitempty"`
// VINS name
// Required: true
Name string `url:"name"`
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
// Private network IP CIDR
// Required: false
IPCIDR string `url:"ipcidr,omitempty"`
// External network ID
// Required: false
ExtNetID uint64 `url:"extNetId,omitempty"`
// External IP, related only for extNetId >= 0
// Required: false
ExtIP string `url:"extIp,omitempty"`
// Description
// Required: false
Description string `url:"desc,omitempty"`
// Number of pre created reservations
// Required: false
PreReservationsNum uint `url:"preReservationsNum,omitempty"`
}
func (vrq CreateInRGRequest) Validate() error {
func (vrq CreateInRGRequest) validate() error {
if vrq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if vrq.RGID == 0 {
return errors.New("validation-error: field RGID can not be empty or equal to 0")
}
@@ -29,8 +49,9 @@ func (vrq CreateInRGRequest) Validate() error {
return nil
}
// CreateInRG creates VINS in resource group level
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return 0, err
}

View File

@@ -7,13 +7,26 @@ import (
"strconv"
)
// Request struct for delete VINS
type DeleteRequest struct {
VINSID uint64 `url:"vinsId"`
Force bool `url:"force"`
Permanently bool `url:"permanently"`
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
// 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"`
// 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"`
}
func (vrq DeleteRequest) Validate() error {
func (vrq DeleteRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -21,8 +34,9 @@ func (vrq DeleteRequest) Validate() error {
return nil
}
// Delete deletes VINS
func (v VINS) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for disable/enable VINS
type DisableEnableRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq DisableEnableRequest) Validate() error {
func (vrq DisableEnableRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq DisableEnableRequest) Validate() error {
return nil
}
// Disable disables VINS
func (v VINS) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -41,8 +45,9 @@ func (v VINS) Disable(ctx context.Context, req DisableEnableRequest) (bool, erro
}
// Enable enables VINS
func (v VINS) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for connect external network
type ExtNetConnectRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
NetID uint64 `url:"netId"`
IP string `url:"ip"`
// External network ID
// Required: false
NetID uint64 `url:"netId,omitempty"`
// Directly set IP address
// Required: false
IP string `url:"ip,omitempty"`
}
func (vrq ExtNetConnectRequest) Validate() error {
func (vrq ExtNetConnectRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -21,8 +30,9 @@ func (vrq ExtNetConnectRequest) Validate() error {
return nil
}
// ExtNetConnect connect VINS to external network
func (v VINS) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for disconnect VINS from external network
type ExtNetDisconnectRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq ExtNetDisconnectRequest) Validate() error {
func (vrq ExtNetDisconnectRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq ExtNetDisconnectRequest) Validate() error {
return nil
}
// ExtNetDisconnect disconnect VINS from external network
func (v VINS) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list VINS external network connections
type ExtNetListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq ExtNetListRequest) Validate() error {
func (vrq ExtNetListRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,20 +22,27 @@ func (vrq ExtNetListRequest) Validate() error {
return nil
}
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ExtNetList, error) {
// ExtNetList show list of VINS external network connections
func (v VINS) ExtNetList(ctx context.Context, req ExtNetListRequest) (ListExtNets, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/vins/extNetList"
extnetListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
extnetList := ExtNetList{}
err = json.Unmarshal(extnetListRaw, &extnetList)
list := ListExtNets{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return extnetList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get information about VINS
type GetRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq GetRequest) Validate() error {
func (vrq GetRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq GetRequest) Validate() error {
return nil
}
func (v VINS) Get(ctx context.Context, req GetRequest) (*VINSDetailed, error) {
err := req.Validate()
// Get gets information about VINS by ID
func (v VINS) Get(ctx context.Context, req GetRequest) (*RecordVINS, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,13 +36,13 @@ func (v VINS) Get(ctx context.Context, req GetRequest) (*VINSDetailed, error) {
return nil, err
}
VINS := &VINSDetailed{}
info := RecordVINS{}
err = json.Unmarshal(res, VINS)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return VINS, nil
return &info, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for DHCP IP
type IPListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq IPListRequest) Validate() error {
func (vrq IPListRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,25 +22,26 @@ func (vrq IPListRequest) Validate() error {
return nil
}
func (v VINS) IPList(ctx context.Context, req IPListRequest) (IPList, error) {
err := req.Validate()
// IPList show DHCP IP reservations on VINS
func (v VINS) IPList(ctx context.Context, req IPListRequest) (ListIPs, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/vins/ipList"
ipListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
ipList := IPList{}
err = json.Unmarshal(ipListRaw, &ipList)
list := ListIPs{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return ipList, nil
return list, nil
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for IP relese
type IPReleaseRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
// IP address
// Required: false
IPAddr string `url:"ipAddr,omitempty"`
MAC string `url:"mac,omitempty"`
// MAC address
// Required: false
MAC string `url:"mac,omitempty"`
}
func (vrq IPReleaseRequest) Validate() error {
func (vrq IPReleaseRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -21,8 +30,10 @@ func (vrq IPReleaseRequest) Validate() error {
return nil
}
// 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 := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -40,5 +51,4 @@ func (v VINS) IPRelese(ctx context.Context, req IPReleaseRequest) (bool, error)
}
return result, nil
}

View File

@@ -4,30 +4,59 @@ import (
"context"
"errors"
"net/http"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for IP reserve
type IPReserveRequest struct {
VINSID uint64 `url:"vinsId"`
Type string `url:"type"`
IPAddr string `url:"ipAddr,omitempty"`
MAC string `url:"mac,omitempty"`
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
// Type of the reservation
// Should be one of:
// - DHCP
// - VIP
// - EXCLUDE
// Required: true
Type string `url:"type"`
// 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"`
// 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"`
// ID of the compute, associated with this reservation of type "DHCP".
// Ignored for other types
// Required: false
ComputeID uint64 `url:"computeId,omitempty"`
}
func (vrq IPReserveRequest) Validate() error {
func (vrq IPReserveRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
if vrq.Type == "" {
return errors.New("validation-error: field Type can not be empty")
}
validate := validators.StringInSlice(vrq.Type, []string{"DHCP", "VIP", "EXCLUDED"})
if !validate {
return errors.New("'type' should be 'DHCP', 'VIP' or 'EXCLUDED'")
}
return nil
}
// IPReserve creates reservation on ViNS DHCP
func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return "", err
}
@@ -40,5 +69,4 @@ func (v VINS) IPReserve(ctx context.Context, req IPReserveRequest) (string, erro
}
return string(res), nil
}

View File

@@ -6,26 +6,36 @@ import (
"net/http"
)
// Request struct for get list of VINSes
type ListRequest struct {
IncludeDeleted bool `url:"includeDeleted"`
Page uint64 `url:"page"`
Size uint64 `url:"size"`
// Include deleted
// Required: false
IncludeDeleted bool `url:"includeDeleted,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (v VINS) List(ctx context.Context, req ListRequest) (VINSList, error) {
// List gets list of VINSes available for current user
func (v VINS) List(ctx context.Context, req ListRequest) (ListVINS, error) {
url := "/cloudapi/vins/list"
VINSListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
VINSList := VINSList{}
err = json.Unmarshal(VINSListRaw, &VINSList)
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return VINSList, nil
return list, nil
}

View File

@@ -6,25 +6,32 @@ import (
"net/http"
)
// Request struct for get list of deleted VINSes
type ListDeletedRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (VINSList, error) {
// ListDeleted gets list of deleted VINSes available for current user
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListVINS, error) {
url := "/cloudapi/vins/listDeleted"
VINSListRaw, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
VINSList := VINSList{}
err = json.Unmarshal(VINSListRaw, &VINSList)
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return VINSList, nil
return list, nil
}

View File

@@ -1,271 +1,691 @@
package vins
type VINSRecord struct {
AccountID uint64 `json:"accountId"`
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
CreatedBy string `json:"createdBy"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID uint64 `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
// External IP
ExternalIP string `json:"externalIP"`
// 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"`
VXLANID uint64 `json:"vxlanId"`
// VXLAN ID
VXLANID uint64 `json:"vxlanId"`
}
type VINSList []VINSRecord
// List of VINSes
type ListVINS []ItemVINS
type VINSAudits struct {
Call string `json:"call"`
// Main information about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
type VINSAuditsList []VINSAudits
// List of audits
type ListAudits []ItemAudit
type VINSExtNet struct {
DefaultGW string `json:"default_gw"`
ExtNetID uint64 `json:"ext_net_id"`
IP string `json:"ip"`
PrefixLen uint64 `json:"prefixlen"`
Status string `json:"status"`
// 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"`
}
type ExtNetList []VINSExtNet
// List of external networks
type ListExtNets []ItemExtNet
type IP struct {
// Main information about IP
type ItemIP struct {
// Client type
ClientType string `json:"clientType"`
// Domain name
DomainName string `json:"domainname"`
HostName string `json:"hostname"`
IP string `json:"ip"`
MAC string `json:"mac"`
Type string `json:"type"`
VMID uint64 `json:"vmId"`
// 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"`
}
type IPList []IP
// List of IPs
type ListIPs []ItemIP
type VNFDev struct {
CKey string `json:"_ckey"`
AccountID uint64 `json:"accountId"`
Capabilities []string `json:"capabilities"`
Config VNFConfig `json:"config"`
ConfigSaved bool `json:"configSaved"`
CustomPreConfig bool `json:"customPrecfg"`
Description string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
Interfaces VNFInterfaceList `json:"interfaces"`
LockStatus string `json:"lockStatus"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
VINS []uint64 `json:"vins"`
// 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"`
}
type VNFConfig struct {
MGMT VNFConfigMGMT `json:"mgmt"`
Resources VNFConfigResources `json:"resources"`
// VNF config
type RecordVNFConfig struct {
// MGMT
MGMT RecordMGMT `json:"mgmt"`
// Resources
Resources RecordResources `json:"resources"`
}
type VNFConfigMGMT struct {
IPAddr string `json:"ipaddr"`
// Main information about MGMT
type RecordMGMT struct {
// IP address
IPAddress string `json:"ipaddr"`
// Password
Password string `json:"password"`
SSHKey string `json:"sshkey"`
User string `json:"user"`
// SSH key
SSHKey string `json:"sshkey"`
// User
User string `json:"user"`
}
type VNFConfigResources struct {
CPU uint64 `json:"cpu"`
RAM uint64 `json:"ram"`
// 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 string `json:"uuid"`
// UUID
UUID string `json:"uuid"`
}
type VNFInterface struct {
ConnID uint64 `json:"connId"`
ConnType string `json:"connType"`
DefGW string `json:"defGw"`
FlipGroupID uint64 `json:"flipgroupId"`
GUID string `json:"guid"`
IPAddress string `json:"ipAddress"`
ListenSSH bool `json:"listenSsh"`
MAC string `json:"mac"`
Name string `json:"name"`
NetID uint64 `json:"netId"`
NetMask uint64 `json:"netMask"`
NetType string `json:"netType"`
PCISlot uint64 `json:"pciSlot"`
QOS QOS `json:"qos"`
Target string `json:"target"`
Type string `json:"type"`
VNFS []uint64 `json:"vnfs"`
// Main information about VNF interface
type ItemVNFInterface struct {
// Connection ID
ConnID uint64 `json:"connId"`
// Connection type
ConnType string `json:"connType"`
// Default GW
DefGW string `json:"defGw"`
// 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"`
// Name
Name string `json:"name"`
// Network type
NetID uint64 `json:"netId"`
// Network mask
NetMask uint64 `json:"netMask"`
// Network type
NetType string `json:"netType"`
// PCI slot
PCISlot uint64 `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 uint64 `json:"eRate"`
GUID string `json:"guid"`
// ERate
ERate uint64 `json:"eRate"`
// GUID
GUID string `json:"guid"`
// InBurst
InBurst uint64 `json:"inBurst"`
InRate uint64 `json:"inRate"`
// InRate
InRate uint64 `json:"inRate"`
}
type VNFInterfaceList []VNFInterface
// List of VNF interfaces
type ListVNFInterfaces []ItemVNFInterface
type VINSCompute struct {
ID uint64 `json:"id"`
// Main information about VINS compute
type ItemVINSCompute struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
}
type VINSComputeList []VINSCompute
// List of VINS computes
type ListVINSComputes []ItemVINSCompute
type VNFS struct {
DHCP DHCP `json:"DHCP"`
GW GW `json:"GW"`
NAT NAT `json:"NAT"`
// Detailed information about VNF
type RecordVNFs struct {
// DHCP
DHCP RecordDHCP `json:"DHCP"`
// GW
GW RecordGW `json:"GW"`
// NAT
NAT RecordNAT `json:"NAT"`
}
type NAT struct {
CKey string `json:"_ckey"`
AccountID uint64 `json:"accountId"`
CreatedTime uint64 `json:"createdTime"`
Devices Devices `json:"devices"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones uint64 `json:"milestones"`
OwnerID uint64 `json:"ownerId"`
OwnerType string `json:"ownerType"`
PureVirtual bool `json:"pureVirtual"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
// 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"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
// NAT configuration
type NATConfig struct {
NetMask uint64 `json:"netmask"`
Network string `json:"network"`
Rules []interface{} `json:"rules"`
// Network mask
NetMask uint64 `json:"netmask"`
// Network
Network string `json:"network"`
// List NAT rules
Rules ListNATRules `json:"rules"`
}
type GW struct {
CKey string `json:"_ckey"`
AccountID uint64 `json:"accountId"`
Config GWConfig `json:"config"`
CreatedTime uint64 `json:"createdTime"`
Devices Devices `json:"devices"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones uint64 `json:"milestones"`
OwnerID uint64 `json:"ownerId"`
OwnerType string `json:"ownerType"`
PureVirtual bool `json:"pureVirtual"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
// 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"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
type GWConfig struct {
DefaultGW string `json:"default_gw"`
ExtNetID uint64 `json:"ext_net_id"`
ExtNetIP string `json:"ext_net_ip"`
// 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 `json:"qos"`
// QOS
QOS QOS `json:"qos"`
}
type Devices struct {
Primary DevicePrimary `json:"primary"`
// Information about devices
type RecordDevices struct {
// Main information about primary device
Primary RecordPrimary `json:"primary"`
}
type DevicePrimary struct {
DevID uint64 `json:"devId"`
// Main information about primary device
type RecordPrimary struct {
// Device ID
DevID uint64 `json:"devId"`
// IFace01
IFace01 string `json:"iface01"`
// IFace02
IFace02 string `json:"iface02"`
}
type DHCP struct {
CKey string `json:"_ckey"`
AccountID uint64 `json:"accountId"`
Config DHCPConfig `json:"config"`
CreatedTime uint64 `json:"createdTime"`
Devices Devices `json:"devices"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
Milestones uint64 `json:"milestones"`
OwnerID uint64 `json:"ownerId"`
OwnerType string `json:"ownerType"`
PureVirtual bool `json:"pureVirtual"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
// 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"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
}
type DHCPConfig struct {
DefaultGW string `json:"default_gw"`
DNS []string `json:"dns"`
IPEnd string `json:"ip_end"`
IPStart string `json:"ip_start"`
Lease uint64 `json:"lease"`
Netmask uint64 `json:"netmask"`
Network string `json:"network"`
Reservations ReservationList `json:"reservations"`
// 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"`
}
type VINSDetailed struct {
VNFDev VNFDev `json:"VNFDev"`
CKey string `json:"_ckey"`
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
Computes VINSComputeList `json:"computes"`
DefaultGW string `json:"defaultGW"`
DefaultQOS QOS `json:"defaultQos"`
Description string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
LockStatus string `json:"lockStatus"`
ManagerID uint64 `json:"managerId"`
ManagerType string `json:"managerType"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
NetMask uint64 `json:"netMask"`
Network string `json:"network"`
PreReservaionsNum uint64 `json:"preReservationsNum"`
Redundant bool `json:"redundant"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
SecVNFDevID uint64 `json:"secVnfDevId"`
Status string `json:"status"`
UserManaged bool `json:"userManaged"`
VNFS VNFS `json:"vnfs"`
VXLanID uint64 `json:"vxlanId"`
}
// Detailed information about VINS
type RecordVINS struct {
// Main information about VNF device
VNFDev RecordVNFDev `json:"VNFDev"`
type Reservation struct {
ClientType string `json:"clientType"`
// CKey
CKey string `json:"_ckey"`
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// List of VINS computes
Computes ListVINSComputes `json:"computes"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Default QOS
DefaultQOS QOS `json:"defaultQos"`
// Description
Description string `json:"desc"`
DomainName string `json:"domainname"`
HostName string `json:"hostname"`
IP string `json:"ip"`
MAC string `json:"mac"`
Type string `json:"type"`
VMID int `json:"vmId"`
// 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"`
// User managed
UserManaged bool `json:"userManaged"`
// Main information about VNFs
VNFs RecordVNFs `json:"vnfs"`
// VXLAN ID
VXLANID uint64 `json:"vxlanId"`
}
type ReservationList []Reservation
// 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 []ItemNATRule
// 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

@@ -7,28 +7,46 @@ import (
"strconv"
)
type NatRuleAddRequest struct {
VINSID uint64 `url:"vinsId"`
IntIP string `url:"intIp "`
IntPort uint `url:"intPort"`
ExtPortStart uint `url:"extPortStart"`
ExtPortEnd uint `url:"extPortEnd,omitempty"`
Proto string `url:"proto"`
// Request struct for create NAT rules
type NATRuleAddRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
// Internal IP address to apply this rule to
// Required: true
IntIP string `url:"intIp "`
// Internal IP port number to use for this rule
// Required: true
IntPort uint `url:"intPort"`
// External IP start port to use for this rule
// Required: true
ExtPortStart uint `url:"extPortStart"`
// External IP end port to use for this rule
// Required: false
ExtPortEnd uint `url:"extPortEnd,omitempty"`
// IP protocol type
// Should be one of:
// - "tcp"
// - "udp"
// Required: false
Proto string `url:"proto,omitempty"`
}
func (vrq NatRuleAddRequest) Validate() error {
func (vrq NATRuleAddRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
if vrq.IntIP == "" {
return errors.New("validation-error: field IntIP can not be empty")
}
if vrq.IntPort == 0 {
return errors.New("validation-error: field IntPort can not be empty or equal to 0")
}
if vrq.ExtPortStart == 0 {
return errors.New("validation-error: field ExtPortStart can not be empty or equal to 0")
}
@@ -36,8 +54,9 @@ func (vrq NatRuleAddRequest) Validate() error {
return nil
}
func (v VINS) NatRuleAdd(ctx context.Context, req NatRuleAddRequest) (bool, error) {
err := req.Validate()
// NATRuleAdd create NAT (port forwarding) rule on VINS
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
@@ -55,5 +74,4 @@ func (v VINS) NatRuleAdd(ctx context.Context, req NatRuleAddRequest) (bool, erro
}
return result, nil
}

View File

@@ -7,16 +7,22 @@ import (
"strconv"
)
type NatRuleDelRequest struct {
// Request struct for delete NAT rule
type NATRuleDelRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
// ID of the rule to delete.
// Pass -1 to clear all rules at once
// Required: true
RuleID uint64 `url:"ruleId"`
}
func (vrq NatRuleDelRequest) Validate() error {
func (vrq NATRuleDelRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
if vrq.RuleID == 0 {
return errors.New("validation-error: field RuleID can not be empty or equal to 0")
}
@@ -24,8 +30,9 @@ func (vrq NatRuleDelRequest) Validate() error {
return nil
}
func (v VINS) NatRuleDel(ctx context.Context, req NatRuleDelRequest) (bool, error) {
err := req.Validate()
// NATRuleDel delete NAT (port forwarding) rule on VINS
func (v VINS) NATRuleDel(ctx context.Context, req NATRuleDelRequest) (bool, error) {
err := req.validate()
if err != nil {
return false, err
}
@@ -43,5 +50,4 @@ func (v VINS) NatRuleDel(ctx context.Context, req NatRuleDelRequest) (bool, erro
}
return result, nil
}

View File

@@ -2,15 +2,19 @@ package vins
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type NatRuleListRequest struct {
// Request struct for get list of NAT rules
type NATRuleListRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq NatRuleListRequest) Validate() error {
func (vrq NATRuleListRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -18,19 +22,26 @@ func (vrq NatRuleListRequest) Validate() error {
return nil
}
func (v VINS) NatRuleList(ctx context.Context, req NatRuleListRequest) (string, error) {
err := req.Validate()
// NATRuleList gets list of NAT (port forwarding) rules
func (v VINS) NATRuleList(ctx context.Context, req NATRuleListRequest) (ListNATRules, error) {
err := req.validate()
if err != nil {
return "", err
return nil, err
}
url := "/cloudapi/vins/natRuleList"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
return nil, err
}
return string(res), nil
list := ListNATRules{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for restore
type RestoreRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq RestoreRequest) Validate() error {
func (vrq RestoreRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq RestoreRequest) Validate() error {
return nil
}
// Restore restores VINS from recycle bin
func (v VINS) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +42,4 @@ func (v VINS) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
}
return result, nil
}

View File

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

View File

@@ -1,13 +1,16 @@
// API Actor for managing VINS. This actor is a final API for endusers to manage VINS
package vins
import (
"github.com/rudecs/decort-sdk/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

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for redeploy VNFDevs
type VNFDevRedeployRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq VNFDevRedeployRequest) Validate() error {
func (vrq VNFDevRedeployRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq VNFDevRedeployRequest) Validate() error {
return nil
}
// VNFDevRedeploy redeploy VINS VNFDevs
func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +42,4 @@ func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bo
}
return result, nil
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for reboot VINSes primary VNF device
type VNFDevRestartRequest struct {
// VINS ID
// Required: true
VINSID uint64 `url:"vinsId"`
}
func (vrq VNFDevRestartRequest) Validate() error {
func (vrq VNFDevRestartRequest) validate() error {
if vrq.VINSID == 0 {
return errors.New("validation-error: field VINSID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (vrq VNFDevRestartRequest) Validate() error {
return nil
}
// VNFDevRestart reboot VINSes primary VNF device
func (v VINS) VNFDevRestart(ctx context.Context, req VNFDevRestartRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +42,4 @@ func (v VINS) VNFDevRestart(ctx context.Context, req VNFDevRestartRequest) (bool
}
return result, nil
}