Refactoring
This commit is contained in:
15
pkg/cloudapi/extnet/extnet.go
Normal file
15
pkg/cloudapi/extnet/extnet.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/interfaces"
|
||||
)
|
||||
|
||||
type Extnet struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Extnet {
|
||||
return &Extnet{
|
||||
client,
|
||||
}
|
||||
}
|
||||
53
pkg/cloudapi/extnet/get.go
Normal file
53
pkg/cloudapi/extnet/get.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
NetId uint64 `url:"net_id"`
|
||||
}
|
||||
|
||||
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, options ...opts.DecortOpts) (*ExtnetDetailed, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/extnet/get"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
extnetRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extnet := &ExtnetDetailed{}
|
||||
err = json.Unmarshal(extnetRaw, &extnet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extnet, nil
|
||||
|
||||
}
|
||||
35
pkg/cloudapi/extnet/get_default.go
Normal file
35
pkg/cloudapi/extnet/get_default.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
func (e Extnet) GetDefault(ctx context.Context, options ...opts.DecortOpts) (uint64, error) {
|
||||
url := "/extnet/getDefault"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
res, err := e.client.DecortApiCall(ctx, typed.POST, url, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
42
pkg/cloudapi/extnet/list.go
Normal file
42
pkg/cloudapi/extnet/list.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
Page uint64 `url:"page"`
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (e Extnet) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (ExtnetList, error) {
|
||||
url := "/extnet/list"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
extnetListRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extnetList := ExtnetList{}
|
||||
err = json.Unmarshal(extnetListRaw, &extnetList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extnetList, nil
|
||||
|
||||
}
|
||||
49
pkg/cloudapi/extnet/list_computes.go
Normal file
49
pkg/cloudapi/extnet/list_computes.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package extnet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/rudecs/decort-sdk/opts"
|
||||
"github.com/rudecs/decort-sdk/typed"
|
||||
)
|
||||
|
||||
type ListComputesRequest struct {
|
||||
AccountId uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
func (erq ListComputesRequest) Validate() error {
|
||||
if erq.AccountId == 0 {
|
||||
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e Extnet) ListComputes(ctx context.Context, req ListComputesRequest, options ...opts.DecortOpts) (ExtnetComputesList, error) {
|
||||
url := "/extnet/listComputes"
|
||||
prefix := "/cloudapi"
|
||||
|
||||
option := opts.New(options)
|
||||
|
||||
if option != nil {
|
||||
if option.IsAdmin {
|
||||
prefix = "/" + option.AdminValue
|
||||
}
|
||||
}
|
||||
url = prefix + url
|
||||
extnetComputesListRaw, err := e.client.DecortApiCall(ctx, typed.POST, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
extnetComputesList := ExtnetComputesList{}
|
||||
err = json.Unmarshal(extnetComputesListRaw, &extnetComputesList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return extnetComputesList, nil
|
||||
|
||||
}
|
||||
80
pkg/cloudapi/extnet/models.go
Normal file
80
pkg/cloudapi/extnet/models.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package extnet
|
||||
|
||||
type ExtnetRecord struct {
|
||||
ID int `json:"id"`
|
||||
IPCidr string `json:"ipcidr"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
type ExtnetExtend struct {
|
||||
ExtnetRecord
|
||||
IPAddr string `json:"ipaddr"`
|
||||
}
|
||||
|
||||
type ExtnetList []ExtnetRecord
|
||||
type ExtnetExtendList []ExtnetExtend
|
||||
|
||||
type ExtnetComputes struct {
|
||||
AccountId int `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
Extnets ExtnetExtendList `json:"extnets"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RGID int `json:"rgId"`
|
||||
RGName string `json:"rgName"`
|
||||
}
|
||||
|
||||
type ExtnetComputesList []ExtnetComputes
|
||||
|
||||
type ExtnetQos struct {
|
||||
ERate int `json:"eRate"`
|
||||
GUID string `json:"guid"`
|
||||
InBurst int `json:"inBurst"`
|
||||
InRate int `json:"inRate"`
|
||||
}
|
||||
|
||||
type ExtnetReservation struct {
|
||||
ClientType string `json:"clientType"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type ExtnetReservations []ExtnetReservation
|
||||
|
||||
type ExtnetVNFS struct {
|
||||
DHCP int `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 int `json:"free_ips"`
|
||||
Gateway string `json:"gateway"`
|
||||
GID int `json:"gid"`
|
||||
GUID int `json:"guid"`
|
||||
ID int `json:"id"`
|
||||
IPCidr string `json:"ipcidr"`
|
||||
Milestones int `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Network string `json:"network"`
|
||||
NetworkId int `json:"networkId"`
|
||||
PreReservationsNum int `json:"preReservationsNum"`
|
||||
Prefix int `json:"prefix"`
|
||||
PriVnfDevId int `json:"priVnfDevId"`
|
||||
Reservations ExtnetReservations `json:"reservations"`
|
||||
SharedWith []int `json:"sharedWith"`
|
||||
Status string `json:"status"`
|
||||
VlanID int `json:"vlanId"`
|
||||
VNFS ExtnetVNFS `json:"vnfs"`
|
||||
}
|
||||
Reference in New Issue
Block a user