Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9e4ae6afe | |||
| 2a1593f45f | |||
| 190f24dac1 | |||
| 256dba5134 | |||
| b7137683ab | |||
| 10e3e19892 | |||
| aaf0857ff0 | |||
| 7d6cda7119 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
cmd/
|
cmd/
|
||||||
|
.idea/
|
||||||
43
CHANGELOG.md
43
CHANGELOG.md
@@ -1,39 +1,4 @@
|
|||||||
## Version 1.3.0
|
## Version 1.4.4
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
- Added "Timeout" param to Config/LegacyConfig that allows configuring HTTP client timeout
|
||||||
- Created CloudAPI/CloudBroker filtering, sorting and serialization functions for List requests.
|
|
||||||
- Every handler with present List request has available FilterBy functions. Filtering by ID, Name is common for each handler.
|
|
||||||
- In case user needs to filter response by uncommon field FilterFunc with user-specified predicate is also available.
|
|
||||||
- CloudAPI/CloudBroker computes, disks and lb also have specific Filter methods predefined, to name a few:
|
|
||||||
- computes:
|
|
||||||
- FilterByK8SID, used to filter computes used by specified k8s cluster;
|
|
||||||
- FilterByK8SMasters, FilterByK8SWorkers, used to filter master/workers nodes. Best used after FilterByK8SID call;
|
|
||||||
- FilterByLBID, used to filter computes used by specified load balancer;
|
|
||||||
|
|
||||||
- disks:
|
|
||||||
- FilterByK8SID, used to filter disks attached to computes inside specified k8s cluster;
|
|
||||||
- FilterByLBID, used to filter disks attached to computes inside specified load balancer;
|
|
||||||
|
|
||||||
- lb:
|
|
||||||
- FilterByK8SID, used to filter load balancers used by specified k8s cluster;
|
|
||||||
|
|
||||||
- Reinvented request validation using go-validator. Made easier to manipulate and add on to.
|
|
||||||
- Request/Config validation now uses tags instead of hard-coded validation functions;
|
|
||||||
|
|
||||||
- Added ability to parse client configuration from JSON or YAML formatted files.
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
- Fixed SSO_URL trailing slash possibly breaking authentication process.
|
|
||||||
- Fixed cloudbroker/vins/nat_rule_add request model types.
|
|
||||||
- Fixed cloudbroker/grid DiskSize field type
|
|
||||||
- Fixed TasksResult, InfoResult in cloudbroker/cloudapi/tasks/models JSON unmarshalling.
|
|
||||||
|
|
||||||
### Tests
|
|
||||||
|
|
||||||
- Covered CloudAPI/CloudBroker filters with unit tests.
|
|
||||||
|
|
||||||
### Other
|
|
||||||
|
|
||||||
- Updated module to new repository
|
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -8,6 +8,7 @@ Decort SDK - это библиотека, написанная на языке G
|
|||||||
- Версия 1.1.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.1.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
- Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.2.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
|
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
||||||
|
|
||||||
## Оглавление
|
## Оглавление
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -126,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
import (
|
import (
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
// Настройка конфигурации
|
// Настройка конфигурации
|
||||||
cfg := config.Config{
|
cfg := config.Config{
|
||||||
@@ -135,6 +138,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -164,6 +169,7 @@ func main() {
|
|||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": false
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -176,6 +182,7 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -203,6 +210,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
}
|
}
|
||||||
@@ -646,6 +655,8 @@ func main() {
|
|||||||
DecortURL: "<DECORT_URL>",
|
DecortURL: "<DECORT_URL>",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
@@ -692,6 +703,7 @@ func main() {
|
|||||||
| Password | string | Да | пароль legacy пользователя |
|
| Password | string | Да | пароль legacy пользователя |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -710,6 +722,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -738,6 +752,7 @@ func main() {
|
|||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": true
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -748,6 +763,7 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
```
|
```
|
||||||
### Создание legacy клиента
|
### Создание legacy клиента
|
||||||
@@ -773,6 +789,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
legacyClient := decort.NewLegacy(cfg)
|
legacyClient := decort.NewLegacy(cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -44,6 +45,15 @@ type Config struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
// HTTP client timeout, unlimited if left empty
|
||||||
|
// Required: false
|
||||||
|
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimeout is used to set HTTP client timeout.
|
||||||
|
func (c *Config) SetTimeout(dur time.Duration) {
|
||||||
|
c.Timeout = Duration(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -38,6 +39,15 @@ type LegacyConfig struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
// HTTP client timeout, unlimited if left empty
|
||||||
|
// Required: false
|
||||||
|
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimeout is used to set HTTP client timeout.
|
||||||
|
func (c *LegacyConfig) SetTimeout(dur time.Duration) {
|
||||||
|
c.Timeout = Duration(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
||||||
|
|||||||
50
config/timeouts.go
Normal file
50
config/timeouts.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Duration is a wrapper around time.Duration (used for better user experience)
|
||||||
|
type Duration time.Duration
|
||||||
|
|
||||||
|
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var v interface{}
|
||||||
|
if err := unmarshal(&v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch value := v.(type) {
|
||||||
|
case string:
|
||||||
|
tmp, err := time.ParseDuration(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = Duration(tmp)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Invalid duration %v", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||||
|
var v interface{}
|
||||||
|
if err := json.Unmarshal(b, &v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch value := v.(type) {
|
||||||
|
case string:
|
||||||
|
tmp, err := time.ParseDuration(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = Duration(tmp)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Invalid duration %v", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Duration) Get() time.Duration {
|
||||||
|
return time.Duration(*d)
|
||||||
|
}
|
||||||
3
go.mod
3
go.mod
@@ -5,14 +5,15 @@ go 1.20
|
|||||||
require (
|
require (
|
||||||
github.com/go-playground/validator/v10 v10.11.2
|
github.com/go-playground/validator/v10 v10.11.2
|
||||||
github.com/google/go-querystring v1.1.0
|
github.com/google/go-querystring v1.1.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
golang.org/x/crypto v0.5.0 // indirect
|
golang.org/x/crypto v0.5.0 // indirect
|
||||||
golang.org/x/sys v0.4.0 // indirect
|
golang.org/x/sys v0.4.0 // indirect
|
||||||
golang.org/x/text v0.6.0 // indirect
|
golang.org/x/text v0.6.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -1,3 +1,4 @@
|
|||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
@@ -11,10 +12,14 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
|||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||||
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
@@ -26,6 +31,7 @@ golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
|
|||||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -35,6 +35,6 @@ func NewHttpClient(cfg config.Config) *http.Client {
|
|||||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
|||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package validators
|
package validators
|
||||||
|
|
||||||
import "github.com/go-playground/validator/v10"
|
import (
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
// protoValidator is used to validate Proto fields.
|
// protoValidator is used to validate Proto fields.
|
||||||
func protoValidator(fe validator.FieldLevel) bool {
|
func protoValidator(fe validator.FieldLevel) bool {
|
||||||
@@ -203,3 +207,52 @@ func sepFieldTypeValidator(fe validator.FieldLevel) bool {
|
|||||||
|
|
||||||
return StringInSlice(fieldValue, sepFieldTypeValues)
|
return StringInSlice(fieldValue, sepFieldTypeValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hwPathValidator is used to validate HWPath field.
|
||||||
|
func hwPathValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldValue := fe.Field().String()
|
||||||
|
|
||||||
|
ok, _ := regexp.MatchString(`^\b[0-9a-f]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}.\d{1}$`, fieldValue)
|
||||||
|
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// networkPluginValidator is used to validate NetworkPlugin field
|
||||||
|
func networkPluginValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldValue := fe.Field().String()
|
||||||
|
fieldValue = strings.ToLower(fieldValue)
|
||||||
|
|
||||||
|
return StringInSlice(fieldValue, networkPluginValues)
|
||||||
|
}
|
||||||
|
|
||||||
|
// networkPluginsValidator is used to validate NetworkPlugins field
|
||||||
|
func networkPluginsValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldSlice, ok := fe.Field().Interface().([]string)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range fieldSlice {
|
||||||
|
item = strings.ToLower(item)
|
||||||
|
|
||||||
|
if !StringInSlice(item, networkPluginValues) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func interfaceStateValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldValue := fe.Field().String()
|
||||||
|
fieldValue = strings.ToLower(fieldValue)
|
||||||
|
|
||||||
|
return StringInSlice(fieldValue, interfaceStateValues)
|
||||||
|
}
|
||||||
|
|
||||||
|
func strictLooseValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldValue := fe.Field().String()
|
||||||
|
fieldValue = strings.ToLower(fieldValue)
|
||||||
|
|
||||||
|
return StringInSlice(fieldValue, strictLooseValues)
|
||||||
|
}
|
||||||
|
|||||||
@@ -187,6 +187,36 @@ func errorMessage(fe validator.FieldError) string {
|
|||||||
fe.Field(),
|
fe.Field(),
|
||||||
joinValues(sepFieldTypeValues))
|
joinValues(sepFieldTypeValues))
|
||||||
|
|
||||||
|
// HWPath Validators
|
||||||
|
case "hwPath":
|
||||||
|
return fmt.Sprintf("%s %s must be in format 0000:1f:2b.0",
|
||||||
|
prefix,
|
||||||
|
fe.Field())
|
||||||
|
|
||||||
|
// Network plugin Validators
|
||||||
|
case "networkPlugin":
|
||||||
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
prefix,
|
||||||
|
fe.Field(),
|
||||||
|
joinValues(networkPluginValues))
|
||||||
|
|
||||||
|
case "networkPlugins":
|
||||||
|
return fmt.Sprintf("%s %s must contain only the following: %s",
|
||||||
|
prefix,
|
||||||
|
fe.Field(),
|
||||||
|
joinValues(networkPluginValues))
|
||||||
|
|
||||||
|
case "strict_loose":
|
||||||
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
prefix,
|
||||||
|
fe.Field(),
|
||||||
|
joinValues(strictLooseValues))
|
||||||
|
|
||||||
|
case "interfaceState":
|
||||||
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
prefix,
|
||||||
|
fe.Field(),
|
||||||
|
joinValues(interfaceStateValues))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fe.Error()
|
return fe.Error()
|
||||||
|
|||||||
@@ -7,29 +7,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
instance *DecortValidator
|
decortValidator = validator.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
type DecortValidator struct {
|
|
||||||
decortValidator *validator.Validate
|
|
||||||
}
|
|
||||||
|
|
||||||
// getDecortValidator returns singleton instance of DecortValidator.
|
// getDecortValidator returns singleton instance of DecortValidator.
|
||||||
func getDecortValidator() *validator.Validate {
|
func getDecortValidator() *validator.Validate {
|
||||||
if instance == nil {
|
once.Do(func() {
|
||||||
once.Do(func() {
|
err := registerAllValidators(decortValidator)
|
||||||
instance = new(DecortValidator)
|
if err != nil {
|
||||||
instance.decortValidator = validator.New()
|
panic(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
err := registerAllValidators(instance.decortValidator)
|
return decortValidator
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance.decortValidator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerAllValidators registers all custom validators in DecortValidator.
|
// registerAllValidators registers all custom validators in DecortValidator.
|
||||||
@@ -159,5 +150,30 @@ func registerAllValidators(validate *validator.Validate) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("hwPath", hwPathValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("networkPlugin", networkPluginValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("networkPlugins", networkPluginsValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("strict_loose", strictLooseValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("interfaceState", interfaceStateValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,10 @@ var (
|
|||||||
imageArchitectureValues = []string{"X86_64", "PPC64_LE"}
|
imageArchitectureValues = []string{"X86_64", "PPC64_LE"}
|
||||||
|
|
||||||
sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"}
|
sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"}
|
||||||
|
|
||||||
|
networkPluginValues = []string{"flannel", "weawenet", "calico"}
|
||||||
|
|
||||||
|
strictLooseValues = []string{"strict", "loose"}
|
||||||
|
|
||||||
|
interfaceStateValues = []string{"on", "off"}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -158,6 +158,12 @@ type RecordAccount struct {
|
|||||||
// Computes
|
// Computes
|
||||||
Computes Computes `json:"computes"`
|
Computes Computes `json:"computes"`
|
||||||
|
|
||||||
|
// CPU allocation parameter
|
||||||
|
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
@@ -165,7 +171,7 @@ type RecordAccount struct {
|
|||||||
CreatedTime uint64 `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
// Deactivation time
|
// Deactivation time
|
||||||
DeactivationTime uint64 `json:"deactivationTime"`
|
DeactivationTime float64 `json:"deactivationTime"`
|
||||||
|
|
||||||
// Deleted by
|
// Deleted by
|
||||||
DeletedBy string `json:"deletedBy"`
|
DeletedBy string `json:"deletedBy"`
|
||||||
@@ -192,7 +198,7 @@ type RecordAccount struct {
|
|||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
// Resource types
|
// Resource types
|
||||||
ResourceTypes []string `json:"resourceTypes"`
|
ResTypes []string `json:"resourceTypes"`
|
||||||
|
|
||||||
// Send access emails
|
// Send access emails
|
||||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package account
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,15 +24,10 @@ func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error)
|
|||||||
|
|
||||||
url := "/cloudapi/account/restore"
|
url := "/cloudapi/account/restore"
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
return true, nil
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,31 +20,31 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// Max size of memory in MB
|
// Max size of memory in MB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||||
|
|
||||||
// Max size of aggregated vdisks in GB
|
// Max size of aggregated vdisks in GB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||||
|
|
||||||
// Max number of CPU cores
|
// Max number of CPU cores
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||||
|
|
||||||
// Max sent/received network transfer peering
|
// Max sent/received network transfer peering
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
// Max number of assigned public IPs
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
GPUUnits uint64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates an account name and resource types and limits
|
// Update updates an account name and resource types and limits
|
||||||
|
|||||||
@@ -35,11 +35,8 @@ type RecordBasicService struct {
|
|||||||
// Grid ID
|
// Grid ID
|
||||||
GID uint64 `json:"gid"`
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
// List of Service Compute Group IDs
|
// List of Service Compute Groups
|
||||||
Groups []uint64 `json:"groups"`
|
Groups ListGroups `json:"groups"`
|
||||||
|
|
||||||
// List of compute groups by name
|
|
||||||
GroupsName []string `json:"groupsName"`
|
|
||||||
|
|
||||||
// GUID
|
// GUID
|
||||||
GUID uint64 `json:"guid"`
|
GUID uint64 `json:"guid"`
|
||||||
@@ -95,6 +92,12 @@ type RecordBasicService struct {
|
|||||||
|
|
||||||
// Main information about Compute
|
// Main information about Compute
|
||||||
type ItemCompute struct {
|
type ItemCompute struct {
|
||||||
|
// Account ID
|
||||||
|
AccountID uint64
|
||||||
|
|
||||||
|
// Architecture
|
||||||
|
Architecture string `json:"arch"`
|
||||||
|
|
||||||
// Compute group ID
|
// Compute group ID
|
||||||
CompGroupID uint64 `json:"compgroupId"`
|
CompGroupID uint64 `json:"compgroupId"`
|
||||||
|
|
||||||
@@ -109,11 +112,47 @@ type ItemCompute struct {
|
|||||||
|
|
||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Resource group ID
|
||||||
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
// StackID
|
||||||
|
StackID uint64 `json:"stackId"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Tech status
|
||||||
|
TechStatus string `json:"techStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of Computes
|
// List of Computes
|
||||||
type ListComputes []ItemCompute
|
type ListComputes []ItemCompute
|
||||||
|
|
||||||
|
// Main information about Group
|
||||||
|
type ItemGroup struct {
|
||||||
|
// Amount of computes
|
||||||
|
Computes uint64 `json:"computes"`
|
||||||
|
|
||||||
|
// Consistency
|
||||||
|
Consistency bool `json:"consistency"`
|
||||||
|
|
||||||
|
// Group ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Group name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// TechStatus
|
||||||
|
TechStatus string `json:"techStatus"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of Groups
|
||||||
|
type ListGroups []ItemGroup
|
||||||
|
|
||||||
// Main information about Snapshot
|
// Main information about Snapshot
|
||||||
type ItemSnapshot struct {
|
type ItemSnapshot struct {
|
||||||
// GUID
|
// GUID
|
||||||
|
|||||||
41
pkg/cloudapi/compute/boot_order_get.go
Normal file
41
pkg/cloudapi/compute/boot_order_get.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting boot order
|
||||||
|
type BootOrderGetRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BootOrderGet gets actual compute boot order information
|
||||||
|
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/bootOrderGet"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
orders := make([]string, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &orders)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return orders, nil
|
||||||
|
}
|
||||||
49
pkg/cloudapi/compute/boot_order_set.go
Normal file
49
pkg/cloudapi/compute/boot_order_set.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for setting boot order
|
||||||
|
type BootOrderSetRequest struct {
|
||||||
|
// ID of compute instance
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of boot devices
|
||||||
|
// Should be one of:
|
||||||
|
// - cdrom
|
||||||
|
// - network
|
||||||
|
// - hd
|
||||||
|
// Required: true
|
||||||
|
Order []string `url:"order" json:"order" validate:"min=1,computeOrder"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BootOrderSet sets compute boot order
|
||||||
|
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/bootOrderSet"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
orders := make([]string, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &orders)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return orders, nil
|
||||||
|
}
|
||||||
47
pkg/cloudapi/compute/change_link_state.go
Normal file
47
pkg/cloudapi/compute/change_link_state.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for changing link state
|
||||||
|
type ChangeLinkStateRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Interface name or MAC address
|
||||||
|
// Required: true
|
||||||
|
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||||
|
|
||||||
|
// Interface state
|
||||||
|
// Must be either "on" or "off"
|
||||||
|
// Required: true
|
||||||
|
State string `url:"state" json:"state" validate:"required,interfaceState"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeLinkState changes the status link virtual of compute
|
||||||
|
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/compute/changeLinkState"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -22,6 +22,11 @@ type DiskAddRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||||
|
|
||||||
|
// Storage endpoint provider ID
|
||||||
|
// By default the same with boot disk
|
||||||
|
// Required: false
|
||||||
|
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
// Type of the disk
|
// Type of the disk
|
||||||
// Should be one of:
|
// Should be one of:
|
||||||
// - D
|
// - D
|
||||||
@@ -29,11 +34,6 @@ type DiskAddRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
||||||
|
|
||||||
// Storage endpoint provider ID
|
|
||||||
// By default the same with boot disk
|
|
||||||
// Required: false
|
|
||||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
|
||||||
|
|
||||||
// Pool name
|
// Pool name
|
||||||
// By default will be chosen automatically
|
// By default will be chosen automatically
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ type DiskAttachRequest struct {
|
|||||||
// ID of the disk to attach
|
// ID of the disk to attach
|
||||||
// Required: true
|
// Required: true
|
||||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||||
|
|
||||||
|
// Type of the disk B;D
|
||||||
|
// Required: false
|
||||||
|
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiskAttach attach disk to compute
|
// DiskAttach attach disk to compute
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import "testing"
|
|||||||
|
|
||||||
var computes = ListComputes{
|
var computes = ListComputes{
|
||||||
ItemCompute{
|
ItemCompute{
|
||||||
ACL: []interface{}{},
|
ACL: ListACL{},
|
||||||
AccountID: 132847,
|
AccountID: 132847,
|
||||||
AccountName: "std_2",
|
AccountName: "std_2",
|
||||||
AffinityLabel: "",
|
AffinityLabel: "",
|
||||||
@@ -85,7 +85,7 @@ var computes = ListComputes{
|
|||||||
VirtualImageID: 0,
|
VirtualImageID: 0,
|
||||||
},
|
},
|
||||||
ItemCompute{
|
ItemCompute{
|
||||||
ACL: []interface{}{},
|
ACL: ListACL{},
|
||||||
AccountID: 132848,
|
AccountID: 132848,
|
||||||
AccountName: "std_broker",
|
AccountName: "std_broker",
|
||||||
AffinityLabel: "",
|
AffinityLabel: "",
|
||||||
@@ -150,92 +150,92 @@ var computes = ListComputes{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
func TestFilterByID(t *testing.T) {
|
||||||
actual := computes.FilterByID(48500).FindOne()
|
actual := computes.FilterByID(48500).FindOne()
|
||||||
|
|
||||||
if actual.ID != 48500 {
|
if actual.ID != 48500 {
|
||||||
t.Fatal("expected ID 48500, found: ", actual.ID)
|
t.Fatal("expected ID 48500, found: ", actual.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
actualEmpty := computes.FilterByID(0)
|
actualEmpty := computes.FilterByID(0)
|
||||||
|
|
||||||
if len(actualEmpty) != 0 {
|
if len(actualEmpty) != 0 {
|
||||||
t.Fatal("expected empty, actual: ", len(actualEmpty))
|
t.Fatal("expected empty, actual: ", len(actualEmpty))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByName(t *testing.T) {
|
func TestFilterByName(t *testing.T) {
|
||||||
actual := computes.FilterByName("test").FindOne()
|
actual := computes.FilterByName("test").FindOne()
|
||||||
|
|
||||||
if actual.Name != "test" {
|
if actual.Name != "test" {
|
||||||
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByStatus(t *testing.T) {
|
func TestFilterByStatus(t *testing.T) {
|
||||||
actual := computes.FilterByStatus("ENABLED")
|
actual := computes.FilterByStatus("ENABLED")
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual {
|
||||||
if item.Status != "ENABLED" {
|
if item.Status != "ENABLED" {
|
||||||
t.Fatal("expected ENABLED status, found: ", item.Status)
|
t.Fatal("expected ENABLED status, found: ", item.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByTechStatus(t *testing.T) {
|
func TestFilterByTechStatus(t *testing.T) {
|
||||||
actual := computes.FilterByTechStatus("STARTED").FindOne()
|
actual := computes.FilterByTechStatus("STARTED").FindOne()
|
||||||
|
|
||||||
if actual.ID != 48556 {
|
if actual.ID != 48556 {
|
||||||
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByDiskID(t *testing.T) {
|
func TestFilterByDiskID(t *testing.T) {
|
||||||
actual := computes.FilterByDiskID(65248).FindOne()
|
actual := computes.FilterByDiskID(65248).FindOne()
|
||||||
|
|
||||||
if actual.ID != 48556 {
|
if actual.ID != 48556 {
|
||||||
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
func TestFilterFunc(t *testing.T) {
|
||||||
actual := computes.FilterFunc(func(ic ItemCompute) bool {
|
actual := computes.FilterFunc(func(ic ItemCompute) bool {
|
||||||
return ic.Registered == true
|
return ic.Registered == true
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(actual) != 2 {
|
if len(actual) != 2 {
|
||||||
t.Fatal("expected 2 elements found, actual: ", len(actual))
|
t.Fatal("expected 2 elements found, actual: ", len(actual))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range actual {
|
for _, item := range actual {
|
||||||
if item.Registered != true {
|
if item.Registered != true {
|
||||||
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSortingByCreatedTime(t *testing.T) {
|
func TestSortingByCreatedTime(t *testing.T) {
|
||||||
actual := computes.SortByCreatedTime(false)
|
actual := computes.SortByCreatedTime(false)
|
||||||
|
|
||||||
if actual[0].Name != "test" {
|
if actual[0].Name != "test" {
|
||||||
t.Fatal("expected 'test', found: ", actual[0].Name)
|
t.Fatal("expected 'test', found: ", actual[0].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual = computes.SortByCreatedTime(true)
|
actual = computes.SortByCreatedTime(true)
|
||||||
if actual[0].Name != "compute_2" {
|
if actual[0].Name != "compute_2" {
|
||||||
t.Fatal("expected 'compute_2', found: ", actual[0].Name)
|
t.Fatal("expected 'compute_2', found: ", actual[0].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSortingByCPU(t *testing.T) {
|
func TestSortingByCPU(t *testing.T) {
|
||||||
actual := computes.SortByCPU(false)
|
actual := computes.SortByCPU(false)
|
||||||
|
|
||||||
if actual[0].CPU != 4{
|
if actual[0].CPU != 4 {
|
||||||
t.Fatal("expected 4 CPU cores, found: ", actual[0].CPU)
|
t.Fatal("expected 4 CPU cores, found: ", actual[0].CPU)
|
||||||
}
|
}
|
||||||
|
|
||||||
actual = computes.SortByCPU(true)
|
actual = computes.SortByCPU(true)
|
||||||
|
|
||||||
if actual[0].CPU != 6 {
|
if actual[0].CPU != 6 {
|
||||||
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPU)
|
t.Fatal("expected 6 CPU cores, found: ", actual[0].CPU)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package compute
|
package compute
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
// Access Control List
|
// Access Control List
|
||||||
type RecordACL struct {
|
type RecordACL struct {
|
||||||
// Account ACL list
|
// Account ACL list
|
||||||
@@ -12,10 +14,27 @@ type RecordACL struct {
|
|||||||
RGACL ListACL `json:"rgAcl"`
|
RGACL ListACL `json:"rgAcl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Explicit bool
|
||||||
|
|
||||||
|
func (e *Explicit) UnmarshalJSON(b []byte) error {
|
||||||
|
if b[0] == '"' {
|
||||||
|
b = b[1 : len(b)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := strconv.ParseBool(string(b))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*e = Explicit(res)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ACL information
|
// ACL information
|
||||||
type ItemACL struct {
|
type ItemACL struct {
|
||||||
// Explicit
|
// Explicit
|
||||||
Explicit bool `json:"explicit"`
|
Explicit Explicit `json:"explicit"`
|
||||||
|
|
||||||
// GUID
|
// GUID
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
@@ -131,6 +150,9 @@ type RecordNetAttach struct {
|
|||||||
// Default GW
|
// Default GW
|
||||||
DefGW string `json:"defGw"`
|
DefGW string `json:"defGw"`
|
||||||
|
|
||||||
|
// Enabled
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// FLIPGroup ID
|
// FLIPGroup ID
|
||||||
FLIPGroupID uint64 `json:"flipgroupId"`
|
FLIPGroupID uint64 `json:"flipgroupId"`
|
||||||
|
|
||||||
@@ -159,7 +181,7 @@ type RecordNetAttach struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
@@ -464,6 +486,9 @@ type ItemVNFInterface struct {
|
|||||||
// Default GW
|
// Default GW
|
||||||
DefGW string `json:"defGw"`
|
DefGW string `json:"defGw"`
|
||||||
|
|
||||||
|
// Enabled
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// FLIPGroup ID
|
// FLIPGroup ID
|
||||||
FLIPGroupID uint64 `json:"flipgroupId"`
|
FLIPGroupID uint64 `json:"flipgroupId"`
|
||||||
|
|
||||||
@@ -492,7 +517,7 @@ type ItemVNFInterface struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
@@ -592,7 +617,7 @@ type ItemComputeDisk struct {
|
|||||||
Passwd string `json:"passwd"`
|
Passwd string `json:"passwd"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// Pool
|
// Pool
|
||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
@@ -709,8 +734,7 @@ type IOTune struct {
|
|||||||
// Main information about compute
|
// Main information about compute
|
||||||
type ItemCompute struct {
|
type ItemCompute struct {
|
||||||
// Access Control List
|
// Access Control List
|
||||||
ACL []interface{} `json:"acl"`
|
ACL ListACL `json:"acl"`
|
||||||
|
|
||||||
// Account ID
|
// Account ID
|
||||||
AccountID uint64 `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
@@ -877,7 +901,7 @@ type InfoDisk struct {
|
|||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
// PCISlot
|
// PCISlot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List information about computes
|
// List information about computes
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
|||||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||||
|
|
||||||
// End port number (inclusive) for the ranged rule
|
// End port number (inclusive) for the ranged rule
|
||||||
|
// Default value: -1
|
||||||
// Required: false
|
// Required: false
|
||||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||||
|
|
||||||
// Internal base port number
|
// Internal base port number
|
||||||
// Required: true
|
// Required: true
|
||||||
|
|||||||
@@ -130,3 +130,62 @@ func (ld ListDisks) FindOne() ItemDisk {
|
|||||||
|
|
||||||
return ld[0]
|
return ld[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FilterByID returns ListDisksUnattached with specified ID.
|
||||||
|
func (lu ListDisksUnattached) FilterByID(id uint64) ListDisksUnattached {
|
||||||
|
predicate := func(idisk ItemDiskUnattached) bool {
|
||||||
|
return idisk.ID == id
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByName returns ListDisksUnattached with specified Name.
|
||||||
|
func (lu ListDisksUnattached) FilterByName(name string) ListDisksUnattached {
|
||||||
|
predicate := func(idisk ItemDiskUnattached) bool {
|
||||||
|
return idisk.Name == name
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByStatus returns ListDisksUnattached with specified Status.
|
||||||
|
func (lu ListDisksUnattached) FilterByStatus(status string) ListDisksUnattached {
|
||||||
|
predicate := func(idisk ItemDiskUnattached) bool {
|
||||||
|
return idisk.Status == status
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterByTechStatus returns ListDisksUnattached with specified TechStatus.
|
||||||
|
func (lu ListDisksUnattached) FilterByTechStatus(techStatus string) ListDisksUnattached {
|
||||||
|
predicate := func(idisk ItemDiskUnattached) bool {
|
||||||
|
return idisk.TechStatus == techStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterFunc allows filtering ListDisksUnattached based on a user-specified predicate.
|
||||||
|
func (lu ListDisksUnattached) FilterFunc(predicate func(ItemDiskUnattached) bool) ListDisksUnattached {
|
||||||
|
var result ListDisksUnattached
|
||||||
|
|
||||||
|
for _, item := range lu {
|
||||||
|
if predicate(item) {
|
||||||
|
result = append(result, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindOne returns first found ItemDiskUnattached
|
||||||
|
// If none was found, returns an empty struct.
|
||||||
|
func (lu ListDisksUnattached) FindOne() ItemDiskUnattached {
|
||||||
|
if len(lu) == 0 {
|
||||||
|
return ItemDiskUnattached{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu[0]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package disks
|
package disks
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var disks = ListDisks{
|
var disks = ListDisks{
|
||||||
ItemDisk{
|
ItemDisk{
|
||||||
@@ -175,3 +177,198 @@ func TestSortByCreatedTime(t *testing.T) {
|
|||||||
t.Fatal("expected ID 65193, found: ", actual[0].ID)
|
t.Fatal("expected ID 65193, found: ", actual[0].ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var unattachedDisks = ListDisksUnattached{
|
||||||
|
{
|
||||||
|
CKey: "",
|
||||||
|
Meta: []interface{}{
|
||||||
|
"cloudbroker",
|
||||||
|
"disk",
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
AccountID: 149,
|
||||||
|
AccountName: "test_account1",
|
||||||
|
ACL: map[string]interface{}{},
|
||||||
|
BootPartition: 0,
|
||||||
|
CreatedTime: 1681477547,
|
||||||
|
DeletedTime: 0,
|
||||||
|
Description: "",
|
||||||
|
DestructionTime: 0,
|
||||||
|
DiskPath: "",
|
||||||
|
GID: 2002,
|
||||||
|
GUID: 22636,
|
||||||
|
ID: 22636,
|
||||||
|
ImageID: 0,
|
||||||
|
Images: []uint64{},
|
||||||
|
IOTune: IOTune{
|
||||||
|
TotalIOPSSec: 2000,
|
||||||
|
},
|
||||||
|
IQN: "",
|
||||||
|
Login: "",
|
||||||
|
Milestones: 43834,
|
||||||
|
Name: "test_disk",
|
||||||
|
Order: 0,
|
||||||
|
Params: "",
|
||||||
|
ParentID: 0,
|
||||||
|
Password: "",
|
||||||
|
PCISlot: -1,
|
||||||
|
Pool: "data05",
|
||||||
|
PresentTo: []uint64{},
|
||||||
|
PurgeAttempts: 0,
|
||||||
|
PurgeTime: 0,
|
||||||
|
RealityDeviceNumber: 0,
|
||||||
|
ReferenceID: "",
|
||||||
|
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||||
|
ResName: "volumes/volume_22636",
|
||||||
|
Role: "",
|
||||||
|
SEPID: 1,
|
||||||
|
Shareable: false,
|
||||||
|
SizeMax: 0,
|
||||||
|
SizeUsed: 0,
|
||||||
|
Snapshots: nil,
|
||||||
|
Status: "CREATED",
|
||||||
|
TechStatus: "ALLOCATED",
|
||||||
|
Type: "D",
|
||||||
|
VMID: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
CKey: "",
|
||||||
|
Meta: []interface{}{
|
||||||
|
"cloudbroker",
|
||||||
|
"disk",
|
||||||
|
1,
|
||||||
|
},
|
||||||
|
AccountID: 150,
|
||||||
|
AccountName: "test_account",
|
||||||
|
ACL: map[string]interface{}{},
|
||||||
|
BootPartition: 0,
|
||||||
|
CreatedTime: 1681477558,
|
||||||
|
DeletedTime: 0,
|
||||||
|
Description: "",
|
||||||
|
DestructionTime: 0,
|
||||||
|
DiskPath: "",
|
||||||
|
GID: 2002,
|
||||||
|
GUID: 22637,
|
||||||
|
ID: 22637,
|
||||||
|
ImageID: 0,
|
||||||
|
Images: []uint64{},
|
||||||
|
IOTune: IOTune{
|
||||||
|
TotalIOPSSec: 2000,
|
||||||
|
},
|
||||||
|
IQN: "",
|
||||||
|
Login: "",
|
||||||
|
Milestones: 43834,
|
||||||
|
Name: "test_disk",
|
||||||
|
Order: 0,
|
||||||
|
Params: "",
|
||||||
|
ParentID: 0,
|
||||||
|
Password: "",
|
||||||
|
PCISlot: -1,
|
||||||
|
Pool: "data05",
|
||||||
|
PresentTo: []uint64{
|
||||||
|
27,
|
||||||
|
27,
|
||||||
|
},
|
||||||
|
PurgeAttempts: 0,
|
||||||
|
PurgeTime: 0,
|
||||||
|
RealityDeviceNumber: 0,
|
||||||
|
ReferenceID: "",
|
||||||
|
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
|
||||||
|
ResName: "volumes/volume_22637",
|
||||||
|
Role: "",
|
||||||
|
SEPID: 1,
|
||||||
|
Shareable: false,
|
||||||
|
SizeMax: 0,
|
||||||
|
SizeUsed: 0,
|
||||||
|
Snapshots: nil,
|
||||||
|
Status: "CREATED",
|
||||||
|
TechStatus: "ALLOCATED",
|
||||||
|
Type: "B",
|
||||||
|
VMID: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_FilterByID(t *testing.T) {
|
||||||
|
actual := unattachedDisks.FilterByID(22636)
|
||||||
|
|
||||||
|
if len(actual) == 0 {
|
||||||
|
t.Fatal("No elements were found")
|
||||||
|
}
|
||||||
|
|
||||||
|
actualItem := actual.FindOne()
|
||||||
|
|
||||||
|
if actualItem.ID != 22636 {
|
||||||
|
t.Fatal("expected ID 22636, found: ", actualItem.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_FilterByName(t *testing.T) {
|
||||||
|
actual := unattachedDisks.FilterByName("test_disk")
|
||||||
|
|
||||||
|
if len(actual) != 2 {
|
||||||
|
t.Fatal("expected 2 elements, found: ", len(actual))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range actual {
|
||||||
|
if item.Name != "test_disk" {
|
||||||
|
t.Fatal("expected 'test_disk' name, found: ", item.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_FilterByStatus(t *testing.T) {
|
||||||
|
actual := unattachedDisks.FilterByStatus("CREATED")
|
||||||
|
|
||||||
|
if len(actual) == 0 {
|
||||||
|
t.Fatal("No elements were found")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range actual {
|
||||||
|
if item.Status != "CREATED" {
|
||||||
|
t.Fatal("expected 'CREATED' status, found: ", item.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_FilterByTechStatus(t *testing.T) {
|
||||||
|
actual := unattachedDisks.FilterByTechStatus("ALLOCATED")
|
||||||
|
|
||||||
|
if len(actual) == 0 {
|
||||||
|
t.Fatal("No elements were found")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range actual {
|
||||||
|
if item.TechStatus != "ALLOCATED" {
|
||||||
|
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_FilterFunc(t *testing.T) {
|
||||||
|
actual := unattachedDisks.FilterFunc(func(id ItemDiskUnattached) bool {
|
||||||
|
return len(id.PresentTo) == 2
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(actual) == 0 {
|
||||||
|
t.Fatal("No elements were found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(actual[0].PresentTo) != 2 {
|
||||||
|
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual[0].PresentTo))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestListDisksUnattached_SortByCreatedTime(t *testing.T) {
|
||||||
|
actual := unattachedDisks.SortByCreatedTime(false)
|
||||||
|
|
||||||
|
if actual[0].ID != 22636 {
|
||||||
|
t.Fatal("expected ID 22636, found: ", actual[0].ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual = unattachedDisks.SortByCreatedTime(true)
|
||||||
|
|
||||||
|
if actual[0].ID != 22637 {
|
||||||
|
t.Fatal("expected ID 22637, found: ", actual[0].ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
// Request struct for get list types of disks
|
// Request struct for get list types of disks
|
||||||
type ListTypesRequest struct {
|
type ListTypesRequest struct {
|
||||||
// Show detailed disk types by seps
|
// Show detailed disk types by seps
|
||||||
// Required: false
|
// Required: true
|
||||||
Detailed bool `url:"detailed,omitempty" json:"detailed,omitempty"`
|
Detailed bool `url:"detailed" json:"detailed" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListTypes gets list defined disk types
|
// ListTypes gets list defined disk types
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type ListUnattachedRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUnattached gets list of unattached disks
|
// ListUnattached gets list of unattached disks
|
||||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListDisks, error) {
|
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListDisksUnattached, error) {
|
||||||
url := "/cloudapi/disks/listUnattached"
|
url := "/cloudapi/disks/listUnattached"
|
||||||
|
|
||||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
@@ -22,7 +22,7 @@ func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (L
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list := ListDisks{}
|
list := ListDisksUnattached{}
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
err = json.Unmarshal(res, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -114,9 +114,146 @@ type ItemDisk struct {
|
|||||||
VMID uint64 `json:"vmid"`
|
VMID uint64 `json:"vmid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ItemDiskUnattached struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
// Account ID
|
||||||
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
// Account name
|
||||||
|
AccountName string `json:"accountName"`
|
||||||
|
|
||||||
|
// Access Control List
|
||||||
|
ACL map[string]interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// Boot Partition
|
||||||
|
BootPartition uint64 `json:"bootPartition"`
|
||||||
|
|
||||||
|
// Created time
|
||||||
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
|
// Deleted time
|
||||||
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// Destruction time
|
||||||
|
DestructionTime uint64 `json:"destructionTime"`
|
||||||
|
|
||||||
|
// Disk path
|
||||||
|
DiskPath string `json:"diskPath"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Image ID
|
||||||
|
ImageID uint64 `json:"imageId"`
|
||||||
|
|
||||||
|
// Images
|
||||||
|
Images []uint64 `json:"images"`
|
||||||
|
|
||||||
|
// IOTune
|
||||||
|
IOTune IOTune `json:"iotune"`
|
||||||
|
|
||||||
|
// IQN
|
||||||
|
IQN string `json:"iqn"`
|
||||||
|
|
||||||
|
// Login
|
||||||
|
Login string `json:"login"`
|
||||||
|
|
||||||
|
// Milestones
|
||||||
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Order
|
||||||
|
Order uint64 `json:"order"`
|
||||||
|
|
||||||
|
// Params
|
||||||
|
Params string `json:"params"`
|
||||||
|
|
||||||
|
// Parent ID
|
||||||
|
ParentID uint64 `json:"parentId"`
|
||||||
|
|
||||||
|
// Password
|
||||||
|
Password string `json:"passwd"`
|
||||||
|
|
||||||
|
//PCISlot
|
||||||
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
|
// Pool
|
||||||
|
Pool string `json:"pool"`
|
||||||
|
|
||||||
|
// Present to
|
||||||
|
PresentTo []uint64 `json:"presentTo"`
|
||||||
|
|
||||||
|
// Purge attempts
|
||||||
|
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||||
|
|
||||||
|
// Purge time
|
||||||
|
PurgeTime uint64 `json:"purgeTime"`
|
||||||
|
|
||||||
|
// Reality device number
|
||||||
|
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||||
|
|
||||||
|
// Reference ID
|
||||||
|
ReferenceID string `json:"referenceId"`
|
||||||
|
|
||||||
|
// Resource ID
|
||||||
|
ResID string `json:"resId"`
|
||||||
|
|
||||||
|
// Resource name
|
||||||
|
ResName string `json:"resName"`
|
||||||
|
|
||||||
|
// Role
|
||||||
|
Role string `json:"role"`
|
||||||
|
|
||||||
|
// ID SEP
|
||||||
|
SEPID uint64 `json:"sepId"`
|
||||||
|
|
||||||
|
// Shareable
|
||||||
|
Shareable bool `json:"shareable"`
|
||||||
|
|
||||||
|
// Size max
|
||||||
|
SizeMax uint64 `json:"sizeMax"`
|
||||||
|
|
||||||
|
// Size used
|
||||||
|
SizeUsed float64 `json:"sizeUsed"`
|
||||||
|
|
||||||
|
// List of snapshots
|
||||||
|
Snapshots ListSnapshots `json:"snapshots"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Tech status
|
||||||
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
|
||||||
|
// Virtual machine ID
|
||||||
|
VMID uint64 `json:"vmid"`
|
||||||
|
}
|
||||||
|
|
||||||
// List of disks
|
// List of disks
|
||||||
type ListDisks []ItemDisk
|
type ListDisks []ItemDisk
|
||||||
|
|
||||||
|
// List of unattached disks
|
||||||
|
type ListDisksUnattached []ItemDiskUnattached
|
||||||
|
|
||||||
// Main information about snapshot
|
// Main information about snapshot
|
||||||
type ItemSnapshot struct {
|
type ItemSnapshot struct {
|
||||||
// GUID
|
// GUID
|
||||||
@@ -240,7 +377,7 @@ type RecordDisk struct {
|
|||||||
ParentID uint64 `json:"parentId"`
|
ParentID uint64 `json:"parentId"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// Pool
|
// Pool
|
||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
|
|||||||
@@ -41,3 +41,39 @@ func (idisk ItemDisk) Serialize(params ...string) (serialization.Serialized, err
|
|||||||
|
|
||||||
return json.Marshal(idisk)
|
return json.Marshal(idisk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (lu ListDisksUnattached) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(lu) == 0 {
|
||||||
|
return []byte{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(lu, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(lu)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (idisk ItemDiskUnattached) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(idisk, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(idisk)
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,3 +58,60 @@ func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
|
|||||||
|
|
||||||
return ld
|
return ld
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SortByCreatedTime sorts ListDisksUnattached by the CreatedTime field in ascending order.
|
||||||
|
//
|
||||||
|
// If inverse param is set to true, the order is reversed.
|
||||||
|
func (lu ListDisksUnattached) SortByCreatedTime(inverse bool) ListDisksUnattached {
|
||||||
|
if len(lu) < 2 {
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(lu, func(i, j int) bool {
|
||||||
|
if inverse {
|
||||||
|
return lu[i].CreatedTime > lu[j].CreatedTime
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu[i].CreatedTime < lu[j].CreatedTime
|
||||||
|
})
|
||||||
|
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortByDestructionTime sorts ListDisksUnattached by the DestructionTime field in ascending order.
|
||||||
|
//
|
||||||
|
// If inverse param is set to true, the order is reversed.
|
||||||
|
func (lu ListDisksUnattached) SortByDestructionTime(inverse bool) ListDisksUnattached {
|
||||||
|
if len(lu) < 2 {
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(lu, func(i, j int) bool {
|
||||||
|
if inverse {
|
||||||
|
return lu[i].DestructionTime > lu[j].DestructionTime
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu[i].DestructionTime < lu[j].DestructionTime
|
||||||
|
})
|
||||||
|
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SortByDeletedTime sorts ListDisksUnattached by the DeletedTime field in ascending order.
|
||||||
|
//
|
||||||
|
// If inverse param is set to true, the order is reversed.
|
||||||
|
func (lu ListDisksUnattached) SortByDeletedTime(inverse bool) ListDisksUnattached {
|
||||||
|
if len(lu) < 2 {
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(lu, func(i, j int) bool {
|
||||||
|
if inverse {
|
||||||
|
return lu[i].DeletedTime > lu[j].DeletedTime
|
||||||
|
}
|
||||||
|
|
||||||
|
return lu[i].DeletedTime < lu[j].DeletedTime
|
||||||
|
})
|
||||||
|
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ type ListExtNetComputes []ItemExtNetCompute
|
|||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
type QOS struct {
|
type QOS struct {
|
||||||
|
// EBurst
|
||||||
|
EBurst uint64 `json:"eBurst"`
|
||||||
|
|
||||||
// ERate
|
// ERate
|
||||||
ERate uint64 `json:"eRate"`
|
ERate uint64 `json:"eRate"`
|
||||||
|
|
||||||
@@ -107,6 +110,23 @@ type VNFs struct {
|
|||||||
DHCP uint64 `json:"dhcp"`
|
DHCP uint64 `json:"dhcp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Excluded struct {
|
||||||
|
// ClientType
|
||||||
|
ClientType string `json:"clientType"`
|
||||||
|
|
||||||
|
// IP
|
||||||
|
IP string `json:"ip"`
|
||||||
|
|
||||||
|
// MAC
|
||||||
|
MAC string `json:"mac"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
|
||||||
|
// VMID
|
||||||
|
VMID uint64 `json:"vmId"`
|
||||||
|
}
|
||||||
|
|
||||||
// Detailed information about external network
|
// Detailed information about external network
|
||||||
type RecordExtNet struct {
|
type RecordExtNet struct {
|
||||||
// CKey
|
// CKey
|
||||||
@@ -134,7 +154,7 @@ type RecordExtNet struct {
|
|||||||
DNS []string `json:"dns"`
|
DNS []string `json:"dns"`
|
||||||
|
|
||||||
// Excluded
|
// Excluded
|
||||||
Excluded []string `json:"excluded"`
|
Excluded []Excluded `json:"excluded"`
|
||||||
|
|
||||||
// Free IPs
|
// Free IPs
|
||||||
FreeIPs uint64 `json:"free_ips"`
|
FreeIPs uint64 `json:"free_ips"`
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ type RecordK8CI struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network plugins
|
||||||
|
NetworkPlugins []string `json:"networkPlugins"`
|
||||||
|
|
||||||
// Version
|
// Version
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ type CreateRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
// Must be one of these values: flannel, weawenet, calico
|
||||||
|
// Required: true
|
||||||
|
NetworkPlugin string `url:"networkPlugin" json:"networkPlugin" validate:"required,networkPlugin"`
|
||||||
|
|
||||||
// ID of SEP to create boot disks for master nodes. Uses images SEP ID if not set
|
// ID of SEP to create boot disks for master nodes. Uses images SEP ID if not set
|
||||||
// Required: false
|
// Required: false
|
||||||
MasterSEPID uint64 `url:"masterSepId,omitempty" json:"masterSepId,omitempty"`
|
MasterSEPID uint64 `url:"masterSepId,omitempty" json:"masterSepId,omitempty"`
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Request struct for disable/enable kubernetes cluster
|
// Request struct for disable/enable kubernetes cluster
|
||||||
type DisabelEnableRequest struct {
|
type DisableEnableRequest struct {
|
||||||
// Kubernetes cluster ID
|
// Kubernetes cluster ID
|
||||||
// Required: true
|
// Required: true
|
||||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable disables kubernetes cluster by ID
|
// Disable disables kubernetes cluster by ID
|
||||||
func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
func (k8s K8S) Disable(ctx context.Context, req DisableEnableRequest) (bool, 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) {
|
||||||
@@ -40,7 +40,7 @@ func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enable enables kubernetes cluster by ID
|
// Enable enables kubernetes cluster by ID
|
||||||
func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
func (k8s K8S) Enable(ctx context.Context, req DisableEnableRequest) (bool, 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) {
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ type RecordK8S struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
NetworkPlugin string `json:"networkPlugin"`
|
||||||
|
|
||||||
// Resource group ID
|
// Resource group ID
|
||||||
RGID uint64 `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
@@ -246,6 +249,9 @@ type ItemK8SCluster struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
NetworkPlugin string `json:"networkPlugin"`
|
||||||
|
|
||||||
// Resource group ID
|
// Resource group ID
|
||||||
RGID uint64 `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package k8s
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,11 +23,11 @@ type WorkerAddRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
// WorkerAdd add worker nodes to a Kubernetes cluster
|
||||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error) {
|
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) ([]uint64, 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) {
|
||||||
return false, validators.ValidationError(validationError)
|
return nil, validators.ValidationError(validationError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,12 +35,14 @@ func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error
|
|||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
result := make([]uint64, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ type WorkersGroupAddRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorkersGroupAdd adds workers group to Kubernetes cluster
|
// WorkersGroupAdd adds workers group to Kubernetes cluster
|
||||||
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (bool, error) {
|
func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest) (uint64, 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) {
|
||||||
return false, validators.ValidationError(validationError)
|
return 0, validators.ValidationError(validationError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,12 +71,12 @@ func (k8s K8S) WorkersGroupAdd(ctx context.Context, req WorkersGroupAddRequest)
|
|||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -18,6 +18,15 @@ func (ll ListLocations) FilterByName(name string) ListLocations {
|
|||||||
return ll.FilterFunc(predicate)
|
return ll.FilterFunc(predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FilterByGID returns ListLocations with specified GID.
|
||||||
|
func (ll ListLocations) FilterByGID(gid uint64) ListLocations {
|
||||||
|
predicate := func(il ItemLocation) bool {
|
||||||
|
return il.GID == gid
|
||||||
|
}
|
||||||
|
|
||||||
|
return ll.FilterFunc(predicate)
|
||||||
|
}
|
||||||
|
|
||||||
// FilterFunc allows filtering ListLocations based on a user-specified predicate.
|
// FilterFunc allows filtering ListLocations based on a user-specified predicate.
|
||||||
func (ll ListLocations) FilterFunc(predicate func(ItemLocation) bool) ListLocations {
|
func (ll ListLocations) FilterFunc(predicate func(ItemLocation) bool) ListLocations {
|
||||||
var result ListLocations
|
var result ListLocations
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ type RecordResourceGroup struct {
|
|||||||
// Access Control List
|
// Access Control List
|
||||||
ACL ListACL `json:"acl"`
|
ACL ListACL `json:"acl"`
|
||||||
|
|
||||||
|
// CPU allocation parameter
|
||||||
|
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
@@ -107,12 +113,18 @@ type RecordResourceGroup struct {
|
|||||||
// Resource limits
|
// Resource limits
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
|
// List of resource types
|
||||||
|
ResTypes []string `json:"resourceTypes"`
|
||||||
|
|
||||||
// Secret
|
// Secret
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// UniqPools
|
||||||
|
UniqPools []string `json:"uniqPools"`
|
||||||
|
|
||||||
// Updated by
|
// Updated by
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
|
||||||
@@ -124,12 +136,6 @@ type RecordResourceGroup struct {
|
|||||||
|
|
||||||
// List of compute IDs
|
// List of compute IDs
|
||||||
Computes []uint64 `json:"vms"`
|
Computes []uint64 `json:"vms"`
|
||||||
|
|
||||||
// List of resource types
|
|
||||||
ResTypes []string `json:"resourceTypes"`
|
|
||||||
|
|
||||||
// UniqPools
|
|
||||||
UniqPools []string `json:"uniqPools"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main information about resource group
|
// Main information about resource group
|
||||||
@@ -146,6 +152,12 @@ type ItemResourceGroup struct {
|
|||||||
// Access Control List
|
// Access Control List
|
||||||
ACL ListACL `json:"acl"`
|
ACL ListACL `json:"acl"`
|
||||||
|
|
||||||
|
// CPU allocation parameter
|
||||||
|
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
@@ -194,12 +206,18 @@ type ItemResourceGroup struct {
|
|||||||
// Resource limits
|
// Resource limits
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
|
// List of resource types
|
||||||
|
ResTypes []string `json:"resourceTypes"`
|
||||||
|
|
||||||
// Secret
|
// Secret
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// UniqPools
|
||||||
|
UniqPools []string `json:"uniqPools"`
|
||||||
|
|
||||||
// Updated by
|
// Updated by
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
|
||||||
@@ -211,12 +229,6 @@ type ItemResourceGroup struct {
|
|||||||
|
|
||||||
// List of compute IDs
|
// List of compute IDs
|
||||||
Computes []uint64 `json:"vms"`
|
Computes []uint64 `json:"vms"`
|
||||||
|
|
||||||
// List of resource types
|
|
||||||
ResTypes []string `json:"resourceTypes"`
|
|
||||||
|
|
||||||
// UniqPools
|
|
||||||
UniqPools []string `json:"uniqPools"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of resource groups
|
// List of resource groups
|
||||||
@@ -735,7 +747,10 @@ type RecordResourceUsage struct {
|
|||||||
CPU uint64 `json:"cpu"`
|
CPU uint64 `json:"cpu"`
|
||||||
|
|
||||||
// Disk size
|
// Disk size
|
||||||
DiskSize uint64 `json:"disksize"`
|
DiskSize float64 `json:"disksize"`
|
||||||
|
|
||||||
|
// Max disk size
|
||||||
|
DiskSizeMax uint64 `json:"disksizemax"`
|
||||||
|
|
||||||
// Number of external IPs
|
// Number of external IPs
|
||||||
ExtIPs uint64 `json:"extips"`
|
ExtIPs uint64 `json:"extips"`
|
||||||
@@ -748,4 +763,7 @@ type RecordResourceUsage struct {
|
|||||||
|
|
||||||
// Number of RAM
|
// Number of RAM
|
||||||
RAM uint64 `json:"ram"`
|
RAM uint64 `json:"ram"`
|
||||||
|
|
||||||
|
// SEPs
|
||||||
|
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,23 +24,23 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// Max size of memory in MB
|
// Max size of memory in MB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||||
|
|
||||||
// Max size of aggregated virtual disks in GB
|
// Max size of aggregated virtual disks in GB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||||
|
|
||||||
// Max number of CPU cores
|
// Max number of CPU cores
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||||
|
|
||||||
// Max sent/received network transfer peering
|
// Max sent/received network transfer peering
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
// Max number of assigned public IPs
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||||
|
|
||||||
// Register computes in registration system
|
// Register computes in registration system
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ type ItemVNFInterface struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -123,6 +123,12 @@ type InfoAccount struct {
|
|||||||
// Company URL
|
// Company URL
|
||||||
CompanyURL string `json:"companyurl"`
|
CompanyURL string `json:"companyurl"`
|
||||||
|
|
||||||
|
// CPU allocation parameter
|
||||||
|
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
@@ -154,7 +160,7 @@ type InfoAccount struct {
|
|||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
// Resource types
|
// Resource types
|
||||||
ResourceTypes []string `json:"resourceTypes"`
|
ResTypes []string `json:"resourceTypes"`
|
||||||
|
|
||||||
// Send access emails
|
// Send access emails
|
||||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
SendAccessEmails bool `json:"sendAccessEmails"`
|
||||||
|
|||||||
45
pkg/cloudbroker/account/set_cpu_allocation_parameter.go
Normal file
45
pkg/cloudbroker/account/set_cpu_allocation_parameter.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation parameter
|
||||||
|
type SetCPUAllocationParameterRequest struct {
|
||||||
|
// Account ID
|
||||||
|
// Required: true
|
||||||
|
AccountID uint64 `url:"accountId" json:"accoutnId" validate:"required"`
|
||||||
|
|
||||||
|
// CPU allocation parameter.
|
||||||
|
// If "strict" VM can't be run if not enough CPU resources.
|
||||||
|
// "loose" allow running VM if not enough resources.
|
||||||
|
// Required: true
|
||||||
|
StrictLoose string `url:"strict_loose" json:"strict_loose" validate:"required,strict_loose"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationParameter sets CPU allocation parameter
|
||||||
|
func (a Account) SetCPUAllocationParameter(ctx context.Context, req SetCPUAllocationParameterRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/account/setCpuAllocationParameter"
|
||||||
|
|
||||||
|
res, err := a.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
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/account/set_cpu_allocation_ratio.go
Normal file
43
pkg/cloudbroker/account/set_cpu_allocation_ratio.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation ratio
|
||||||
|
type SetCPUAllocationRatioRequest struct {
|
||||||
|
// Account ID
|
||||||
|
// Required: true
|
||||||
|
AccountID uint64 `url:"accountId" json:"accoutnId" validate:"required"`
|
||||||
|
|
||||||
|
// CPU allocation ratio, i.e. one pCPU = ratio*vCPU
|
||||||
|
// Required: true
|
||||||
|
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationRatio sets CPU allocation ratio
|
||||||
|
func (a Account) SetCPUAllocationRatio(ctx context.Context, req SetCPUAllocationRatioRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/account/setCpuAllocationRatio"
|
||||||
|
|
||||||
|
res, err := a.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
|
||||||
|
}
|
||||||
@@ -15,8 +15,8 @@ type UpdateRequest struct {
|
|||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
// Display name
|
// Display name
|
||||||
// Required: true
|
// Required: false
|
||||||
Name string `url:"name" json:"name" validate:"required"`
|
Name string `url:"name" json:"name"`
|
||||||
|
|
||||||
// Name of the account
|
// Name of the account
|
||||||
// Required: true
|
// Required: true
|
||||||
@@ -24,35 +24,35 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// Email
|
// Email
|
||||||
// Required: false
|
// Required: false
|
||||||
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
|
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
|
||||||
|
|
||||||
// Max size of memory in MB
|
// Max size of memory in MB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||||
|
|
||||||
// Max size of aggregated vdisks in GB
|
// Max size of aggregated vdisks in GB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||||
|
|
||||||
// Max number of CPU cores
|
// Max number of CPU cores
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||||
|
|
||||||
// Max sent/received network transfer peering
|
// Max sent/received network transfer peering
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
// Max number of assigned public IPs
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
GPUUnits uint64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
||||||
|
|
||||||
// List of strings with pools
|
// List of strings with pools
|
||||||
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
|
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
|
||||||
|
|||||||
8
pkg/cloudbroker/backup.go
Normal file
8
pkg/cloudbroker/backup.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/backup"
|
||||||
|
|
||||||
|
// Accessing the Backup method group
|
||||||
|
func (cb *CloudBroker) Backup() *backup.Backup {
|
||||||
|
return backup.New(cb.client)
|
||||||
|
}
|
||||||
17
pkg/cloudbroker/backup/backup.go
Normal file
17
pkg/cloudbroker/backup/backup.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Structure for creating request to backup
|
||||||
|
type Backup struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for backup endpoints
|
||||||
|
func New(client interfaces.Caller) *Backup {
|
||||||
|
return &Backup{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
81
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
81
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for creating disk backup
|
||||||
|
type CreateDiskBackupRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Disk ID
|
||||||
|
// Required: true
|
||||||
|
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||||
|
|
||||||
|
// Backup path
|
||||||
|
// Required: true
|
||||||
|
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||||
|
|
||||||
|
// Async API Call
|
||||||
|
// For async call use CreateDiskBackupAsync
|
||||||
|
// For sync call use CreateDiskBackup
|
||||||
|
// Required: true
|
||||||
|
async bool `url:"async"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDiskBackup creates disk backup
|
||||||
|
func (b Backup) CreateDiskBackup(ctx context.Context, req CreateDiskBackupRequest) (ListInfoBackup, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = false
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(ListInfoBackup, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDiskBackupAsync creates disk backup
|
||||||
|
func (b Backup) CreateDiskBackupAsync(ctx context.Context, req CreateDiskBackupRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = true
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
83
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
83
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Disk struct {
|
||||||
|
// Disk ID
|
||||||
|
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||||
|
|
||||||
|
// Backup path
|
||||||
|
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request struct for creating disks backup
|
||||||
|
type CreateDisksBackupRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Disks
|
||||||
|
Disks []Disk `url:"disks" json:"disks" validate:"required,dive"`
|
||||||
|
|
||||||
|
// Async API Call
|
||||||
|
// For async call use CreateDisksBackupAsync
|
||||||
|
// For sync call use CreateDisksBackup
|
||||||
|
// Required: true
|
||||||
|
async bool `url:"async"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDisksBackup creates disks backup
|
||||||
|
func (b Backup) CreateDisksBackup(ctx context.Context, req CreateDisksBackupRequest) (ListInfoBackup, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = false
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDisksBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(ListInfoBackup, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDisksBackupAsync creates disks backup
|
||||||
|
func (b Backup) CreateDisksBackupAsync(ctx context.Context, req CreateDisksBackupRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = true
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDisksBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
73
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
73
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for deleting disk backup
|
||||||
|
type DeleteDiskBackupRequest struct {
|
||||||
|
// Backup path
|
||||||
|
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||||
|
|
||||||
|
// Backup file
|
||||||
|
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||||
|
|
||||||
|
// Async API Call
|
||||||
|
// For async call use DeleteDiskBackupAsync
|
||||||
|
// For sync call use DeleteDiskBackup
|
||||||
|
// Required: true
|
||||||
|
async bool `url:"async"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDiskBackup deletes disk backup
|
||||||
|
func (b Backup) DeleteDiskBackup(ctx context.Context, req DeleteDiskBackupRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = false
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.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
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDiskBackupAsync deletes disk backup
|
||||||
|
func (b Backup) DeleteDiskBackupAsync(ctx context.Context, req DeleteDiskBackupRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = true
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
40
pkg/cloudbroker/backup/list_backup_paths.go
Normal file
40
pkg/cloudbroker/backup/list_backup_paths.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting list of backup paths
|
||||||
|
type ListBackupPathsRequest struct {
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListBackupPaths gets list of backup paths
|
||||||
|
func (b Backup) ListBackupPaths(ctx context.Context, req ListBackupPathsRequest) ([]string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/listBackupPaths"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]string, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
31
pkg/cloudbroker/backup/models.go
Normal file
31
pkg/cloudbroker/backup/models.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
// Main info about backup
|
||||||
|
type InfoBackup struct {
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `json:"computeId"`
|
||||||
|
|
||||||
|
// Disk ID
|
||||||
|
DiskID uint64 `json:"diskId"`
|
||||||
|
|
||||||
|
// Backup path
|
||||||
|
BackupPath string `json:"backupPath"`
|
||||||
|
|
||||||
|
// Possible error
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDisksBackup response
|
||||||
|
type ListInfoBackup []InfoBackup
|
||||||
|
|
||||||
|
// RestoreDiskFromFile response
|
||||||
|
type InfoRestoredDisk struct {
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `json:"computeId"`
|
||||||
|
|
||||||
|
// Disk ID
|
||||||
|
DiskID uint64 `json:"diskId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreDisksFromFile response
|
||||||
|
type ListInfoRestoredDisk []InfoRestoredDisk
|
||||||
81
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
81
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for restoring disk from backup
|
||||||
|
type RestoreDiskFromBackupRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Disk ID
|
||||||
|
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||||
|
|
||||||
|
// Backup path
|
||||||
|
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||||
|
|
||||||
|
// Backup file
|
||||||
|
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||||
|
|
||||||
|
// Async API Call
|
||||||
|
// For async call use RestoreDiskFromBackupAsync
|
||||||
|
// For sync call use RestoreDiskFromBackup
|
||||||
|
// Required: true
|
||||||
|
async bool `url:"async"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreDiskFromBackup restores disk from backup
|
||||||
|
func (b Backup) RestoreDiskFromBackup(ctx context.Context, req RestoreDiskFromBackupRequest) (ListInfoRestoredDisk, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = false
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(ListInfoRestoredDisk, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreDiskFromBackupAsync restores disk from backup
|
||||||
|
func (b Backup) RestoreDiskFromBackupAsync(ctx context.Context, req RestoreDiskFromBackupRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = true
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
86
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
86
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BackupFile struct {
|
||||||
|
// Disk ID
|
||||||
|
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||||
|
|
||||||
|
// Backup path
|
||||||
|
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||||
|
|
||||||
|
// Backup file
|
||||||
|
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request struct for restoring disks from backup
|
||||||
|
type RestoreDisksFromBackupRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
//Backup files
|
||||||
|
BackupFiles []BackupFile `url:"backupFiles" json:"backupFiles" validate:"required,dive"`
|
||||||
|
|
||||||
|
// Async API Call
|
||||||
|
// For async call use RestoreDisksFromBackupAsync
|
||||||
|
// For sync call use RestoreDisksFromBackup
|
||||||
|
// Required: true
|
||||||
|
async bool `url:"async"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreDisksFromBackup restores disks from backup
|
||||||
|
func (b Backup) RestoreDisksFromBackup(ctx context.Context, req RestoreDisksFromBackupRequest) (ListInfoRestoredDisk, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = false
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(ListInfoRestoredDisk, 0)
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreDisksFromBackupAsync restores disks from backup
|
||||||
|
func (b Backup) RestoreDisksFromBackupAsync(ctx context.Context, req RestoreDisksFromBackupRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.async = true
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
47
pkg/cloudbroker/compute/change_link_state.go
Normal file
47
pkg/cloudbroker/compute/change_link_state.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for changing link state
|
||||||
|
type ChangeLinkStateRequest struct {
|
||||||
|
// Compute ID
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Interface name or MAC address
|
||||||
|
// Required: true
|
||||||
|
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||||
|
|
||||||
|
// Interface state
|
||||||
|
// Must be either "on" or "off"
|
||||||
|
// Required: true
|
||||||
|
State string `url:"state" json:"state" validate:"required,interfaceState"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangeLinkState changes the status link virtual of compute
|
||||||
|
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/compute/changeLinkState"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -12,27 +12,27 @@ import (
|
|||||||
type DiskAddRequest struct {
|
type DiskAddRequest struct {
|
||||||
// ID of compute instance
|
// ID of compute instance
|
||||||
// Required: true
|
// Required: true
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
// Name for disk
|
// Name for disk
|
||||||
// Required: true
|
// Required: true
|
||||||
DiskName string `url:"diskName" json:"diskName" validate:"required"`
|
DiskName string `url:"diskName" json:"diskName" validate:"required"`
|
||||||
|
|
||||||
// Disk size in GB
|
// Disk size in GB
|
||||||
// Required: true
|
// Required: true
|
||||||
Size uint64 `url:"size" json:"size" validate:"required"`
|
Size uint64 `url:"size" json:"size" validate:"required"`
|
||||||
|
|
||||||
|
// Storage endpoint provider ID
|
||||||
|
// By default the same with boot disk
|
||||||
|
// Required: false
|
||||||
|
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
// Type of the disk
|
// Type of the disk
|
||||||
// Should be one of:
|
// Should be one of:
|
||||||
// - D
|
// - D
|
||||||
// - B
|
// - B
|
||||||
// Required: false
|
// Required: false
|
||||||
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
DiskType string `url:"diskType,omitempty" json:"diskType,omitempty" validate:"omitempty,computeDiskType"`
|
||||||
|
|
||||||
// Storage endpoint provider ID
|
|
||||||
// By default the same with boot disk
|
|
||||||
// Required: false
|
|
||||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
|
||||||
|
|
||||||
// Pool name
|
// Pool name
|
||||||
// By default will be chosen automatically
|
// By default will be chosen automatically
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ type RecordNetAttach struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
@@ -396,7 +396,7 @@ type ItemDisk struct {
|
|||||||
Password string `json:"passwd"`
|
Password string `json:"passwd"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// Pool
|
// Pool
|
||||||
Pool string `json:"pool"`
|
Pool string `json:"pool"`
|
||||||
@@ -498,7 +498,7 @@ type ItemInterface struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
@@ -738,7 +738,7 @@ type InfoDisk struct {
|
|||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
// PCISlot
|
// PCISlot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List computes
|
// List computes
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
|||||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||||
|
|
||||||
// End port number (inclusive) for the ranged rule
|
// End port number (inclusive) for the ranged rule
|
||||||
|
// Default value: -1
|
||||||
// Required: false
|
// Required: false
|
||||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||||
|
|
||||||
// Internal base port number
|
// Internal base port number
|
||||||
// Required: true
|
// Required: true
|
||||||
|
|||||||
45
pkg/cloudbroker/grid/set_cpu_allocation_parameter.go
Normal file
45
pkg/cloudbroker/grid/set_cpu_allocation_parameter.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package grid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation parameter
|
||||||
|
type SetCPUAllocationParameterRequest struct {
|
||||||
|
// Grid ID
|
||||||
|
// Required: true
|
||||||
|
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||||
|
|
||||||
|
// CPU allocation parameter.
|
||||||
|
// If "strict" VM can't be run if not enough CPU resources.
|
||||||
|
// "loose" allow running VM if not enough resources.
|
||||||
|
// Required: true
|
||||||
|
StrictLoose string `url:"strict_loose" json:"strict_loose" validate:"required,strict_loose"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationParameter sets CPU allocation parameter
|
||||||
|
func (g Grid) SetCPUAllocationParameter(ctx context.Context, req SetCPUAllocationParameterRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/grid/setCpuAllocationParameter"
|
||||||
|
|
||||||
|
res, err := g.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
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/grid/set_cpu_allocation_ratio_for_vm.go
Normal file
43
pkg/cloudbroker/grid/set_cpu_allocation_ratio_for_vm.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package grid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation ratio for computes
|
||||||
|
type SetCPUAllocationRatioForVMRequest struct {
|
||||||
|
// Grid ID
|
||||||
|
// Required: true
|
||||||
|
GridID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||||
|
|
||||||
|
// Default CPU allocation ratio for computes
|
||||||
|
// Required: true
|
||||||
|
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationRatio sets CPU allocation ratio for computes
|
||||||
|
func (g Grid) SetCPUAllocationRatioForVM(ctx context.Context, req SetCPUAllocationRatioForVMRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/grid/setCpuAllocationRatioForVM"
|
||||||
|
|
||||||
|
res, err := g.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
|
||||||
|
}
|
||||||
@@ -34,6 +34,11 @@ type CreateRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
MasterDriver string `url:"masterDriver" json:"masterDriver" validate:"driver"`
|
MasterDriver string `url:"masterDriver" json:"masterDriver" validate:"driver"`
|
||||||
|
|
||||||
|
// Network plugins
|
||||||
|
// Values of slice must be flannel, weawenet or calico
|
||||||
|
//Required: true
|
||||||
|
NetworkPlugins []string `url:"networkPlugins" json:"networkPlugins" validate:"required,networkPlugins"`
|
||||||
|
|
||||||
// Image ID for worker K8S node
|
// Image ID for worker K8S node
|
||||||
// Required: true
|
// Required: true
|
||||||
WorkerImageID uint64 `url:"workerImageId" json:"workerImageId" validate:"required"`
|
WorkerImageID uint64 `url:"workerImageId" json:"workerImageId" validate:"required"`
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ type CreateRequest struct {
|
|||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
// Must be one of these values: flunnel, weawenet, calico
|
||||||
|
// Required: true
|
||||||
|
NetworkPlugin string `url:"networkPlugin" json:"networkPlugin" validate:"required,networkPlugin"`
|
||||||
|
|
||||||
// ID of SEP to create boot disks for master nodes.
|
// ID of SEP to create boot disks for master nodes.
|
||||||
// Uses images SEP ID if not set
|
// Uses images SEP ID if not set
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ type RecordK8S struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
NetworkPlugin string `json:"networkPlugin"`
|
||||||
|
|
||||||
// Resource group ID
|
// Resource group ID
|
||||||
RGID uint64 `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
@@ -245,6 +248,9 @@ type ItemK8S struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network plugin
|
||||||
|
NetworkPlugin string `json:"networkPlugin"`
|
||||||
|
|
||||||
// Resource group ID
|
// Resource group ID
|
||||||
RGID uint64 `json:"rgId"`
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
|||||||
8
pkg/cloudbroker/pcidevice.go
Normal file
8
pkg/cloudbroker/pcidevice.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/pcidevice"
|
||||||
|
|
||||||
|
// Accessing the PCI Device method group
|
||||||
|
func (cb *CloudBroker) PCIDevice() *pcidevice.PCIDevice {
|
||||||
|
return pcidevice.New(cb.client)
|
||||||
|
}
|
||||||
56
pkg/cloudbroker/pcidevice/create.go
Normal file
56
pkg/cloudbroker/pcidevice/create.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for creating PCI device
|
||||||
|
type CreateRequest struct {
|
||||||
|
// StackID
|
||||||
|
// Required: true
|
||||||
|
StackID uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||||
|
|
||||||
|
// Resource group ID
|
||||||
|
// Required: true
|
||||||
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
|
// Name of device
|
||||||
|
// Required: true
|
||||||
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
|
// PCI address of the device
|
||||||
|
// Must be in format 0000:1f:2b.0
|
||||||
|
// Required: true
|
||||||
|
HWPath string `url:"hwPath" json:"hwPath" validate:"required,hwPath"`
|
||||||
|
|
||||||
|
// Description, just for information
|
||||||
|
// Required: false
|
||||||
|
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates PCI Device
|
||||||
|
func (p PCIDevice) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return 0, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/pcidevice/create"
|
||||||
|
|
||||||
|
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/pcidevice/delete.go
Normal file
43
pkg/cloudbroker/pcidevice/delete.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for deleting PCI device
|
||||||
|
type DeleteRequest struct {
|
||||||
|
// PCI device ID
|
||||||
|
// Required: true
|
||||||
|
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
|
||||||
|
|
||||||
|
// Force delete
|
||||||
|
// Required: false
|
||||||
|
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete PCI device
|
||||||
|
func (p PCIDevice) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/pcidevice/delete"
|
||||||
|
|
||||||
|
res, err := p.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
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/pcidevice/disable.go
Normal file
43
pkg/cloudbroker/pcidevice/disable.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for disabling PCI device
|
||||||
|
type DisableRequest struct {
|
||||||
|
// PCI device ID
|
||||||
|
// Required: true
|
||||||
|
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
|
||||||
|
|
||||||
|
// Force delete
|
||||||
|
// Required: false
|
||||||
|
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable PCI device
|
||||||
|
func (p PCIDevice) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/pcidevice/disable"
|
||||||
|
|
||||||
|
res, err := p.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
|
||||||
|
}
|
||||||
39
pkg/cloudbroker/pcidevice/enable.go
Normal file
39
pkg/cloudbroker/pcidevice/enable.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for enabling PCI device
|
||||||
|
type EnableRequest struct {
|
||||||
|
// PCI device ID
|
||||||
|
// Required: true
|
||||||
|
DeviceID uint64 `url:"deviceId" json:"deviceId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable PCI device
|
||||||
|
func (p PCIDevice) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/pcidevice/enable"
|
||||||
|
|
||||||
|
res, err := p.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
|
||||||
|
}
|
||||||
26
pkg/cloudbroker/pcidevice/list.go
Normal file
26
pkg/cloudbroker/pcidevice/list.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List gets list all pci devices
|
||||||
|
func (p PCIDevice) List(ctx context.Context) (ListPCIDevices, error) {
|
||||||
|
url := "/cloudbroker/pcidevice/list"
|
||||||
|
|
||||||
|
res, err := p.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListPCIDevices{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/pcidevice/models.go
Normal file
43
pkg/cloudbroker/pcidevice/models.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
// Main information about PCI device
|
||||||
|
type ItemPCIDevice struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
// Compute ID
|
||||||
|
ComputeID uint64 `json:"computeId"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"description"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// HwPath
|
||||||
|
HwPath string `json:"hwPath"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Resource group ID
|
||||||
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
// Stack ID
|
||||||
|
StackID uint64 `json:"stackId"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// System name
|
||||||
|
SystemName string `json:"systemName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List PCI devices
|
||||||
|
type ListPCIDevices []ItemPCIDevice
|
||||||
15
pkg/cloudbroker/pcidevice/pcidevice.go
Normal file
15
pkg/cloudbroker/pcidevice/pcidevice.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to PCI device
|
||||||
|
type PCIDevice struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for PCI device endpoints
|
||||||
|
func New(client interfaces.Caller) *PCIDevice {
|
||||||
|
return &PCIDevice{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/pcidevice/serialize.go
Normal file
42
pkg/cloudbroker/pcidevice/serialize.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package pcidevice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (l ListPCIDevices) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(l) == 0 {
|
||||||
|
return []byte{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(l, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (i ItemPCIDevice) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(i, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(i)
|
||||||
|
}
|
||||||
@@ -131,6 +131,12 @@ type ItemRG struct {
|
|||||||
// List ACL
|
// List ACL
|
||||||
ACL ListACL `json:"acl"`
|
ACL ListACL `json:"acl"`
|
||||||
|
|
||||||
|
// CPU allocation parameter
|
||||||
|
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
CreatedBy string `json:"createdBy"`
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
@@ -176,12 +182,18 @@ type ItemRG struct {
|
|||||||
// Resource limits
|
// Resource limits
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
||||||
|
|
||||||
|
// Resource types list
|
||||||
|
ResTypes []string `json:"resourceTypes"`
|
||||||
|
|
||||||
// Secret
|
// Secret
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Uniq pools
|
||||||
|
UniqPools []string `json:"uniqPools"`
|
||||||
|
|
||||||
// Updated by
|
// Updated by
|
||||||
UpdatedBy string `json:"updatedBy"`
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
|
||||||
@@ -193,12 +205,6 @@ type ItemRG struct {
|
|||||||
|
|
||||||
// List virtual machine IDs
|
// List virtual machine IDs
|
||||||
VMs []uint64 `json:"vms"`
|
VMs []uint64 `json:"vms"`
|
||||||
|
|
||||||
// Resource types list
|
|
||||||
ResTypes []string `json:"resourceTypes"`
|
|
||||||
|
|
||||||
// Uniq pools
|
|
||||||
UniqPools []string `json:"uniqPools"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List resource groups
|
// List resource groups
|
||||||
|
|||||||
45
pkg/cloudbroker/rg/set_cpu_allocation_parameter.go
Normal file
45
pkg/cloudbroker/rg/set_cpu_allocation_parameter.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package rg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation parameter
|
||||||
|
type SetCPUAllocationParameterRequest struct {
|
||||||
|
// Resource group ID
|
||||||
|
// Required: true
|
||||||
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
|
// CPU allocation parameter.
|
||||||
|
// If "strict" VM can't be run if not enough CPU resources.
|
||||||
|
// "loose" allow running VM if not enough resources.
|
||||||
|
// Required: true
|
||||||
|
StrictLoose string `url:"strict_loose" json:"strict_loose" validate:"required,strict_loose"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationParameter sets CPU allocation parameter
|
||||||
|
func (r RG) SetCPUAllocationParameter(ctx context.Context, req SetCPUAllocationParameterRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/rg/setCpuAllocationParameter"
|
||||||
|
|
||||||
|
res, err := r.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
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/rg/set_cpu_allocation_ratio.go
Normal file
43
pkg/cloudbroker/rg/set_cpu_allocation_ratio.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package rg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for setting CPU allocation ratio
|
||||||
|
type SetCPUAllocationRatioRequest struct {
|
||||||
|
// Resource group ID
|
||||||
|
// Required: true
|
||||||
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
|
// CPU allocation ratio, i.e. one pCPU = ratio*vCPU
|
||||||
|
// Required: true
|
||||||
|
Ratio float64 `url:"ratio" json:"ratio" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCPUAllocationRatio sets CPU allocation ratio
|
||||||
|
func (r RG) SetCPUAllocationRatio(ctx context.Context, req SetCPUAllocationRatioRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/rg/setCpuAllocationRatio"
|
||||||
|
|
||||||
|
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -24,23 +24,23 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// Max size of memory in MB
|
// Max size of memory in MB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
||||||
|
|
||||||
// Max size of aggregated virtual disks in GB
|
// Max size of aggregated virtual disks in GB
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
||||||
|
|
||||||
// Max number of CPU cores
|
// Max number of CPU cores
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
||||||
|
|
||||||
// Max sent/received network transfer peering
|
// Max sent/received network transfer peering
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
MaxNetworkPeerTransfer int64 `url:"maxNetworkPeerTransfer,omitempty" json:"maxNetworkPeerTransfer,omitempty"`
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
// Max number of assigned public IPs
|
||||||
// Required: false
|
// Required: false
|
||||||
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
||||||
|
|
||||||
// Register computes in registration system
|
// Register computes in registration system
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
8
pkg/cloudbroker/vgpu.go
Normal file
8
pkg/cloudbroker/vgpu.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vgpu"
|
||||||
|
|
||||||
|
// Accessing the VGPU method group
|
||||||
|
func (cb *CloudBroker) VGPU() *vgpu.VGPU {
|
||||||
|
return vgpu.New(cb.client)
|
||||||
|
}
|
||||||
39
pkg/cloudbroker/vgpu/allocate.go
Normal file
39
pkg/cloudbroker/vgpu/allocate.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for allocating VGPU
|
||||||
|
type AllocateRequest struct {
|
||||||
|
// Virtual GPU ID
|
||||||
|
// Required: true
|
||||||
|
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate allocates GPU
|
||||||
|
func (v VGPU) Allocate(ctx context.Context, req AllocateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vgpu/allocate"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
51
pkg/cloudbroker/vgpu/create.go
Normal file
51
pkg/cloudbroker/vgpu/create.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for creating VGPU
|
||||||
|
type CreateRequest struct {
|
||||||
|
// ID of pGPU
|
||||||
|
// Required: true
|
||||||
|
PGPUID uint64 `url:"pgpuId" json:"pgpuId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the target resource group.
|
||||||
|
// Required: true
|
||||||
|
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
||||||
|
|
||||||
|
// Virtual profile id
|
||||||
|
// Required: false
|
||||||
|
ProfileID uint64 `url:"profileId,omitempty" json:"profileId,omitempty"`
|
||||||
|
|
||||||
|
// Allocate vgpu after creation
|
||||||
|
// Required: false
|
||||||
|
Allocate bool `url:"allocate,omitempty" json:"allocate,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates VGPU
|
||||||
|
func (v VGPU) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return 0, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vgpu/create"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/vgpu/deallocate.go
Normal file
43
pkg/cloudbroker/vgpu/deallocate.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for deallocating VGPU
|
||||||
|
type DeallocateRequest struct {
|
||||||
|
// Virtual GPU ID
|
||||||
|
// Required: true
|
||||||
|
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
|
||||||
|
|
||||||
|
// Force delete (detach from compute)
|
||||||
|
// Required: false
|
||||||
|
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deallocate releases GPU resources
|
||||||
|
func (v VGPU) Deallocate(ctx context.Context, req DeallocateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vgpu/deallocate"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/vgpu/destroy.go
Normal file
43
pkg/cloudbroker/vgpu/destroy.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request for destroying VGPU
|
||||||
|
type DestroyRequest struct {
|
||||||
|
// Virtual GPU ID
|
||||||
|
// Required: true
|
||||||
|
VGPUID uint64 `url:"vgpuId" json:"vgpuId" validate:"required"`
|
||||||
|
|
||||||
|
// Force delete (deallocate and detach from compute)
|
||||||
|
// Required: false
|
||||||
|
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy destroys VGPU
|
||||||
|
func (v VGPU) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/vgpu/destroy"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
37
pkg/cloudbroker/vgpu/list.go
Normal file
37
pkg/cloudbroker/vgpu/list.go
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting list of VGPU
|
||||||
|
type ListRequest struct {
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List gets list all VGPU
|
||||||
|
func (v VGPU) List(ctx context.Context, req ListRequest) (ListVGPU, error) {
|
||||||
|
url := "/cloudbroker/vgpu/list"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListVGPU{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
66
pkg/cloudbroker/vgpu/models.go
Normal file
66
pkg/cloudbroker/vgpu/models.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
type ItemVGPU struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
// Account ID
|
||||||
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
// Created time
|
||||||
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
|
// Deleted time
|
||||||
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
|
|
||||||
|
//Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// VGPU ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Last claimed by
|
||||||
|
LastClaimedBy uint64 `json:"lastClaimedBy"`
|
||||||
|
|
||||||
|
// Last update time
|
||||||
|
LastUpdateTime uint64 `json:"lastUpdateTime"`
|
||||||
|
|
||||||
|
// Mode
|
||||||
|
Mode string `json:"mode"`
|
||||||
|
|
||||||
|
// PCI Slot
|
||||||
|
PCISlot interface{} `json:"pciSlot"`
|
||||||
|
|
||||||
|
// PGPUID
|
||||||
|
PGPUID uint64 `json:"pgpuid"`
|
||||||
|
|
||||||
|
// Profile ID
|
||||||
|
ProfileID interface{} `json:"profileId"`
|
||||||
|
|
||||||
|
// RAM
|
||||||
|
RAM uint64 `json:"ram"`
|
||||||
|
|
||||||
|
// Reference ID
|
||||||
|
ReferenceID interface{} `json:"referenceId"`
|
||||||
|
|
||||||
|
// RGID
|
||||||
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
|
||||||
|
// VMID
|
||||||
|
VMID uint64 `json:"vmid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of VGPU
|
||||||
|
type ListVGPU []ItemVGPU
|
||||||
42
pkg/cloudbroker/vgpu/serialize.go
Normal file
42
pkg/cloudbroker/vgpu/serialize.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (l ListVGPU) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(l) == 0 {
|
||||||
|
return []byte{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(l, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||||
|
//
|
||||||
|
// In order to serialize with indent make sure to follow these guidelines:
|
||||||
|
// - First argument -> prefix
|
||||||
|
// - Second argument -> indent
|
||||||
|
func (i ItemVGPU) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(i, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(i)
|
||||||
|
}
|
||||||
15
pkg/cloudbroker/vgpu/vgpu.go
Normal file
15
pkg/cloudbroker/vgpu/vgpu.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package vgpu
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to VGPU
|
||||||
|
type VGPU struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for VGPU endpoints
|
||||||
|
func New(client interfaces.Caller) *VGPU {
|
||||||
|
return &VGPU{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -138,7 +138,7 @@ type ItemInterface struct {
|
|||||||
NetType string `json:"netType"`
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
// PCI slot
|
// PCI slot
|
||||||
PCISlot uint64 `json:"pciSlot"`
|
PCISlot int64 `json:"pciSlot"`
|
||||||
|
|
||||||
// QOS
|
// QOS
|
||||||
QOS QOS `json:"qos"`
|
QOS QOS `json:"qos"`
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"appId": "<APP_ID>",
|
"appId": "<APP_ID>",
|
||||||
"appSecret": "<APP_SECRET>",
|
"appSecret": "<APP_SECRET>",
|
||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": false
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"username": "<USERNAME>",
|
"username": "<USERNAME>",
|
||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": true
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
|
|||||||
Reference in New Issue
Block a user