v1.0.0
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
// API Actor for use external networks
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to extnet
|
||||
type ExtNet struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for extnet endpoints
|
||||
func New(client interfaces.Caller) *ExtNet {
|
||||
return &ExtNet{
|
||||
client,
|
||||
|
||||
@@ -7,36 +7,41 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about external network
|
||||
type GetRequest struct {
|
||||
// ID of external network
|
||||
// Required: true
|
||||
NetID uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
func (erq GetRequest) Validate() error {
|
||||
func (erq GetRequest) validate() error {
|
||||
if erq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*ExtNetDetailed, error) {
|
||||
err := req.Validate()
|
||||
// Get gets detailed information about external network
|
||||
func (e ExtNet) Get(ctx context.Context, req GetRequest) (*RecordExtNet, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/extnet/get"
|
||||
|
||||
extnetRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extnet := &ExtNetDetailed{}
|
||||
err = json.Unmarshal(extnetRaw, &extnet)
|
||||
info := RecordExtNet{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extnet, nil
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetDefault get default external network ID
|
||||
func (e ExtNet) GetDefault(ctx context.Context) (uint64, error) {
|
||||
url := "/cloudapi/extnet/getDefault"
|
||||
|
||||
@@ -20,5 +21,4 @@ func (e ExtNet) GetDefault(ctx context.Context) (uint64, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -6,26 +6,36 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list external network
|
||||
type ListRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
// Filter by account ID
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (ExtNetList, error) {
|
||||
// List gets list all available external networks
|
||||
func (e ExtNet) List(ctx context.Context, req ListRequest) (ListExtNets, error) {
|
||||
url := "/cloudapi/extnet/list"
|
||||
|
||||
extnetListRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := e.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
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list computes
|
||||
type ListComputesRequest struct {
|
||||
// Filter by account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (erq ListComputesRequest) Validate() error {
|
||||
func (erq ListComputesRequest) validate() error {
|
||||
if erq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
@@ -19,20 +22,26 @@ func (erq ListComputesRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ExtNetComputesList, error) {
|
||||
// ListComputes gets computes from account with extnets
|
||||
func (e ExtNet) ListComputes(ctx context.Context, req ListComputesRequest) (ListExtNetComputes, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudapi/extnet/listComputes"
|
||||
|
||||
extnetComputesListRaw, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extnetComputesList := ExtNetComputesList{}
|
||||
err = json.Unmarshal(extnetComputesListRaw, &extnetComputesList)
|
||||
list := ListExtNetComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extnetComputesList, nil
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,80 +1,195 @@
|
||||
package extnet
|
||||
|
||||
type ExtNetRecord struct {
|
||||
ID uint64 `json:"id"`
|
||||
IPCidr string `json:"ipcidr"`
|
||||
Name string `json:"name"`
|
||||
// Main information about external network
|
||||
type ItemExtNet struct {
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// IPCIDR
|
||||
IPCIDR string `json:"ipcidr"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
}
|
||||
type ExtNetExtend struct {
|
||||
ExtNetRecord
|
||||
|
||||
// Extend information about external network
|
||||
type ItemExtNetExtend struct {
|
||||
// Main information about external network
|
||||
ItemExtNet
|
||||
|
||||
// IP address
|
||||
IPAddr string `json:"ipaddr"`
|
||||
}
|
||||
|
||||
type ExtNetList []ExtNetRecord
|
||||
type ExtNetExtendList []ExtNetExtend
|
||||
// List of information about external network
|
||||
type ListExtNets []ItemExtNet
|
||||
|
||||
type ExtNetComputes struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
ExtNets ExtNetExtendList `json:"extnets"`
|
||||
ID uint64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RGID uint64 `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
// List of extend information about external network
|
||||
type ListExtNetExtends []ItemExtNetExtend
|
||||
|
||||
// Main information about compute with external network
|
||||
type ItemExtNetCompute struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// List of extend information about external network
|
||||
ExtNets ListExtNetExtends `json:"extnets"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// Resource group name
|
||||
RGName string `json:"rgName"`
|
||||
}
|
||||
|
||||
type ExtNetComputesList []ExtNetComputes
|
||||
// List of information about computes with external network
|
||||
type ListExtNetComputes []ItemExtNetCompute
|
||||
|
||||
type ExtNetQos struct {
|
||||
ERate uint64 `json:"eRate"`
|
||||
GUID string `json:"guid"`
|
||||
// QOS
|
||||
type QOS struct {
|
||||
// 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 ExtNetReservation struct {
|
||||
ClientType string `json:"clientType"`
|
||||
// Main information about reservations
|
||||
type ItemReservation struct {
|
||||
// ClientType
|
||||
ClientType string `json:"clientType"`
|
||||
|
||||
// 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 uint64 `json:"vmId"`
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
type ExtNetReservations []ExtNetReservation
|
||||
// List of information about reservations
|
||||
type ListReservations []ItemReservation
|
||||
|
||||
type ExtNetVNFS struct {
|
||||
// VNFs
|
||||
type VNFs struct {
|
||||
DHCP uint64 `json:"dhcp"`
|
||||
}
|
||||
|
||||
type ExtNetDetailed struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
CheckIPs []string `json:"checkIPs"`
|
||||
CheckIps []string `json:"checkIps"`
|
||||
Default bool `json:"default"`
|
||||
DefaultQos ExtNetQos `json:"defaultQos"`
|
||||
Description string `json:"desc"`
|
||||
Dns []string `json:"dns"`
|
||||
Excluded []string `json:"excluded"`
|
||||
FreeIps uint64 `json:"free_ips"`
|
||||
Gateway string `json:"gateway"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
IPCidr string `json:"ipcidr"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
Prefix uint64 `json:"prefix"`
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
Reservations ExtNetReservations `json:"reservations"`
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
Status string `json:"status"`
|
||||
VlanID uint64 `json:"vlanId"`
|
||||
VNFS ExtNetVNFS `json:"vnfs"`
|
||||
// Detailed information about external network
|
||||
type RecordExtNet struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// CheckIPs
|
||||
CheckIPs []string `json:"checkIPs"`
|
||||
|
||||
// CheckIps
|
||||
CheckIps []string `json:"checkIps"`
|
||||
|
||||
// Default
|
||||
Default bool `json:"default"`
|
||||
|
||||
// Default QOS
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// list of DNS
|
||||
DNS []string `json:"dns"`
|
||||
|
||||
// Excluded
|
||||
Excluded []string `json:"excluded"`
|
||||
|
||||
// Free IPs
|
||||
FreeIPs uint64 `json:"free_ips"`
|
||||
|
||||
// Gateway
|
||||
Gateway string `json:"gateway"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// IPCIDR
|
||||
IPCIDR string `json:"ipcidr"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Network
|
||||
Network string `json:"network"`
|
||||
|
||||
// Network ID
|
||||
NetworkID uint64 `json:"networkId"`
|
||||
|
||||
// OVS Bridge
|
||||
OVSBridge string `json:"ovsBridge"`
|
||||
|
||||
// PreReservation IP num
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
|
||||
// Prefix
|
||||
Prefix uint64 `json:"prefix"`
|
||||
|
||||
// PriVNFDevID
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
|
||||
// List reservations
|
||||
Reservations ListReservations `json:"reservations"`
|
||||
|
||||
// Shared with
|
||||
SharedWith []uint64 `json:"sharedWith"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// VLAN ID
|
||||
VLANID uint64 `json:"vlanId"`
|
||||
|
||||
// VNFs
|
||||
VNFs VNFs `json:"vnfs"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user