v1.0.0
This commit is contained in:
47
pkg/cloudbroker/vins/audits.go
Normal file
47
pkg/cloudbroker/vins/audits.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"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 {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := "/cloudbroker/vins/audits"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListAudits{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
72
pkg/cloudbroker/vins/create_in_account.go
Normal file
72
pkg/cloudbroker/vins/create_in_account.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create VINS in account
|
||||
type CreateInAccountRequest struct {
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq CreateInAccountRequest) validate() error {
|
||||
if vrq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if vrq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateInAccount creates VINS in account level
|
||||
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/createInAccount"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, 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
|
||||
}
|
||||
76
pkg/cloudbroker/vins/create_in_rg.go
Normal file
76
pkg/cloudbroker/vins/create_in_rg.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for create VINS in resource group
|
||||
type CreateInRGRequest struct {
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq CreateInRGRequest) validate() error {
|
||||
if vrq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
if vrq.RGID == 0 {
|
||||
return errors.New("validation-error: field RGID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateInRG creates VINS in resource group level
|
||||
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/createInRG"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, 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
|
||||
}
|
||||
57
pkg/cloudbroker/vins/default_qos_update.go
Normal file
57
pkg/cloudbroker/vins/default_qos_update.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update QOS
|
||||
type DefaultQOSUpdateRequest struct {
|
||||
// ID of VINS
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
IngressRate uint64 `url:"ingress_rate,omitempty"`
|
||||
|
||||
// Internal traffic burst, kbit
|
||||
// Required: false
|
||||
IngressBirst uint64 `url:"ingress_birst,omitempty"`
|
||||
|
||||
// External traffic rate, kbit
|
||||
// Required: false
|
||||
EgressRate uint64 `url:"egress_rate,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq DefaultQOSUpdateRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultQOSUpdate update default QOS values
|
||||
func (v VINS) DefaultQOSUpdate(ctx context.Context, req DefaultQOSUpdateRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/defaultQosUpdate"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
61
pkg/cloudbroker/vins/delete.go
Normal file
61
pkg/cloudbroker/vins/delete.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete VINS
|
||||
type DeleteRequest struct {
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq DeleteRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes VINS
|
||||
func (v VINS) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/delete"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/disable.go
Normal file
49
pkg/cloudbroker/vins/disable.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disable VINS
|
||||
type DisableRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq DisableRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disable disables VINS by ID
|
||||
func (v VINS) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/disable"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/enable.go
Normal file
49
pkg/cloudbroker/vins/enable.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for enable VINS
|
||||
type EnableRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq EnableRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Enable enables VINS by ID
|
||||
func (v VINS) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/enable"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
60
pkg/cloudbroker/vins/extnet_connect.go
Normal file
60
pkg/cloudbroker/vins/extnet_connect.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for connect external network
|
||||
type ExtNetConnectRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// External network ID
|
||||
// Required: true
|
||||
NetID uint64 `url:"netId"`
|
||||
|
||||
// Directly set IP address
|
||||
// Required: false
|
||||
IP string `url:"ip,omitempty"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq ExtNetConnectRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
if vrq.NetID == 0 {
|
||||
return errors.New("validation-error: field NetID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExtNetConnect connect VINS to external network
|
||||
func (v VINS) ExtNetConnect(ctx context.Context, req ExtNetConnectRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/extNetConnect"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/extnet_disconnect.go
Normal file
49
pkg/cloudbroker/vins/extnet_disconnect.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for disconnect VINS from external network
|
||||
type ExtNetDisconnectRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq ExtNetDisconnectRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExtNetDisconnect disconnect VINS from external network
|
||||
func (v VINS) ExtNetDisconnect(ctx context.Context, req ExtNetDisconnectRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/extNetDisconnect"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
51
pkg/cloudbroker/vins/extnet_list.go
Normal file
51
pkg/cloudbroker/vins/extnet_list.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list VINS external network connections
|
||||
type ExtNetListRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq ExtNetListRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := "/cloudbroker/vins/extNetList"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListExtNets{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
51
pkg/cloudbroker/vins/get.go
Normal file
51
pkg/cloudbroker/vins/get.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about VINS
|
||||
type GetRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq GetRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/get"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
47
pkg/cloudbroker/vins/ip_list.go
Normal file
47
pkg/cloudbroker/vins/ip_list.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for DHCP IP
|
||||
type IPListRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
}
|
||||
|
||||
func (vrq IPListRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 := "/cloudbroker/vins/ipList"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListIPs{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
54
pkg/cloudbroker/vins/ip_release.go
Normal file
54
pkg/cloudbroker/vins/ip_release.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"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 address
|
||||
// Required: false
|
||||
MAC string `url:"mac,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq IPReleaseRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
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) IPRelease(ctx context.Context, req IPReleaseRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/ipRelease"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
79
pkg/cloudbroker/vins/ip_reserve.go
Normal file
79
pkg/cloudbroker/vins/ip_reserve.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for IP reserve
|
||||
type IPReserveRequest struct {
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq IPReserveRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
if vrq.Type == "" {
|
||||
return errors.New("validation-error: field Type must be set")
|
||||
}
|
||||
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()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/ipReserve"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
37
pkg/cloudbroker/vins/list.go
Normal file
37
pkg/cloudbroker/vins/list.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of VINSes
|
||||
type ListRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of VINSes
|
||||
func (v VINS) List(ctx context.Context, req ListRequest) (ListVINS, error) {
|
||||
url := "/cloudbroker/vins/list"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
37
pkg/cloudbroker/vins/list_deleted.go
Normal file
37
pkg/cloudbroker/vins/list_deleted.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of deleted VINSes
|
||||
type ListDeletedRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list of deleted VINSes
|
||||
func (v VINS) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListVINS, error) {
|
||||
url := "/cloudbroker/vins/listDeleted"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
56
pkg/cloudbroker/vins/mass_delete.go
Normal file
56
pkg/cloudbroker/vins/mass_delete.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for delete several VINSes
|
||||
type MassDeleteRequest struct {
|
||||
// VINS IDs
|
||||
// Required: true
|
||||
VINSIDs []uint64 `url:"vinsIds"`
|
||||
|
||||
// Set to true if you want force delete non-empty VINS. Primarily,
|
||||
// VINS is considered non-empty if it has VMs 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 bins purge period
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq MassDeleteRequest) validate() error {
|
||||
if len(vrq.VINSIDs) == 0 {
|
||||
return errors.New("validation-error: field VINSIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MassDelete start jobs to delete several VINSes
|
||||
func (v VINS) MassDelete(ctx context.Context, req MassDeleteRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/massDelete"
|
||||
|
||||
_, err = v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
43
pkg/cloudbroker/vins/mass_disable.go
Normal file
43
pkg/cloudbroker/vins/mass_disable.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for disable several VINSes
|
||||
type MassDisableRequest struct {
|
||||
// VINS IDs
|
||||
// Required: true
|
||||
VINSIDs []uint64 `url:"vinsIds"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq MassDisableRequest) validate() error {
|
||||
if len(vrq.VINSIDs) == 0 {
|
||||
return errors.New("validation-error: field VINSIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MassDisable start jobs to disable several VINSes
|
||||
func (v VINS) MassDisable(ctx context.Context, req MassDisableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/massDisable"
|
||||
|
||||
_, err = v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
43
pkg/cloudbroker/vins/mass_enable.go
Normal file
43
pkg/cloudbroker/vins/mass_enable.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for enable several VINSes
|
||||
type MassEnableRequest struct {
|
||||
// VINS IDs
|
||||
// Required: true
|
||||
VINSIDs []uint64 `url:"vinsIds"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq MassEnableRequest) validate() error {
|
||||
if len(vrq.VINSIDs) == 0 {
|
||||
return errors.New("validation-error: field VINSIDs must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MassEnable start jobs to enable several VINSes
|
||||
func (v VINS) MassEnable(ctx context.Context, req MassEnableRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/massEnable"
|
||||
|
||||
_, err = v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
673
pkg/cloudbroker/vins/models.go
Normal file
673
pkg/cloudbroker/vins/models.go
Normal file
@@ -0,0 +1,673 @@
|
||||
package vins
|
||||
|
||||
// Main information about audit
|
||||
type ItemAudit struct {
|
||||
// Call
|
||||
Call string `json:"call"`
|
||||
|
||||
// Response time
|
||||
ResponseTime float64 `json:"responsetime"`
|
||||
|
||||
// Status code
|
||||
StatusCode uint64 `json:"statuscode"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
|
||||
// User
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
// List of audits
|
||||
type ListAudits []ItemAudit
|
||||
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// List of external networks
|
||||
type ListExtNets []ItemExtNet
|
||||
|
||||
// MGMT
|
||||
type MGMT struct {
|
||||
// IP address
|
||||
IPAddress string `json:"ipaddr"`
|
||||
|
||||
// Password
|
||||
Password string `json:"password"`
|
||||
|
||||
// SSH key
|
||||
SSHKey string `json:"sshkey"`
|
||||
|
||||
// User
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
// Main information about resource
|
||||
type Resources struct {
|
||||
// Number of CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Number of RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// Stack ID
|
||||
StackID uint64 `json:"stackId"`
|
||||
|
||||
// UUID
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
|
||||
// VNF config
|
||||
type Config struct {
|
||||
// MGMT
|
||||
MGMT MGMT `json:"mgmt"`
|
||||
|
||||
// Resources
|
||||
Resources Resources `json:"resources"`
|
||||
}
|
||||
|
||||
// Main information about QOS
|
||||
type QOS struct {
|
||||
// ERate
|
||||
ERate uint64 `json:"eRate"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// InBurst
|
||||
InBurst uint64 `json:"inBurst"`
|
||||
|
||||
// InRate
|
||||
InRate uint64 `json:"inRate"`
|
||||
}
|
||||
|
||||
// Main information about interface
|
||||
type ItemInterface 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"`
|
||||
}
|
||||
|
||||
// List of interfaces
|
||||
type ListInterfaces []ItemInterface
|
||||
|
||||
// Main information about VNF device
|
||||
type VNFDev struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Capabilities
|
||||
Capabilities []string `json:"capabilities"`
|
||||
|
||||
// Config
|
||||
Config Config `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 ListInterfaces `json:"interfaces"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// TechStatus
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
//List of VINS IDs
|
||||
VINS []uint64 `json:"vins"`
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// VNFs sonfig
|
||||
type VNFsConfig 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"`
|
||||
}
|
||||
|
||||
// Primary
|
||||
type Primary struct {
|
||||
// Device ID
|
||||
DevID uint64 `json:"devId"`
|
||||
|
||||
// IFace01
|
||||
IFace01 string `json:"iface01"`
|
||||
|
||||
// IFace02
|
||||
IFace02 string `json:"iface02"`
|
||||
}
|
||||
|
||||
// Devices
|
||||
type Devices struct {
|
||||
// Primary
|
||||
Primary Primary `json:"primary"`
|
||||
}
|
||||
|
||||
// Main information about DHCP
|
||||
type RecordDHCP struct {
|
||||
// Config
|
||||
Config VNFsConfig `json:"config"`
|
||||
|
||||
// DHCP details
|
||||
InfoVNF
|
||||
}
|
||||
|
||||
// GW config
|
||||
type GWConfig 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 QOS `json:"qos"`
|
||||
}
|
||||
|
||||
// Main information about GW
|
||||
type RecordGW struct {
|
||||
// Config
|
||||
Config GWConfig `json:"config"`
|
||||
|
||||
// GW details
|
||||
InfoVNF
|
||||
}
|
||||
|
||||
// NAT config
|
||||
type NATConfig struct {
|
||||
// Network mask
|
||||
NetMask uint64 `json:"netmask"`
|
||||
|
||||
// Network
|
||||
Network string `json:"network"`
|
||||
|
||||
// Rules
|
||||
Rules []interface{} `json:"rules"`
|
||||
}
|
||||
|
||||
// Main information about NAT
|
||||
type RecordNAT struct {
|
||||
// Config
|
||||
Config NATConfig `json:"config"`
|
||||
|
||||
// NAT details
|
||||
InfoVNF
|
||||
}
|
||||
|
||||
// NAT/GW/NAT details
|
||||
type InfoVNF struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Config
|
||||
Config NATConfig `json:"config"`
|
||||
|
||||
// CreatedTime
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Devices
|
||||
Devices Devices `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"`
|
||||
}
|
||||
|
||||
// main information about VNF
|
||||
type RecordVNFs struct {
|
||||
// DHCP
|
||||
DHCP RecordDHCP `json:"DHCP"`
|
||||
|
||||
// GW
|
||||
GW RecordGW `json:"GW"`
|
||||
|
||||
// NAT
|
||||
NAT RecordNAT `json:"NAT"`
|
||||
}
|
||||
|
||||
// Detailed information about VINS
|
||||
type RecordVINS struct {
|
||||
// VNF device
|
||||
VNFDev VNFDev `json:"VNFDev"`
|
||||
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Default GW
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
|
||||
// Default QOS
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// PreReservationsNum
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
|
||||
// Redundant
|
||||
Redundant bool `json:"redundant"`
|
||||
|
||||
// Resource group ID
|
||||
RGID uint64 `json:"rgId"`
|
||||
|
||||
// SecVNFDevID
|
||||
SecVNFDevID uint64 `json:"secVnfDevId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// User managed
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// VNFs information
|
||||
VNFs RecordVNFs `json:"vnfs"`
|
||||
|
||||
// VXLAN ID
|
||||
VXLANID uint64 `json:"vxlanId"`
|
||||
}
|
||||
|
||||
// Main information about IP
|
||||
type ItemIP struct {
|
||||
// IP
|
||||
IP string `json:"ip"`
|
||||
|
||||
// MAC
|
||||
MAC string `json:"mac"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"vmId"`
|
||||
|
||||
// Client type
|
||||
ClientType string `json:"clientType"`
|
||||
|
||||
// Domain name
|
||||
DomainName string `json:"domainname"`
|
||||
|
||||
// Hostname
|
||||
Hostname string `json:"hostname"`
|
||||
}
|
||||
|
||||
// List of information about IPs
|
||||
type ListIPs []ItemIP
|
||||
|
||||
// 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 NAT rules
|
||||
type ListNATRules []ItemNATRule
|
||||
|
||||
// Shorted information about VNF
|
||||
type ItemVNFs struct {
|
||||
// DHCP
|
||||
DHCP uint64 `json:"dhcp"`
|
||||
|
||||
// DNS
|
||||
DNS uint64 `json:"dns"`
|
||||
|
||||
// FW
|
||||
FW uint64 `json:"fw"`
|
||||
|
||||
// GW
|
||||
GW uint64 `json:"gw"`
|
||||
|
||||
// NAT
|
||||
NAT uint64 `json:"nat"`
|
||||
|
||||
// VPN
|
||||
VPN uint64 `json:"vpn"`
|
||||
}
|
||||
|
||||
// Main information about VINS
|
||||
type ItemVINS struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Created by
|
||||
CreatedBy string `json:"createdBy"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Default GW
|
||||
DefaultGW string `json:"defaultGW"`
|
||||
|
||||
// Default QOS
|
||||
DefaultQOS QOS `json:"defaultQos"`
|
||||
|
||||
// Deleted by
|
||||
DeletedBy string `json:"deletedBy"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// External IP
|
||||
ExternalIP string `json:"externalIP"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// PreReservationsNum
|
||||
PreReservationsNum uint64 `json:"preReservationsNum"`
|
||||
|
||||
// PriVNFDevID
|
||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
|
||||
// User managed
|
||||
UserManaged bool `json:"userManaged"`
|
||||
|
||||
// VNFs
|
||||
VNFs ItemVNFs `json:"vnfs"`
|
||||
|
||||
// VXLAN ID
|
||||
VXLANID uint64 `json:"vxlanId"`
|
||||
}
|
||||
|
||||
// List of VINS
|
||||
type ListVINS []ItemVINS
|
||||
81
pkg/cloudbroker/vins/nat_rule_add.go
Normal file
81
pkg/cloudbroker/vins/nat_rule_add.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq NATRuleAddRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
if vrq.IntIP == "" {
|
||||
return errors.New("validation-error: field IntIP must be set")
|
||||
}
|
||||
if vrq.IntPort == 0 {
|
||||
return errors.New("validation-error: field IntPort must be set")
|
||||
}
|
||||
if vrq.ExtPortStart == 0 {
|
||||
return errors.New("validation-error: field ExtPortStart must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NATRuleAdd create NAT (port forwarding) rule on VINS
|
||||
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/natRuleAdd"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, 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
|
||||
}
|
||||
57
pkg/cloudbroker/vins/nat_rule_del.go
Normal file
57
pkg/cloudbroker/vins/nat_rule_del.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq NATRuleDelRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
if vrq.RuleID == 0 {
|
||||
return errors.New("validation-error: field RuleID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/natRuleDel"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
51
pkg/cloudbroker/vins/nat_rule_list.go
Normal file
51
pkg/cloudbroker/vins/nat_rule_list.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of NAT rules
|
||||
type NATRuleListRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq NATRuleListRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/natRuleList"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListNATRules{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
57
pkg/cloudbroker/vins/net_qos.go
Normal file
57
pkg/cloudbroker/vins/net_qos.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for update all VINS interfaces QOS
|
||||
type NetQOSRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Internal traffic, kbit
|
||||
// Required: false
|
||||
IngressRate uint64 `url:"ingress_rate,omitempty"`
|
||||
|
||||
// Internal traffic burst, kbit
|
||||
// Required: false
|
||||
IngressBirst uint64 `url:"ingress_birst,omitempty"`
|
||||
|
||||
// External traffic rate, kbit
|
||||
// Required: false
|
||||
EgressRate uint64 `url:"egress_rate,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq NetQOSRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NetQOS update all VINS interfaces QOS
|
||||
func (v VINS) NetQOS(ctx context.Context, req NetQOSRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/netQos"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
24
pkg/cloudbroker/vins/raise_down.go
Normal file
24
pkg/cloudbroker/vins/raise_down.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// RaiseDown starting all VINSes VNFDevs in "DOWN" tech status
|
||||
func (v VINS) RaiseDown(ctx context.Context) (bool, error) {
|
||||
url := "/cloudbroker/vins/raiseDown"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/restore.go
Normal file
49
pkg/cloudbroker/vins/restore.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restore
|
||||
type RestoreRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq RestoreRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: field VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restores VINS from recycle bin
|
||||
func (v VINS) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/restore"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/search.go
Normal file
49
pkg/cloudbroker/vins/search.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"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"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
// Search search VINSes
|
||||
func (v VINS) Search(ctx context.Context, req SearchRequest) (ListVINS, error) {
|
||||
url := "/cloudbroker/vins/search"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListVINS{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
18
pkg/cloudbroker/vins/vins.go
Normal file
18
pkg/cloudbroker/vins/vins.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// 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: client,
|
||||
}
|
||||
}
|
||||
49
pkg/cloudbroker/vins/vnfdev_redeploy.go
Normal file
49
pkg/cloudbroker/vins/vnfdev_redeploy.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for redeploy VNF devices
|
||||
type VNFDevRedeployRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq VNFDevRedeployRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: fiels VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VNFDevRedeploy redeploy VINS VNFDevs
|
||||
func (v VINS) VNFDevRedeploy(ctx context.Context, req VNFDevRedeployRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/vnfdevRedeploy"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/vnfdev_reset.go
Normal file
49
pkg/cloudbroker/vins/vnfdev_reset.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for reset VNF device
|
||||
type VNFDevResetRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq VNFDevResetRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: fiels VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VNFDevReset reset VINSes primary VNF device
|
||||
func (v VINS) VNFDevReset(ctx context.Context, req VNFDevResetRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/vnfdevReset"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/vnfdev_restart.go
Normal file
49
pkg/cloudbroker/vins/vnfdev_restart.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for reboot VINSes primary VNF device
|
||||
type VNFDevRestartRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: fal
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq VNFDevRestartRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: fiels VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VNFDevRestart reboot VINSes primary VNF device
|
||||
func (v VINS) VNFDevRestart(ctx context.Context, req VNFDevRestartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/vnfdevRestart"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/vnfdev_start.go
Normal file
49
pkg/cloudbroker/vins/vnfdev_start.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for start VNF devices
|
||||
type VNFDevStartRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq VNFDevStartRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: fiels VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VNFDevStart starts VINSes primary VNF device
|
||||
func (v VINS) VNFDevStart(ctx context.Context, req VNFDevStartRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/vnfdevStart"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
49
pkg/cloudbroker/vins/vnfdev_stop.go
Normal file
49
pkg/cloudbroker/vins/vnfdev_stop.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package vins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for stop VNF devices
|
||||
type VNFDevStopRequest struct {
|
||||
// VINS ID
|
||||
// Required: true
|
||||
VINSID uint64 `url:"vinsId"`
|
||||
|
||||
// Reason for action
|
||||
// Required: true
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (vrq VNFDevStopRequest) validate() error {
|
||||
if vrq.VINSID == 0 {
|
||||
return errors.New("validation-error: fiels VINSID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// VNFDevStop stop VINSes primary VNF device
|
||||
func (v VINS) VNFDevStop(ctx context.Context, req VNFDevStopRequest) (bool, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/vins/vnfdevStop"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user