Refactoring

This commit is contained in:
stSolo
2022-08-11 16:39:39 +03:00
parent 9563097dcb
commit 39a6f9a1ce
300 changed files with 64 additions and 58 deletions

View File

@@ -0,0 +1,54 @@
package vins
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type AuditsRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq AuditsRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) Audits(ctx context.Context, req AuditsRequest, options ...opts.DecortOpts) (VinsAuditsList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/vins/audits"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
auditsRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
audits := VinsAuditsList{}
err = json.Unmarshal([]byte(auditsRaw), &audits)
if err != nil {
return nil, err
}
return audits, nil
}

View File

@@ -0,0 +1,61 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
}
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")
}
return nil
}
func (v Vins) CreateInAccount(ctx context.Context, req CreateInAccountRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/vins/createInAccount"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, 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,62 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
}
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")
}
return nil
}
func (v Vins) CreateInRG(ctx context.Context, req CreateInRGRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/vins/createInRG"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, 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,54 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
VinsId uint64 `url:"vinsId"`
Force bool `url:"force"`
Permanently bool `url:"permanently"`
}
func (vrq DeleteRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/delete"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,84 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisableEnableRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq DisableEnableRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) Disable(ctx context.Context, req DisableEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/disable"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}
func (v Vins) Enable(ctx context.Context, req DisableEnableRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/enable"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,54 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ExtNetConnectRequest struct {
VinsId uint64 `url:"vinsId"`
NetId uint64 `url:"netId"`
IP string `url:"ip"`
}
func (vrq ExtNetConnectRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/extNetConnect"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,52 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ExtNetDisconnectRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq ExtNetDisconnectRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/extNetDisconnect"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,49 @@
package vins
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ExtNetListRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq ExtNetListRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) ExtNetList(ctx context.Context, req ExtNetListRequest, options ...opts.DecortOpts) (ExtnetList, error) {
url := "/vins/extNetList"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
extnetListRaw, err := v.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
}

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

@@ -0,0 +1,55 @@
package vins
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq GetRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*VinsDetailed, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/vins/get"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
vins := &VinsDetailed{}
err = json.Unmarshal(res, vins)
if err != nil {
return nil, err
}
return vins, nil
}

View File

@@ -0,0 +1,54 @@
package vins
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type IPListRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq IPListRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) IPList(ctx context.Context, req IPListRequest, options ...opts.DecortOpts) (IPList, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/vins/ipList"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
ipListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
ipList := IPList{}
err = json.Unmarshal(ipListRaw, &ipList)
if err != nil {
return nil, err
}
return ipList, nil
}

View File

@@ -0,0 +1,55 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type IPReleaseRequest struct {
VinsId uint64 `url:"vinsId"`
IPAddr string `url:"ipAddr,omitempty"`
MAC string `url:"mac,omitempty"`
}
func (vrq IPReleaseRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) IPRelese(ctx context.Context, req IPReleaseRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/ipRelease"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,55 @@
package vins
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type IPReserveRequest struct {
VinsId uint64 `url:"vinsId"`
Type string `url:"type"`
IPAddr string `url:"ipAddr,omitempty"`
MAC string `url:"mac,omitempty"`
ComputeId uint64 `url:"computeId,omitempty"`
}
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")
}
return nil
}
func (v Vins) IPReserve(ctx context.Context, req IPReserveRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/vins/ipReserve"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

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

@@ -0,0 +1,42 @@
package vins
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
IncludeDeleted bool `url:"includeDeleted"`
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (v Vins) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (VinsList, error) {
url := "/vins/list"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
vinsList := VinsList{}
err = json.Unmarshal(vinsListRaw, &vinsList)
if err != nil {
return nil, err
}
return vinsList, nil
}

View File

@@ -0,0 +1,41 @@
package vins
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListDeletedRequest struct {
Page uint64 `url:"page"`
Size uint64 `url:"size"`
}
func (v Vins) ListDeleted(ctx context.Context, req ListDeletedRequest, options ...opts.DecortOpts) (VinsList, error) {
url := "/vins/listDeleted"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
vinsList := VinsList{}
err = json.Unmarshal(vinsListRaw, &vinsList)
if err != nil {
return nil, err
}
return vinsList, nil
}

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

@@ -0,0 +1,271 @@
package vins
type VinsRecord struct {
AccountId int `json:"accountId"`
AccountName string `json:"accountName"`
CreatedBy string `json:"createdBy"`
CreatedTime int `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime int `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID int `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
RGID int `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime int `json:"updatedTime"`
VXLanID int `json:"vxlanId"`
}
type VinsList []VinsRecord
type VinsAudits struct {
Call string `json:"call"`
ResponseTime float64 `json:"responsetime"`
StatusCode int `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
}
type VinsAuditsList []VinsAudits
type VinsExtnet struct {
DefaultGW string `json:"default_gw"`
ExtNetID uint64 `json:"ext_net_id"`
IP string `json:"ip"`
PrefixLen uint `json:"prefixlen"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
}
type ExtnetList []VinsExtnet
type IP struct {
ClientType string `json:"clientType"`
DomainName string `json:"domainname"`
HostName string `json:"hostname"`
IP string `json:"ip"`
MAC string `json:"mac"`
Type string `json:"type"`
VMId uint64 `json:"vmId"`
}
type IPList []IP
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"`
}
type VNFConfig struct {
MGMT VNFConfigMGMT `json:"mgmt"`
Resources VNFConfigResources `json:"resources"`
}
type VNFConfigMGMT struct {
IPAddr string `json:"ipaddr"`
Password string `json:"password"`
SSHKey string `json:"sshkey"`
User string `json:"user"`
}
type VNFConfigResources struct {
CPU uint64 `json:"cpu"`
RAM uint64 `json:"ram"`
StackId uint64 `json:"stackId"`
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"`
}
type QOS struct {
ERate uint64 `json:"eRate"`
GUID string `json:"guid"`
InBurst uint64 `json:"inBurst"`
InRate uint64 `json:"inRate"`
}
type VNFInterfaceList []VNFInterface
type VINSCompute struct {
ID uint64 `json:"id"`
Name string `json:"name"`
}
type VINSComputeList []VINSCompute
type VNFS struct {
DHCP DHCP `json:"DHCP"`
GW GW `json:"GW"`
NAT NAT `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"`
}
type NATConfig struct {
NetMask uint64 `json:"netmask"`
Network string `json:"network"`
Rules []interface{} `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"`
}
type GWConfig struct {
DefaultGW string `json:"default_gw"`
ExtNetId uint64 `json:"ext_net_id"`
ExtNetIp string `json:"ext_net_ip"`
ExtNetMask uint64 `json:"ext_netmask"`
QOS QOS `json:"qos"`
}
type Devices struct {
Primary DevicePrimary `json:"primary"`
}
type DevicePrimary struct {
DevId uint64 `json:"devId"`
IFace01 string `json:"iface01"`
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"`
}
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"`
}
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"`
}
type Reservation 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 ReservationList []Reservation

View File

@@ -0,0 +1,70 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
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"`
}
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")
}
return nil
}
func (v Vins) NatRuleAdd(ctx context.Context, req NatRuleAddRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/natRuleAdd"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,58 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type NatRuleDelRequest struct {
VinsId uint64 `url:"vinsId"`
RuleId uint64 `url:"ruleId"`
}
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")
}
return nil
}
func (v Vins) NatRuleDel(ctx context.Context, req NatRuleDelRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/natRuleDel"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,47 @@
package vins
import (
"context"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type NatRuleListRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq NatRuleListRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) NatRuleList(ctx context.Context, req NatRuleListRequest, options ...opts.DecortOpts) (string, error) {
err := req.Validate()
if err != nil {
return "", err
}
url := "/vins/natRuleList"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,53 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq RestoreRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/restore"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,43 @@
package vins
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SearchRequest struct {
AccountId uint64 `url:"accountId,omitempty"`
RGID uint64 `url:"rgId,omitempty"`
Name string `url:"name,omitempty"`
ShowAll bool `url:"show_all,omitempty"`
}
func (v Vins) Search(ctx context.Context, req SearchRequest, options ...opts.DecortOpts) (VinsList, error) {
url := "/vins/search"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
vinsListRaw, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
vinsList := VinsList{}
err = json.Unmarshal(vinsListRaw, &vinsList)
if err != nil {
return nil, err
}
return vinsList, nil
}

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

@@ -0,0 +1,15 @@
package vins
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Vins struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Vins {
return &Vins{
client,
}
}

View File

@@ -0,0 +1,53 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type VnfdevRedeployRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq VnfdevRedeployRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) VnfdevRedeploy(ctx context.Context, req VnfdevRedeployRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/vnfdevRedeploy"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}

View File

@@ -0,0 +1,53 @@
package vins
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type VnfdevRestartRequest struct {
VinsId uint64 `url:"vinsId"`
}
func (vrq VnfdevRestartRequest) Validate() error {
if vrq.VinsId == 0 {
return errors.New("validation-error: field VinsId can not be empty or equal to 0")
}
return nil
}
func (v Vins) VnfdevRestart(ctx context.Context, req VnfdevRestartRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/vins/vnfdevRestart"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := v.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, nil
}
return result, nil
}