Compare commits
4 Commits
v1.6.0-eps
...
v1.6.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 1575b75fa6 | |||
| 35fa4af0d6 | |||
| d3e6309ef8 | |||
| 78a4152471 |
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,32 +1,4 @@
|
|||||||
## Version 1.6.0
|
## Version 1.6.1
|
||||||
|
|
||||||
### Bugfix
|
### Bugfix
|
||||||
- Fix cloudaApi/client and cloudapi/legacy-client, the cyclicity of sending requests has been removed
|
- Fixed tags url and json CreateRequest in cloudapi/k8s/create and cloudbroker/k8s/create
|
||||||
- Edit description field SSLSkipVerify in cloudapi/config/config and cloudapi/config/legacy-config
|
|
||||||
- Remove tags required fields ExtNetID VINSID Start in model CreateRequest in cloudapi/lb/create
|
|
||||||
- Add tags required fields BindingName BindingAddress BindingPort in model FrontendBindRequest in cloudapi/lb/frontend_bind
|
|
||||||
- Add tags required fields BindingAddress BindingPort in model FrontendBindUpdateRequest in cloudapi/lb/frontend_bind_update
|
|
||||||
|
|
||||||
### Feature
|
|
||||||
- Add field UserData in cloudapi/bservice/group_add
|
|
||||||
- Add fields VinsId, LbSysctlParams, HighlyAvailable, AdditionalSANs, InitConfiguration, ClusterConfiguration, KubeletConfiguration, KubeProxyConfiguration, JoinConfiguration, UserData, ExtNetOnly, OidcCertificate in model request cloudapi/k8s/create
|
|
||||||
- Add field Externalip in model ItemDetailedInfo in cloudapi/k8s/models
|
|
||||||
- Add fields SysctlParams, HighlyAvailable in model CreateRequest in cloudapi/lb/create
|
|
||||||
- Add fields BackendHAIP, FrontendHAIP, PartK8s, SysctlParams in model RecordLB in cloudapi/lb/models
|
|
||||||
- Add models InfoStack, ItemStack, ListStacks cloudapi/stack/models
|
|
||||||
- Add field Routes and type Route in CreateInAccountRequest and CreateInRGRequest models in cloudapi/vins/create_in_rg and /cloudapi/vins/create_in_account
|
|
||||||
- Add field Enabled in model ItemVNFInterface
|
|
||||||
- Add fields Routes in models RecordNAT, RecordDHCP, RecordGW and add type ListStaticRoutes, ListRoutes, ItemRoutes in cloudapi/vins/models
|
|
||||||
|
|
||||||
- Added new endpoints:
|
|
||||||
- cloudapi/k8s/get_worker_nodes_meta_data
|
|
||||||
- cloudapi/k8s/update_worker_nodes_meta_data
|
|
||||||
- cloudapi/lb/make_highly_available
|
|
||||||
- cloudapi/lb/updateSysctParams
|
|
||||||
- cloudapi/stack/get
|
|
||||||
- cloudapi/stack/list
|
|
||||||
- cloudapi/vins/static_route_list
|
|
||||||
- cloudapi/vins/static_route_access_grant
|
|
||||||
- cloudapi/vins/static_route_access_revoke
|
|
||||||
- cloudapi/vins/static_route_add
|
|
||||||
- cloudapi/vins/static_route_del
|
|
||||||
|
|||||||
331
client.go
331
client.go
@@ -7,14 +7,17 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||||
|
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
|
k8s_cb"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
@@ -68,6 +71,283 @@ func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||||
|
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
|
||||||
|
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
|
||||||
|
|
||||||
|
if okCa {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCaCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCaCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCaCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCaCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCaCreateReq.K8SCIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCaCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCaCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCaCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCaCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCaCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCaCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCaCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCaCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCaCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCaCreateReq.MasterCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCaCreateReq.MasterNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCaCreateReq.MasterRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCaCreateReq.MasterDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCaCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCaCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCaCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCaCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCaCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCaCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCaCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCaCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCaCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCaCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCaCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCaCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCaCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCaCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = dc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := dc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
} else if okCb {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCbCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCbCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCbCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCbCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCbCreateReq.K8CIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCbCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCbCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCbCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCbCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCbCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCbCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCbCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCbCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCbCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(k8sCbCreateReq.MasterCPU, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(k8sCbCreateReq.MasterNum, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(k8sCbCreateReq.MasterRAM, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(k8sCbCreateReq.MasterDisk, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(k8sCbCreateReq.WorkerCPU, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(k8sCbCreateReq.WorkerNum, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(k8sCbCreateReq.WorkerRAM, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(k8sCbCreateReq.WorkerDisk, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCbCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCbCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCbCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCbCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCbCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCbCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCbCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCbCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCbCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCbCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCbCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCbCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCbCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCbCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = dc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := dc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
values, err := query.Values(params)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -143,20 +423,47 @@ func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
|||||||
// var resp *http.Response
|
// var resp *http.Response
|
||||||
// var err error
|
// var err error
|
||||||
buf, _ := io.ReadAll(req.Body)
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||||
req = req.Clone(req.Context())
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
resp, err := dc.client.Do(req)
|
||||||
resp, err := dc.client.Do(req)
|
|
||||||
|
|
||||||
// if err == nil {
|
// if err == nil {
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
err = fmt.Errorf("%s", respBytes)
|
err = fmt.Errorf("%s", respBytes)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *DecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", ctype)
|
||||||
|
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := dc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
|||||||
193
legacy-client.go
193
legacy-client.go
@@ -7,8 +7,10 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -16,6 +18,7 @@ import (
|
|||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,6 +71,148 @@ func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||||
|
if k8sCreateReq, ok := params.(k8s.CreateRequest); ok {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCreateReq.K8SCIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCreateReq.MasterCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCreateReq.MasterNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCreateReq.MasterRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCreateReq.MasterDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCreateReq.WorkerCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCreateReq.WorkerNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCreateReq.WorkerRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCreateReq.WorkerDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(k8sCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
if err := ldc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("authkey", ldc.cfg.Token)
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := ldc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
values, err := query.Values(params)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -140,21 +285,49 @@ func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
|
|||||||
// var resp *http.Response
|
// var resp *http.Response
|
||||||
// var err error
|
// var err error
|
||||||
buf, _ := io.ReadAll(req.Body)
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
req = req.Clone(req.Context())
|
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
resp, err := ldc.client.Do(req)
|
|
||||||
|
|
||||||
// if err == nil {
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
if resp.StatusCode == 200 {
|
resp, err := ldc.client.Do(req)
|
||||||
return resp, err
|
|
||||||
}
|
// if err == nil {
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
if resp.StatusCode == 200 {
|
||||||
err = fmt.Errorf("%s", respBytes)
|
return resp, err
|
||||||
resp.Body.Close()
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ldc *LegacyDecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", ctype)
|
||||||
|
req.Header.Add("Authorization", "bearer "+ldc.cfg.Token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := ldc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Custom sysctl values for Load Balancer instance. Applied on boot
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
// Required: false
|
// Required: false
|
||||||
LbSysctlParams string `url:"-" json:"lbSysctlParams,omitempty" validate:"omitempty,dive"`
|
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||||
|
|
||||||
// Use Highly Available schema for LB deploy
|
// Use Highly Available schema for LB deploy
|
||||||
// Required: false
|
// Required: false
|
||||||
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
HighlyAvailable bool `url:"highlyAvailableLB,omitempty" json:"highlyAvailableLB,omitempty"`
|
||||||
|
|
||||||
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
|
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -160,10 +160,10 @@ type CreateRequest struct {
|
|||||||
// Use only selected ExtNet for infrastructure connections
|
// Use only selected ExtNet for infrastructure connections
|
||||||
// Required: false
|
// Required: false
|
||||||
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
||||||
|
|
||||||
// Insert ssl certificate in x509 pem format
|
// Insert ssl certificate in x509 pem format
|
||||||
// Required: false
|
// Required: false
|
||||||
OidcCertificate []byte `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// type wrapperCreateRequest struct {
|
// type wrapperCreateRequest struct {
|
||||||
@@ -173,6 +173,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
43
pkg/cloudbroker/compute/set_custom_fields.go
Normal file
43
pkg/cloudbroker/compute/set_custom_fields.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
// Request struct for setting customFields values for the Compute
|
||||||
|
type SetCustomFieldsRequest struct {
|
||||||
|
// ID of the compute
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Custom fields for Compute. Must be dict.
|
||||||
|
// Required: true
|
||||||
|
CustomFields string `url:"customFields" json:"customFields" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCustomFields sets customFields values for the Compute
|
||||||
|
func (c Compute) SetCustomFields(ctx context.Context, req SetCustomFieldsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/compute/setCustomFields"
|
||||||
|
|
||||||
|
res, err := c.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
|
||||||
|
}
|
||||||
@@ -2,12 +2,24 @@ package extnet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
// Destination network
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Request struct for create external network
|
// Request struct for create external network
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// External network name
|
// External network name
|
||||||
@@ -70,6 +82,15 @@ type CreateRequest struct {
|
|||||||
// OpenvSwith bridge name for ExtNet connection
|
// OpenvSwith bridge name for ExtNet connection
|
||||||
// Required: false
|
// Required: false
|
||||||
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
||||||
|
|
||||||
|
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||||
|
// Required: false
|
||||||
|
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Routes []string `url:"routes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates new external network into platform
|
// Create creates new external network into platform
|
||||||
@@ -81,9 +102,31 @@ func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
if len(req.Routes) != 0 {
|
||||||
|
routes = make([]string, 0, len(req.Routes))
|
||||||
|
|
||||||
|
for r := range req.Routes {
|
||||||
|
b, err := json.Marshal(req.Routes[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
routes = append(routes, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routes = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Routes: routes,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/extnet/create"
|
url := "/cloudbroker/extnet/create"
|
||||||
|
|
||||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,3 +151,33 @@ type RecordExtNet struct {
|
|||||||
// List reservations
|
// List reservations
|
||||||
Reservations ListReservations `json:"reservations"`
|
Reservations ListReservations `json:"reservations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of static routes
|
||||||
|
type ListStaticRoutes struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemRoutes `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed information about Routes
|
||||||
|
type ItemRoutes struct {
|
||||||
|
//Compute Id
|
||||||
|
ComputeIds []uint64 `json:"computeIds"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `json:"gateway"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `json:"netmask"`
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
48
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for grant access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessGrantRequest struct {
|
||||||
|
// ExtNet ID to grant access
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to grant access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to grant access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grant access to static route to Compute/ViNS
|
||||||
|
func (v ExtNet) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAccessGrant"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
48
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for revoke access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessRevokeRequest struct {
|
||||||
|
// ExtNet ID to revoke access
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to revoke access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to revoke access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke access to static route to Compute/ViNS
|
||||||
|
func (v ExtNet) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAccessRevoke"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
56
pkg/cloudbroker/extnet/static_route_add.go
Normal file
56
pkg/cloudbroker/extnet/static_route_add.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add static route
|
||||||
|
type StaticRouteAddRequest struct {
|
||||||
|
// ExtNet ID to add static route
|
||||||
|
// Required: true
|
||||||
|
ExtNetId uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
// Required: true
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network mask in 255.255.255.255 format
|
||||||
|
// Required: true
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
// Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
// Required: true
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs which have access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticRouteAdd add new static route to ViNS
|
||||||
|
func (v ExtNet) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAdd"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/extnet/static_route_del.go
Normal file
44
pkg/cloudbroker/extnet/static_route_del.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for remove static route from ViNS
|
||||||
|
type StaticRouteDelRequest struct {
|
||||||
|
// ExtNet ID to remove static route from
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to remove, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove static route from ViNS
|
||||||
|
func (v ExtNet) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteDel"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/extnet/static_route_list.go
Normal file
42
pkg/cloudbroker/extnet/static_route_list.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for static route list
|
||||||
|
type StaticRouteListRequest struct {
|
||||||
|
// ExtNet ID to show list of static routes
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show list of static routes for ViNS
|
||||||
|
func (v ExtNet) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteList"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStaticRoutes{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// type Params []string
|
||||||
|
|
||||||
// Request struct for create K8S
|
// Request struct for create K8S
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// Name of kubernetes cluster
|
// Name of kubernetes cluster
|
||||||
@@ -24,7 +26,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Name for first worker group created with cluster
|
// Name for first worker group created with cluster
|
||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required, workerGroupName"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
|
||||||
|
|
||||||
// Network plugin
|
// Network plugin
|
||||||
// Must be one of these values: flunnel, weawenet, calico
|
// Must be one of these values: flunnel, weawenet, calico
|
||||||
@@ -100,16 +102,77 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
|
||||||
|
// ID of the ViNS to connect k8s cluster. If nothing is specified, ViNS will be created automatically
|
||||||
|
// Required: false
|
||||||
|
VinsId uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
// Create kubernetes cluster with masters nodes behind load balancer if true.
|
// Create kubernetes cluster with masters nodes behind load balancer if true.
|
||||||
// Otherwise give all cluster nodes direct external addresses from selected external network
|
// Otherwise give all cluster nodes direct external addresses from selected external network
|
||||||
// Required: false
|
// Required: false
|
||||||
WithLB bool `url:"withLB" json:"withLB"`
|
WithLB bool `url:"withLB" json:"withLB"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailableLB,omitempty" json:"highlyAvailableLB,omitempty"`
|
||||||
|
|
||||||
|
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
|
||||||
|
// Required: false
|
||||||
|
AdditionalSANs []string `url:"additionalSANs,omitempty" json:"additionalSANs,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define settings and actions that should be performed before any other component in the cluster starts.
|
||||||
|
// It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
InitConfiguration string `url:"initConfiguration,omitempty" json:"initConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define global settings and configurations for the entire cluster.
|
||||||
|
// It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
ClusterConfiguration string `url:"clusterConfiguration,omitempty" json:"clusterConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster.
|
||||||
|
// It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeletConfiguration string `url:"kubeletConfiguration,omitempty" json:"kubeletConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster.
|
||||||
|
// It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeProxyConfiguration string `url:"kubeProxyConfiguration,omitempty" json:"kubeProxyConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings for joining a node to a cluster.
|
||||||
|
// It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
JoinConfiguration string `url:"joinConfiguration,omitempty" json:"joinConfiguration,omitempty"`
|
||||||
|
|
||||||
// Text description of this kubernetes cluster
|
// Text description of this kubernetes cluster
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: false
|
||||||
|
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||||
|
|
||||||
|
// Use only selected ExtNet for infrastructure connections
|
||||||
|
// Required: false
|
||||||
|
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
||||||
|
|
||||||
|
// Insert ssl certificate in x509 pem format
|
||||||
|
// Required: false
|
||||||
|
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// type wrapperCreateRequest struct {
|
||||||
|
// CreateRequest
|
||||||
|
// Params []string `url:"lbSysctlParams,omitempty"`
|
||||||
|
// }
|
||||||
|
|
||||||
// Create creates a new kubernetes cluster in the specified resource group
|
// Create creates a new kubernetes cluster in the specified resource group
|
||||||
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -119,6 +182,28 @@ func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var params []string
|
||||||
|
|
||||||
|
// if len(req.LbSysctlParams) != 0 {
|
||||||
|
// params = make([]string, 0, len(req.LbSysctlParams))
|
||||||
|
|
||||||
|
// for r := range req.LbSysctlParams {
|
||||||
|
// b, err := json.Marshal(req.LbSysctlParams[r])
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// params = append(params, string(b))
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// params = []string{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// reqWrapped := wrapperCreateRequest{
|
||||||
|
// CreateRequest: req,
|
||||||
|
// Params: params,
|
||||||
|
// }
|
||||||
|
|
||||||
url := "/cloudbroker/k8s/create"
|
url := "/cloudbroker/k8s/create"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
|||||||
38
pkg/cloudbroker/k8s/get_worker_nodes_meta_data.go
Normal file
38
pkg/cloudbroker/k8s/get_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get worker group metadata by ID
|
||||||
|
type GetWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get worker group metadata by ID
|
||||||
|
func (k K8S) GetWorkerNodesMetaData(ctx context.Context, req GetWorkerNodesMetaDataRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/k8s/getWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@ package k8s
|
|||||||
|
|
||||||
// Deteiled information
|
// Deteiled information
|
||||||
type ItemDetailedInfo struct {
|
type ItemDetailedInfo struct {
|
||||||
|
// External Ip
|
||||||
|
ExternalIp string `json:"externalip"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
@@ -11,7 +14,7 @@ type ItemDetailedInfo struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
// Status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
48
pkg/cloudbroker/k8s/update_worker_nodes_meta_data.go
Normal file
48
pkg/cloudbroker/k8s/update_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add worker to a kubernetes cluster
|
||||||
|
type UpdateWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: true
|
||||||
|
UserData string `url:"userData" json:"userData" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WorkerAdd adds worker nodes to a kubernetes cluster
|
||||||
|
func (k K8S) UpdateWorkerNodesMetaData(ctx context.Context, req UpdateWorkerNodesMetaDataRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/k8s/updateWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.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,7 +79,11 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
|
// Stack ID
|
||||||
|
// Required: false
|
||||||
|
StackID uint64 `url:"stackId,omitempty" json:"stackId,omitempty"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -88,6 +92,10 @@ type CreateRequest struct {
|
|||||||
// Compute purpose
|
// Compute purpose
|
||||||
// Required: false
|
// Required: false
|
||||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||||
|
|
||||||
|
// Reason for action
|
||||||
|
// Required: false
|
||||||
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateRequest struct {
|
type wrapperCreateRequest struct {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ type MassCreateRequest struct {
|
|||||||
|
|
||||||
// Start after create of not
|
// Start after create of not
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Reason to action
|
// Reason to action
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Stack ID
|
// Stack ID
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -97,6 +97,10 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
CustomField string `url:"customFields,omitempty" json:"customFields,omitempty"`
|
CustomField string `url:"customFields,omitempty" json:"customFields,omitempty"`
|
||||||
|
|
||||||
|
//Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
|
||||||
|
// Required: false
|
||||||
|
Driver string `url:"driver,omitempty" json:"driver,omitempty"`
|
||||||
|
|
||||||
// Reason for action
|
// Reason for action
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ type CreateBlankRequest struct {
|
|||||||
// Text description of this VM
|
// Text description of this VM
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
|
||||||
|
//Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
|
||||||
|
// Required: false
|
||||||
|
Driver string `url:"driver,omitempty" json:"driver,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateBlankRequest struct {
|
type wrapperCreateBlankRequest struct {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ type MassCreateRequest struct {
|
|||||||
|
|
||||||
// Start after create of not
|
// Start after create of not
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Reason to action
|
// Reason to action
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package lb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Params []string
|
||||||
|
|
||||||
// Request struct for create load balancer
|
// Request struct for create load balancer
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// ID of the resource group where this load balancer instance will be located
|
// ID of the resource group where this load balancer instance will be located
|
||||||
@@ -20,12 +24,20 @@ type CreateRequest struct {
|
|||||||
Name string `url:"name" json:"name" validate:"required"`
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
// External network to connect this load balancer to
|
// External network to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||||
|
|
||||||
// Internal network (VINS) to connect this load balancer to
|
// Internal network (VINS) to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
||||||
|
|
||||||
// Start now Load balancer
|
// Start now Load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -36,6 +48,11 @@ type CreateRequest struct {
|
|||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Params []string `url:"sysctlParams,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Create method will create a new load balancer instance
|
// Create method will create a new load balancer instance
|
||||||
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -45,9 +62,35 @@ func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.ExtNetID == 0 && req.VINSID == 0 {
|
||||||
|
return 0, errors.New("vinsId and extNetId cannot be both in the value 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/lb/create"
|
url := "/cloudbroker/lb/create"
|
||||||
|
|
||||||
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
40
pkg/cloudbroker/lb/make_highly_available.go
Normal file
40
pkg/cloudbroker/lb/make_highly_available.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for make Load Balancer Highly available
|
||||||
|
type HighlyAvailableRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make Load Balancer Highly available
|
||||||
|
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/lb/makeHighlyAvailable"
|
||||||
|
|
||||||
|
res, err := l.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
|
||||||
|
}
|
||||||
@@ -156,6 +156,9 @@ type RecordLB struct {
|
|||||||
// Access Control List
|
// Access Control List
|
||||||
ACL []interface{} `json:"acl"`
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
// List of load balancer backends
|
// List of load balancer backends
|
||||||
Backends ListBackends `json:"backends"`
|
Backends ListBackends `json:"backends"`
|
||||||
|
|
||||||
@@ -171,6 +174,9 @@ type RecordLB struct {
|
|||||||
// External network ID
|
// External network ID
|
||||||
ExtNetID uint64 `json:"extnetId"`
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
// List of load balancer frontends
|
// List of load balancer frontends
|
||||||
Frontends ListFrontends `json:"frontends"`
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
@@ -192,6 +198,9 @@ type RecordLB struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Part K8s
|
||||||
|
PartK8s bool `json:"partK8s"`
|
||||||
|
|
||||||
// Primary node
|
// Primary node
|
||||||
PrimaryNode Node `json:"primaryNode"`
|
PrimaryNode Node `json:"primaryNode"`
|
||||||
|
|
||||||
@@ -204,6 +213,9 @@ type RecordLB struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []string `json:"sysctlParams"`
|
||||||
|
|
||||||
// Tech status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
@@ -219,6 +231,9 @@ type ItemLBList struct {
|
|||||||
// Access Control List
|
// Access Control List
|
||||||
ACL []interface{} `json:"acl"`
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
// List of load balancer backends
|
// List of load balancer backends
|
||||||
Backends ListBackends `json:"backends"`
|
Backends ListBackends `json:"backends"`
|
||||||
|
|
||||||
@@ -246,6 +261,9 @@ type ItemLBList struct {
|
|||||||
// External network ID
|
// External network ID
|
||||||
ExtNetID uint64 `json:"extnetId"`
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
// List of load balancer frontends
|
// List of load balancer frontends
|
||||||
Frontends ListFrontends `json:"frontends"`
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
@@ -279,6 +297,9 @@ type ItemLBList struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []string `json:"sysctlParams"`
|
||||||
|
|
||||||
// Tech status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
|
|||||||
72
pkg/cloudbroker/lb/updateSysctParams.go
Normal file
72
pkg/cloudbroker/lb/updateSysctParams.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for update sysct params for lb
|
||||||
|
type UpdateSysctParamsRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: true
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperUpdateSysctParamsRequest struct {
|
||||||
|
UpdateSysctParamsRequest
|
||||||
|
Params []string `url:"sysctlParams" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create method will create a new load balancer instance
|
||||||
|
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperUpdateSysctParamsRequest{
|
||||||
|
UpdateSysctParamsRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/lb/updateSysctParams"
|
||||||
|
|
||||||
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -411,8 +411,19 @@ type InfoVNF struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of static routes
|
||||||
|
type ListStaticRoutes struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemRoutes `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of Routes
|
||||||
type ListRoutes []ItemRoutes
|
type ListRoutes []ItemRoutes
|
||||||
|
|
||||||
|
// Detailed information about Routes
|
||||||
type ItemRoutes struct {
|
type ItemRoutes struct {
|
||||||
//Compute Id
|
//Compute Id
|
||||||
ComputeIds []uint64 `json:"computeIds"`
|
ComputeIds []uint64 `json:"computeIds"`
|
||||||
@@ -424,7 +435,7 @@ type ItemRoutes struct {
|
|||||||
Gateway string `json:"gateway"`
|
Gateway string `json:"gateway"`
|
||||||
|
|
||||||
// GUID
|
// GUID
|
||||||
GUID uint64 `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|||||||
48
pkg/cloudbroker/vins/static_route_access_grant.go
Normal file
48
pkg/cloudbroker/vins/static_route_access_grant.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for grant access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessGrantRequest struct {
|
||||||
|
// ViNS ID to grant access
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to grant access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to grant access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grant access to static route to Compute/ViNS
|
||||||
|
func (v VINS) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vins/staticRouteAccessGrant"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/vins/static_route_access_revoke.go
Normal file
48
pkg/cloudbroker/vins/static_route_access_revoke.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for revoke access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessRevokeRequest struct {
|
||||||
|
// ViNS ID to revoke access
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to revoke access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to revoke access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke access to static route to Compute/ViNS
|
||||||
|
func (v VINS) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vins/staticRouteAccessRevoke"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
56
pkg/cloudbroker/vins/static_route_add.go
Normal file
56
pkg/cloudbroker/vins/static_route_add.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add static route
|
||||||
|
type StaticRouteAddRequest struct {
|
||||||
|
// VINS ID
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
// Required: true
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network mask in 255.255.255.255 format
|
||||||
|
// Required: true
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
// Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
// Required: true
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs which have access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticRouteAdd add new static route to ViNS
|
||||||
|
func (v VINS) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vins/staticRouteAdd"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/vins/static_route_del.go
Normal file
44
pkg/cloudbroker/vins/static_route_del.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for remove static route from ViNS
|
||||||
|
type StaticRouteDelRequest struct {
|
||||||
|
// ViNS ID to remove static route from
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to remove, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove static route from ViNS
|
||||||
|
func (v VINS) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vins/staticRouteDel"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/vins/static_route_list.go
Normal file
42
pkg/cloudbroker/vins/static_route_list.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for static route list
|
||||||
|
type StaticRouteListRequest struct {
|
||||||
|
// ViNS ID to show list of static routes
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show list of static routes for ViNS
|
||||||
|
func (v VINS) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vins/staticRouteList"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStaticRoutes{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user