Compare commits
3 Commits
v1.5.16
...
v1.6.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
| afcbc7e749 | |||
| 0b3de4df7f | |||
| c0608d08b9 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1,3 @@
|
|||||||
cmd/
|
cmd/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
.fleet/
|
|
||||||
.DS_Store
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
## Version 1.5.16
|
## Version 1.6.0-beta
|
||||||
|
|
||||||
### Bugfix
|
### Bugfix
|
||||||
- Fix EOF error by closing request
|
- Fixed RoudTrip bug in HTTP transport, made it concurrent safe
|
||||||
46
README.md
46
README.md
@@ -62,11 +62,12 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
- `BService` - управление группами виртуальных машин (computes);
|
- `BService` - управление группами виртуальных машин (computes);
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
|
- `ComputeCI` - управление конвейром для создания виртуальных машин;
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - получение информации о конвейере для создания кластера;
|
- `K8CI` - управление конвейром для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
@@ -83,39 +84,30 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
||||||
|
|
||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
- `APIAccess` - управление доступом к API и его объектам;
|
|
||||||
- `Backup` - управление резервным копированием;
|
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
- `FLIPGroup` - управление группами с «плавающими» ip адресами;
|
|
||||||
- `Grid` - управление площадками;
|
- `Grid` - управление площадками;
|
||||||
- `Group` - управление группами пользователей;
|
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - управление конвейром для создания кластера;
|
- `K8CI` - управление конвейром для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
- `LB` - управление балансировщиками нагрузки;
|
- `LB` - управление балансировщиками нагрузки;
|
||||||
- `PCIDevice` - управление устройствами;
|
|
||||||
- `RG` - управление ресурсными группами аккаунта;
|
- `RG` - управление ресурсными группами аккаунта;
|
||||||
- `SEP` - управление storage endpoint (sep);
|
- `SEP` - управление storage endpoint (sep);
|
||||||
- `Stack` - получение информации о стеках;
|
|
||||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||||
- `User` - управление пользователями (индивидуально);
|
|
||||||
- `VGPU` - управление виртуальными графическими процессорами;
|
|
||||||
- `VINS` - управление виртуальными изолированными сетями.
|
- `VINS` - управление виртуальными изолированными сетями.
|
||||||
|
|
||||||
## Работа с библиотекой
|
## Работа с библиотекой
|
||||||
|
|
||||||
Алгоритм работы с библиотекой выглядит следующим образом:
|
Алгоритм работы с библиотекой выглядит следующим образом:
|
||||||
|
|
||||||
1. Выполнение одного из действий:
|
1. Настройка конфигурации клиента.
|
||||||
- настройка конфигурации клиента;
|
2. Парсинг конфигурации из файла.
|
||||||
- парсинг конфигурации из файла.
|
3. Создание клиента.
|
||||||
2. Создание клиента.
|
4. Создание структуры запроса.
|
||||||
3. Создание структуры запроса.
|
5. Выполнение запроса.
|
||||||
4. Выполнение запроса.
|
|
||||||
|
|
||||||
### Настройка конфигурации клиента
|
### Настройка конфигурации клиента
|
||||||
|
|
||||||
@@ -128,7 +120,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации клиента
|
#### Пример конфигурации клиента
|
||||||
@@ -239,6 +231,7 @@ func main() {
|
|||||||
- `pkg/cloudapi/account` - для `Account`
|
- `pkg/cloudapi/account` - для `Account`
|
||||||
- `pkg/cloudapi/bservice` - для `Basic Service`
|
- `pkg/cloudapi/bservice` - для `Basic Service`
|
||||||
- `pkg/cloudapi/compute` - для `Compute`
|
- `pkg/cloudapi/compute` - для `Compute`
|
||||||
|
- `pkg/cloudapi/computeci` - для `ComputeCI`
|
||||||
- `pkg/cloudapi/disks` - для `Disks`
|
- `pkg/cloudapi/disks` - для `Disks`
|
||||||
- `pkg/cloudapi/extnet` - для `ExtNet`
|
- `pkg/cloudapi/extnet` - для `ExtNet`
|
||||||
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
||||||
@@ -255,27 +248,19 @@ func main() {
|
|||||||
- `pkg/cloudapi/vins` - для `VINS`
|
- `pkg/cloudapi/vins` - для `VINS`
|
||||||
- **cloudbroker**:
|
- **cloudbroker**:
|
||||||
- `pkg/cloudbroker/account` - для `Account`
|
- `pkg/cloudbroker/account` - для `Account`
|
||||||
- `pkg/cloudbroker/apiaccess` - для `APIAccess`
|
|
||||||
- `pkg/cloudbroker/backup` - для `Backup`
|
|
||||||
- `pkg/cloudbroker/compute` - для `Compute`
|
- `pkg/cloudbroker/compute` - для `Compute`
|
||||||
- `pkg/cloudbroker/disks` - для `Disks`
|
- `pkg/cloudbroker/disks` - для `Disks`
|
||||||
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
||||||
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
|
|
||||||
- `pkg/cloudbroker/grid` - для `Grid`
|
- `pkg/cloudbroker/grid` - для `Grid`
|
||||||
- `pkg/cloudbroker/group` - для `Group`
|
|
||||||
- `pkg/cloudbroker/image` - для `Image`
|
- `pkg/cloudbroker/image` - для `Image`
|
||||||
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
||||||
- `pkg/cloudbroker/k8s` - для `K8S`
|
- `pkg/cloudbroker/k8s` - для `K8S`
|
||||||
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
||||||
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
||||||
- `pkg/cloudbroker/lb` - для `LB`
|
- `pkg/cloudbroker/lb` - для `LB`
|
||||||
- `pkg/cloudbroker/pcidevice` - для `PCIDevice`
|
|
||||||
- `pkg/cloudbroker/rg` - для `RG`
|
- `pkg/cloudbroker/rg` - для `RG`
|
||||||
- `pkg/cloudbroker/sep` - для `SEP`
|
- `pkg/cloudbroker/sep` - для `SEP`
|
||||||
- `pkg/cloudbroker/stack` - для `Stack`
|
|
||||||
- `pkg/cloudbroker/tasks` - для `Tasks`
|
- `pkg/cloudbroker/tasks` - для `Tasks`
|
||||||
- `pkg/cloudbroker/user` - для `User`
|
|
||||||
- `pkg/cloudbroker/vgpu` - для `VGPU`
|
|
||||||
- `pkg/cloudbroker/vins` - для `VINS`
|
- `pkg/cloudbroker/vins` - для `VINS`
|
||||||
|
|
||||||
Все поля структуры имеют описание, в которых содержится:
|
Все поля структуры имеют описание, в которых содержится:
|
||||||
@@ -420,6 +405,7 @@ func main() {
|
|||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
- `.BService()` - для работы с `BService`
|
- `.BService()` - для работы с `BService`
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
|
- `.ComputeCI()` - для работы с `ComputeCI`
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
||||||
@@ -438,27 +424,19 @@ func main() {
|
|||||||
Доступные методы для `.CloudBroker()`:
|
Доступные методы для `.CloudBroker()`:
|
||||||
|
|
||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
- `.APIAccess()` - для работы с `APIAccess`
|
|
||||||
- `.Backup()` - для работы с `Backup`
|
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
- `.FLIPGroup()` - для работы с `FLIPGroup`
|
|
||||||
- `.Grid()` - для работы с `Grid`
|
- `.Grid()` - для работы с `Grid`
|
||||||
- `.Group()` - для работы с `Group`
|
|
||||||
- `.Image()` - для работы с `Image`
|
- `.Image()` - для работы с `Image`
|
||||||
- `.K8CI()` - для работы с `K8CI`
|
- `.K8CI()` - для работы с `K8CI`
|
||||||
- `.K8S()` - для работы с `K8S`
|
- `.K8S()` - для работы с `K8S`
|
||||||
- `.KVMPPC()` - для работы с `KVMPPC`
|
- `.KVMPPC()` - для работы с `KVMPPC`
|
||||||
- `.KVMx86()` - для работы с `KVMX86`
|
- `.KVMx86()` - для работы с `KVMX86`
|
||||||
- `.LB()` - для работы с `LB`
|
- `.LB()` - для работы с `LB`
|
||||||
- `.PCIDevice()` - для работы с `PCIDevice`
|
|
||||||
- `.RG()` - для работы с `RG`
|
- `.RG()` - для работы с `RG`
|
||||||
- `.SEP()` - для работы с `SEP`
|
- `.SEP()` - для работы с `SEP`
|
||||||
- `.Stack()` - для работы с `Stack`
|
|
||||||
- `.Tasks()` - для работы с `Tasks`
|
- `.Tasks()` - для работы с `Tasks`
|
||||||
- `.User()` - для работы с `User`
|
|
||||||
- `.VGPU()` - для работы с `VGPU`
|
|
||||||
- `.VINS()` - для работы с `VINS`
|
- `.VINS()` - для работы с `VINS`
|
||||||
|
|
||||||
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
||||||
@@ -470,7 +448,7 @@ func main() {
|
|||||||
4. Обработать результат и ошибки.
|
4. Обработать результат и ошибки.
|
||||||
|
|
||||||
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
||||||
Общий вид конвейера будет выглядеть так:
|
Общий вид вонвейра будет выглядеть так:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
client.<API>.<группа>.<метод>
|
client.<API>.<группа>.<метод>
|
||||||
@@ -727,7 +705,7 @@ func main() {
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации legacy клиента
|
#### Пример конфигурации legacy клиента
|
||||||
|
|||||||
111
client.go
111
client.go
@@ -1,31 +1,24 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
|
|
||||||
"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/internal/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP-client for platform
|
// HTTP-client for platform
|
||||||
type DecortClient struct {
|
type DecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
cfg config.Config
|
|
||||||
expiryTime time.Time
|
|
||||||
mutex *sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сlient builder
|
// Сlient builder
|
||||||
@@ -34,25 +27,9 @@ func New(cfg config.Config) *DecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
var expiryTime time.Time
|
|
||||||
|
|
||||||
if cfg.Token != "" {
|
|
||||||
expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &DecortClient{
|
return &DecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
client: &http.Client{
|
client: client.NewHttpClient(cfg),
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cfg: cfg,
|
|
||||||
expiryTime: expiryTime,
|
|
||||||
mutex: &sync.Mutex{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +56,7 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = dc.getToken(ctx); err != nil {
|
resp, err := dc.client.Do(req)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := dc.do(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -100,77 +73,3 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DecortClient) getToken(ctx context.Context) error {
|
|
||||||
dc.mutex.Lock()
|
|
||||||
defer dc.mutex.Unlock()
|
|
||||||
|
|
||||||
if dc.cfg.Token == "" || time.Now().After(dc.expiryTime) {
|
|
||||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
dc.cfg.SSOURL = strings.TrimSuffix(dc.cfg.SSOURL, "/")
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", dc.cfg.SSOURL+"/v1/oauth/access_token", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
resp, err := dc.client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
token := string(tokenBytes)
|
|
||||||
|
|
||||||
dc.cfg.Token = token
|
|
||||||
dc.expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
|
|
||||||
buf, _ := io.ReadAll(req.Body)
|
|
||||||
|
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
resp, err := dc.client.Do(req)
|
|
||||||
req.Close = true
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
if strings.Contains(err.Error(), "connection reset by peer") || errors.Is(err, io.EOF) {
|
|
||||||
for i := uint64(0); i < dc.cfg.Retries; i++ {
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
resp, err = dc.client.Do(req)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "connection reset by peer") || errors.Is(err, io.EOF) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
||||||
}
|
|
||||||
|
|||||||
42
internal/client/http-client.go
Normal file
42
internal/client/http-client.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewHttpClient(cfg config.Config) *http.Client {
|
||||||
|
|
||||||
|
transCfg := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
//nolint:gosec
|
||||||
|
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var expiredTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiredTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &transport{
|
||||||
|
base: transCfg,
|
||||||
|
retries: cfg.Retries,
|
||||||
|
clientID: cfg.AppID,
|
||||||
|
clientSecret: cfg.AppSecret,
|
||||||
|
ssoURL: cfg.SSOURL,
|
||||||
|
token: cfg.Token,
|
||||||
|
expiryTime: expiredTime,
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
|
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeout: cfg.Timeout.Get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
42
internal/client/legacy-http-client.go
Normal file
42
internal/client/legacy-http-client.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewLegacyHttpClient creates legacy HTTP Client
|
||||||
|
func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
||||||
|
transCfg := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
//nolint:gosec
|
||||||
|
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var expiredTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiredTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &transportLegacy{
|
||||||
|
base: transCfg,
|
||||||
|
username: url.QueryEscape(cfg.Username),
|
||||||
|
password: url.QueryEscape(cfg.Password),
|
||||||
|
retries: cfg.Retries,
|
||||||
|
token: cfg.Token,
|
||||||
|
decortURL: cfg.DecortURL,
|
||||||
|
expiryTime: expiredTime,
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
|
},
|
||||||
|
|
||||||
|
Timeout: cfg.Timeout.Get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
78
internal/client/legacy-transport.go
Normal file
78
internal/client/legacy-transport.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type transportLegacy struct {
|
||||||
|
base http.RoundTripper
|
||||||
|
username string
|
||||||
|
password string
|
||||||
|
retries uint64
|
||||||
|
token string
|
||||||
|
decortURL string
|
||||||
|
mutex *sync.Mutex
|
||||||
|
expiryTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||||
|
if t.token == "" || time.Now().After(t.expiryTime) {
|
||||||
|
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
|
||||||
|
bodyReader := strings.NewReader(body)
|
||||||
|
|
||||||
|
req, _ := http.NewRequestWithContext(request.Context(), "POST", t.decortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
resp, err := t.base.RoundTrip(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("unable to get token: %s", tokenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
token := string(tokenBytes)
|
||||||
|
t.token = token
|
||||||
|
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenValue := fmt.Sprintf("&authkey=%s", t.token)
|
||||||
|
tokenReader := strings.NewReader(tokenValue)
|
||||||
|
|
||||||
|
newBody := io.MultiReader(request.Body, tokenReader)
|
||||||
|
|
||||||
|
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), newBody)
|
||||||
|
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
var resp *http.Response
|
||||||
|
var err error
|
||||||
|
for i := uint64(0); i < t.retries; i++ {
|
||||||
|
t.mutex.Lock()
|
||||||
|
resp, err = t.base.RoundTrip(req)
|
||||||
|
t.mutex.Unlock()
|
||||||
|
if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
74
internal/client/transport.go
Normal file
74
internal/client/transport.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type transport struct {
|
||||||
|
base http.RoundTripper
|
||||||
|
retries uint64
|
||||||
|
clientID string
|
||||||
|
clientSecret string
|
||||||
|
token string
|
||||||
|
ssoURL string
|
||||||
|
expiryTime time.Time
|
||||||
|
mutex *sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
if t.token == "" || time.Now().After(t.expiryTime) {
|
||||||
|
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
|
||||||
|
bodyReader := strings.NewReader(body)
|
||||||
|
|
||||||
|
t.ssoURL = strings.TrimSuffix(t.ssoURL, "/")
|
||||||
|
|
||||||
|
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.ssoURL+"/v1/oauth/access_token", bodyReader)
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
resp, err := t.base.RoundTrip(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot get token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
token := string(tokenBytes)
|
||||||
|
|
||||||
|
t.token = token
|
||||||
|
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Add("Authorization", "bearer "+t.token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
var resp *http.Response
|
||||||
|
var err error
|
||||||
|
for i := uint64(0); i < t.retries; i++ {
|
||||||
|
t.mutex.Lock()
|
||||||
|
resp, err = t.base.RoundTrip(req)
|
||||||
|
t.mutex.Unlock()
|
||||||
|
if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
|
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
116
legacy-client.go
116
legacy-client.go
@@ -1,31 +1,23 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"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/internal/client"
|
||||||
"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/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Legacy HTTP-client for platform
|
// Legacy HTTP-client for platform
|
||||||
type LegacyDecortClient struct {
|
type LegacyDecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
cfg config.LegacyConfig
|
|
||||||
expiryTime time.Time
|
|
||||||
mutex *sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy client builder
|
// Legacy client builder
|
||||||
@@ -34,25 +26,9 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
var expiryTime time.Time
|
|
||||||
|
|
||||||
if cfg.Token != "" {
|
|
||||||
expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &LegacyDecortClient{
|
return &LegacyDecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
client: &http.Client{
|
client: client.NewLegacyHttpClient(cfg),
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cfg: cfg,
|
|
||||||
expiryTime: expiryTime,
|
|
||||||
mutex: &sync.Mutex{},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,18 +49,13 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ldc.getToken(ctx); err != nil {
|
body := strings.NewReader(values.Encode())
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
body := strings.NewReader(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ldc.do(req)
|
resp, err := ldc.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -101,78 +72,3 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
|
|||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
|
|
||||||
ldc.mutex.Lock()
|
|
||||||
defer ldc.mutex.Unlock()
|
|
||||||
|
|
||||||
if ldc.cfg.Token == "" || time.Now().After(ldc.expiryTime) {
|
|
||||||
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password))
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", ldc.cfg.DecortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
resp, err := ldc.client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("unable to get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
token := string(tokenBytes)
|
|
||||||
ldc.cfg.Token = token
|
|
||||||
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
|
|
||||||
// var resp *http.Response
|
|
||||||
// var err error
|
|
||||||
buf, _ := io.ReadAll(req.Body)
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
req.Close = true
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
if strings.Contains(err.Error(), "connection reset by peer") || errors.Is(err, io.EOF) {
|
|
||||||
for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
resp, err = ldc.client.Do(req)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "connection reset by peer") || errors.Is(err, io.EOF) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
|
||||||
// }
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -106,6 +106,10 @@ type CreateRequest struct {
|
|||||||
// 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"`
|
||||||
|
|
||||||
|
//Use only selected ExtNet for infrastructure connections
|
||||||
|
// Required: false
|
||||||
|
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package lb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -20,16 +21,16 @@ 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"`
|
||||||
|
|
||||||
// Start now Load balancer
|
// Start now Load balancer
|
||||||
// Required: true
|
// Required: false
|
||||||
Start bool `url:"start" json:"start" validate:"required"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Text description of this load balancer
|
// Text description of this load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -45,6 +46,10 @@ func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.ExtNetID == 0 && req.VINSID == 0 {
|
||||||
|
return "", errors.New ("vinsId and extNetId cannot be both in the value 0")
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/lb/create"
|
url := "/cloudapi/lb/create"
|
||||||
|
|
||||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type CreateInRGRequest struct {
|
|||||||
|
|
||||||
// Number of pre created reservations
|
// Number of pre created reservations
|
||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInRG creates VINS in resource group level
|
// CreateInRG creates VINS in resource group level
|
||||||
|
|||||||
@@ -397,11 +397,9 @@ type NATConfig struct {
|
|||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
|
|
||||||
// List NAT rules
|
// List NAT rules
|
||||||
Rules ListNATRulesConfig `json:"rules"`
|
Rules ListNATRules `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListNATRulesConfig []ItemNATRule
|
|
||||||
|
|
||||||
// Main information about GW
|
// Main information about GW
|
||||||
type RecordGW struct {
|
type RecordGW struct {
|
||||||
// CKey
|
// CKey
|
||||||
@@ -572,6 +570,9 @@ type RecordVINS struct {
|
|||||||
// Main information about VNF device
|
// Main information about VNF device
|
||||||
VNFDev RecordVNFDev `json:"VNFDev"`
|
VNFDev RecordVNFDev `json:"VNFDev"`
|
||||||
|
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
// Account ID
|
// Account ID
|
||||||
AccountID uint64 `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
@@ -581,24 +582,12 @@ type RecordVINS struct {
|
|||||||
// List of VINS computes
|
// List of VINS computes
|
||||||
Computes ListVINSComputes `json:"computes"`
|
Computes ListVINSComputes `json:"computes"`
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Default GW
|
// Default GW
|
||||||
DefaultGW string `json:"defaultGW"`
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
// Default QOS
|
// Default QOS
|
||||||
DefaultQOS QOS `json:"defaultQos"`
|
DefaultQOS QOS `json:"defaultQos"`
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package k8ci
|
|||||||
// FilterByID returns ListK8CI with specified ID.
|
// FilterByID returns ListK8CI with specified ID.
|
||||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||||
predicate := func(ikc ItemK8CI) bool {
|
predicate := func(ikc ItemK8CI) bool {
|
||||||
return ikc.RecordK8CIList.ID == id
|
return ikc.RecordK8CI.ID == id
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc.FilterFunc(predicate)
|
return lkc.FilterFunc(predicate)
|
||||||
@@ -12,7 +12,7 @@ func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
|||||||
// FilterByName returns ListK8CI with specified Name.
|
// FilterByName returns ListK8CI with specified Name.
|
||||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||||
predicate := func(ikc ItemK8CI) bool {
|
predicate := func(ikc ItemK8CI) bool {
|
||||||
return ikc.RecordK8CIList.Name == name
|
return ikc.RecordK8CI.Name == name
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc.FilterFunc(predicate)
|
return lkc.FilterFunc(predicate)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ var k8ciItems = ListK8CI{
|
|||||||
Data: []ItemK8CI{
|
Data: []ItemK8CI{
|
||||||
{
|
{
|
||||||
CreatedTime: 123902139,
|
CreatedTime: 123902139,
|
||||||
RecordK8CIList: RecordK8CIList{
|
RecordK8CI: RecordK8CI{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 1,
|
GUID: 1,
|
||||||
@@ -17,7 +17,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 2,
|
MaxMasterCount: 2,
|
||||||
MaxWorkerCount: 3,
|
MaxWorkerCount: 3,
|
||||||
Name: "purple_snake",
|
Name: "purple_snake",
|
||||||
SharedWith: []uint64{},
|
SharedWith: []interface{}{},
|
||||||
Status: "ENABLED",
|
Status: "ENABLED",
|
||||||
Version: "1",
|
Version: "1",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
@@ -26,7 +26,7 @@ var k8ciItems = ListK8CI{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CreatedTime: 123902232,
|
CreatedTime: 123902232,
|
||||||
RecordK8CIList: RecordK8CIList{
|
RecordK8CI: RecordK8CI{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 2,
|
GUID: 2,
|
||||||
@@ -37,7 +37,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 3,
|
MaxMasterCount: 3,
|
||||||
MaxWorkerCount: 5,
|
MaxWorkerCount: 5,
|
||||||
Name: "green_giant",
|
Name: "green_giant",
|
||||||
SharedWith: []uint64{},
|
SharedWith: []interface{}{},
|
||||||
Status: "DISABLED",
|
Status: "DISABLED",
|
||||||
Version: "2",
|
Version: "2",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
@@ -46,7 +46,7 @@ var k8ciItems = ListK8CI{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CreatedTime: 123902335,
|
CreatedTime: 123902335,
|
||||||
RecordK8CIList: RecordK8CIList{
|
RecordK8CI: RecordK8CI{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 3,
|
GUID: 3,
|
||||||
@@ -57,7 +57,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 5,
|
MaxMasterCount: 5,
|
||||||
MaxWorkerCount: 9,
|
MaxWorkerCount: 9,
|
||||||
Name: "magenta_cloud",
|
Name: "magenta_cloud",
|
||||||
SharedWith: []uint64{},
|
SharedWith: []interface{}{},
|
||||||
Status: "ENABLED",
|
Status: "ENABLED",
|
||||||
Version: "3",
|
Version: "3",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package k8ci
|
package k8ci
|
||||||
|
|
||||||
// Main information about K8CI in List
|
// Main information about K8CI
|
||||||
type ItemK8CI struct {
|
type ItemK8CI struct {
|
||||||
// Created time
|
// Created time
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
// Detailed information about K8CI
|
// Detailed information about K8CI
|
||||||
RecordK8CIList
|
RecordK8CI
|
||||||
}
|
}
|
||||||
|
|
||||||
// List K8CI
|
// List K8CI
|
||||||
@@ -17,55 +17,7 @@ type ListK8CI struct {
|
|||||||
EntryCount uint64 `json:"entryCount"`
|
EntryCount uint64 `json:"entryCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detailed information about K8CI in List
|
// Detailed information about K8CI
|
||||||
type RecordK8CIList struct {
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// Grid ID
|
|
||||||
GID uint64 `json:"gid"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Load balancer image ID
|
|
||||||
LBImageID uint64 `json:"lbImageId"`
|
|
||||||
|
|
||||||
// Master driver
|
|
||||||
MasterDriver string `json:"masterDriver"`
|
|
||||||
|
|
||||||
// Master image ID
|
|
||||||
MasterImageID uint64 `json:"masterImageId"`
|
|
||||||
|
|
||||||
// Max master count
|
|
||||||
MaxMasterCount uint64 `json:"maxMasterCount"`
|
|
||||||
|
|
||||||
// Max worker count
|
|
||||||
MaxWorkerCount uint64 `json:"maxWorkerCount"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Shared with
|
|
||||||
SharedWith []uint64 `json:"sharedWith"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Version
|
|
||||||
Version string `json:"version"`
|
|
||||||
|
|
||||||
// Worker driver
|
|
||||||
WorkerDriver string `json:"workerDriver"`
|
|
||||||
|
|
||||||
// Worker image ID
|
|
||||||
WorkerImageID uint64 `json:"workerImageId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detailed information about K8CI
|
|
||||||
type RecordK8CI struct {
|
type RecordK8CI struct {
|
||||||
// Description
|
// Description
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
@@ -100,11 +52,8 @@ type RecordK8CI struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
//NetworkPlugins
|
|
||||||
NetworkPlugins []string `json:"networkPlugins"`
|
|
||||||
|
|
||||||
// Shared with
|
// Shared with
|
||||||
SharedWith []uint64 `json:"sharedWith"`
|
SharedWith []interface{} `json:"sharedWith"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|||||||
@@ -2,24 +2,12 @@ package vins
|
|||||||
|
|
||||||
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 VINS in account
|
// Request struct for create VINS in account
|
||||||
type CreateInAccountRequest struct {
|
type CreateInAccountRequest struct {
|
||||||
// VINS name
|
// VINS name
|
||||||
@@ -46,20 +34,11 @@ type CreateInAccountRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,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"`
|
|
||||||
|
|
||||||
// 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateRequestInAcc struct {
|
|
||||||
CreateInAccountRequest
|
|
||||||
Routes []string `url:"routes,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateInAccount creates VINS in account level
|
// CreateInAccount creates VINS in account level
|
||||||
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -69,31 +48,9 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 := wrapperCreateRequestInAcc{
|
|
||||||
CreateInAccountRequest: req,
|
|
||||||
Routes: routes,
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudbroker/vins/createInAccount"
|
url := "/cloudbroker/vins/createInAccount"
|
||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package vins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -37,22 +36,13 @@ type CreateInRGRequest struct {
|
|||||||
|
|
||||||
// Number of pre created reservations
|
// Number of pre created reservations
|
||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,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"`
|
|
||||||
|
|
||||||
// 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateRequestInRG struct {
|
|
||||||
CreateInRGRequest
|
|
||||||
Routes []string `url:"routes,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateInRG creates VINS in resource group level
|
// CreateInRG creates VINS in resource group level
|
||||||
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
|
func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -61,31 +51,10 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
|
|||||||
return 0, validators.ValidationError(validationError)
|
return 0, validators.ValidationError(validationError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 := wrapperCreateRequestInRG{
|
|
||||||
CreateInRGRequest: req,
|
|
||||||
Routes: routes,
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudbroker/vins/createInRG"
|
url := "/cloudbroker/vins/createInRG"
|
||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ type NATConfig struct {
|
|||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
Rules []ItemNATRule `json:"rules"`
|
Rules []interface{} `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main information about NAT
|
// Main information about NAT
|
||||||
@@ -357,7 +357,7 @@ type RecordNAT struct {
|
|||||||
InfoVNF
|
InfoVNF
|
||||||
}
|
}
|
||||||
|
|
||||||
// DHCP/GW/NAT details
|
// NAT/GW/NAT details
|
||||||
type InfoVNF struct {
|
type InfoVNF struct {
|
||||||
// CKey
|
// CKey
|
||||||
CKey string `json:"_ckey"`
|
CKey string `json:"_ckey"`
|
||||||
@@ -368,6 +368,9 @@ type InfoVNF struct {
|
|||||||
// Account ID
|
// Account ID
|
||||||
AccountID uint64 `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
// Config
|
||||||
|
Config NATConfig `json:"config"`
|
||||||
|
|
||||||
// CreatedTime
|
// CreatedTime
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
@@ -398,9 +401,6 @@ type InfoVNF struct {
|
|||||||
// Pure virtual
|
// Pure virtual
|
||||||
PureVirtual bool `json:"pureVirtual"`
|
PureVirtual bool `json:"pureVirtual"`
|
||||||
|
|
||||||
// Routes
|
|
||||||
Routes ListRoutes `json:"routes"`
|
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
@@ -411,28 +411,6 @@ type InfoVNF struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListRoutes []ItemRoutes
|
|
||||||
|
|
||||||
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 uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
//Destination network mask in 255.255.255.255 format
|
|
||||||
Netmask string `json:"netmask"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// main information about VNF
|
// main information about VNF
|
||||||
type RecordVNFs struct {
|
type RecordVNFs struct {
|
||||||
// DHCP
|
// DHCP
|
||||||
@@ -450,6 +428,12 @@ type RecordVINS struct {
|
|||||||
// VNF device
|
// VNF device
|
||||||
VNFDev VNFDev `json:"VNFDev"`
|
VNFDev VNFDev `json:"VNFDev"`
|
||||||
|
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
// Account ID
|
// Account ID
|
||||||
AccountID uint64 `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user