Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 35fa4af0d6 | |||
| d3e6309ef8 | |||
| 78a4152471 | |||
| 3e55195831 | |||
| 9f5e76aee4 | |||
| df8b045e77 | |||
| 4d9b8fc9d8 | |||
| e8270453cc | |||
| 7de095302b | |||
| a3711057ba | |||
| 1c59ca338a | |||
| f1529c9aac | |||
| 040235f92f |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
|||||||
cmd/
|
cmd/
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.fleet/
|
||||||
|
.DS_Store
|
||||||
|
|||||||
210
CHANGELOG.md
210
CHANGELOG.md
@@ -1,162 +1,52 @@
|
|||||||
## Version 1.5.0
|
## Version 1.6.0
|
||||||
|
|
||||||
### Feature
|
|
||||||
|
|
||||||
- Updated lists responses models in:
|
|
||||||
- - cloudapi/account/list
|
|
||||||
- - cloudbroker/account/list
|
|
||||||
- - cloudapi/bservice/list
|
|
||||||
- - cloudapi/compute/list
|
|
||||||
- - cloudbroker/compute/list
|
|
||||||
- - cloudapi/computeci/list
|
|
||||||
- - cloudapi/disks/list
|
|
||||||
- - cloudbroker/disks/list
|
|
||||||
- - cloudapi/extnet/list
|
|
||||||
- - cloudbroker/extnet/list
|
|
||||||
- - cloudapi/flipgroup/list
|
|
||||||
- - cloudapi/image/list
|
|
||||||
- - cloudbroker/image/list
|
|
||||||
- - cloudapi/k8ci/list
|
|
||||||
- - cloudbroker/k8ci/list
|
|
||||||
- - cloudapi/k8s/list
|
|
||||||
- - cloudapi/k8s/listDeleted
|
|
||||||
- - cloudbroker/k8s/list
|
|
||||||
- - cloudbroker/k8s/listDeleted
|
|
||||||
- - cloudapi/tasks/list
|
|
||||||
- - cloudbroker/tasks/list
|
|
||||||
- - cloudapi/rg/list
|
|
||||||
- - cloudbroker/rg/list
|
|
||||||
- - cloudapi/vins/list
|
|
||||||
- - cloudbroker/vins/list
|
|
||||||
- - cloudapi/account/listDeleted
|
|
||||||
- - cloudapi/account/listCompute
|
|
||||||
- - cloudapi/account/listDisks
|
|
||||||
- - cloudapi/account/listFlipGroups
|
|
||||||
- - cloudapi/account/listRG
|
|
||||||
- - cloudapi/account/listVINS
|
|
||||||
- - cloudapi/compute/listDeleted
|
|
||||||
- - cloudapi/disks/listDeleted
|
|
||||||
- - cloudapi/disks/listTypes
|
|
||||||
- - cloudapi/k8ci/listDeleted
|
|
||||||
- - cloudapi/lb/list
|
|
||||||
- - cloudapi/lb/listDeleted
|
|
||||||
- - cloudbroker/lb/list
|
|
||||||
- - cloudbroker/lb/listDeleted
|
|
||||||
- - cloudapi/rg/listComputes
|
|
||||||
- - cloudapi/rg/listDeleted
|
|
||||||
- - cloudapi/rg/listLb
|
|
||||||
- - cloudapi/rg/listPFW
|
|
||||||
- - cloudapi/rg/listVins
|
|
||||||
- - cloudapi/vins/listDeleted
|
|
||||||
- - cloudbroker/account/listComputes
|
|
||||||
- - cloudbroker/account/listDeleted
|
|
||||||
- - cloudbroker/account/listDisks
|
|
||||||
- - cloudbroker/account/listFlipGroups
|
|
||||||
- - cloudbroker/account/listRG
|
|
||||||
- - cloudbroker/account/listVINS
|
|
||||||
- - cloudbroker/compute/listDeleted
|
|
||||||
- - cloudapi/compute/listPciDevice
|
|
||||||
- - cloudbroker/compute/listPciDevice
|
|
||||||
- - cloudapi/compute/listVGpu
|
|
||||||
- - cloudbroker/compute/listVGpu
|
|
||||||
- - cloudbroker/disks/listTypes
|
|
||||||
- - cloudbroker/grid/list
|
|
||||||
- - cloudbroker/grid/listEmails
|
|
||||||
- - cloudbroker/k8ci/listDeleted
|
|
||||||
- - cloudbroker/pcidevice/list
|
|
||||||
- - cloudbroker/rg/affinityGroupsList
|
|
||||||
- - cloudbroker/rg/listDeleted
|
|
||||||
- - cloudbroker/rg/listComputes
|
|
||||||
- - cloudbroker/rg/listLB
|
|
||||||
- - cloudbroker/rg/listPfw
|
|
||||||
- - cloudbroker/rg/listResourceConsumption
|
|
||||||
- - cloudbroker/rg/listVins
|
|
||||||
- - cloudbroker/sep/list
|
|
||||||
- - cloudbroker/vgpu/list
|
|
||||||
- - cloudbroker/vins/extnetList
|
|
||||||
- - cloudbroker/vins/IpList
|
|
||||||
- - cloudbroker/vins/natRuleList
|
|
||||||
- - cloudapi/account/listTemplates
|
|
||||||
- - cloudapi/compute/pfwList
|
|
||||||
- - cloudapi/compute/sanpshotList
|
|
||||||
- - cloudapi/compute/userList
|
|
||||||
- - cloudapi/vins/extnetList
|
|
||||||
- - cloudapi/vins/ipList
|
|
||||||
- - cloudapi/vins/natRuleList
|
|
||||||
- - cloudapi/sizes/list
|
|
||||||
- - cloudapi/rg/affinityGroupsList
|
|
||||||
- - cloudapi/extnet/listComputes
|
|
||||||
|
|
||||||
- Added new endpoints:
|
|
||||||
- - cloudapi/rg/getResourceConsumption
|
|
||||||
- - cloudapi/rg/listResourceConsumption
|
|
||||||
- - cloudbroker/rg/getResourceConsumption
|
|
||||||
- - cloudbroker/rg/listResourceConsumption
|
|
||||||
- - cloudapi/account/getResourceConsumption
|
|
||||||
- - cloudapi/account/listResourceConsumption
|
|
||||||
- - cloudbroker/account/getResourceConsumption
|
|
||||||
- - cloudbroker/account/listResourceConsumption
|
|
||||||
- - cloudbroker/grid/getResourceConsumption
|
|
||||||
- - cloudbroker/grid/listResourceConsumption
|
|
||||||
- - cloudapi/compute/getCustomFields
|
|
||||||
- - cloudapi/compute/deleteCustomFields
|
|
||||||
- - cloudapi/compute/setCustomFields
|
|
||||||
|
|
||||||
- Added field CU_DM to ResourceLimits model (account, rg)
|
|
||||||
|
|
||||||
- Added field ReferenceID to SnapshotExtended model in cloudapi/compute/get
|
|
||||||
|
|
||||||
- Added field Interfaces in requests:
|
|
||||||
- - cloudapi/kvmppc/create
|
|
||||||
- - cloudapi/kvmppc/createBlank
|
|
||||||
- - cloudapi/kvmx86/create
|
|
||||||
- - cloudapi/kvmx86/createBlank
|
|
||||||
- - cloudbroker/kvmppc/create
|
|
||||||
- - cloudbroker/kvmppc/createBlank
|
|
||||||
- - cloudbroker/kvmx86/create
|
|
||||||
- - cloudbroker/kvmx86/createBlank
|
|
||||||
|
|
||||||
- Added UpdatedBy field to task model in cloudbroker/task/get
|
|
||||||
|
|
||||||
- Made optional fields in requests:
|
|
||||||
- - Reason (cloudbroker/account/delete)
|
|
||||||
- - Reason (cloudbroker/account/restore)
|
|
||||||
- - Gateway (cloudbroker/extnet/create)
|
|
||||||
- - Reason (cloudbroker/image/delete)
|
|
||||||
- - Num (cloudapi/k8s/workerAdd)
|
|
||||||
- - NetID (cloudbroker/vins/extnetConnect)
|
|
||||||
|
|
||||||
- Updated cloudapi/rg/get model
|
|
||||||
|
|
||||||
- Deleted field Username from cloudbroker/account/update request
|
|
||||||
|
|
||||||
- Deleted field EmailAddress from cloudbroker/account/update request
|
|
||||||
|
|
||||||
- Added field DiskType to cloudbroker/compute/diskAttach request
|
|
||||||
|
|
||||||
- Added field Reason to cloudbroker/compute/diskQos request
|
|
||||||
|
|
||||||
- Added field Enabled to cloudbroker/compute/netAttach response model
|
|
||||||
|
|
||||||
- Added field CPUAllocationRatio to cloudbroker/image/listStacks response model
|
|
||||||
|
|
||||||
- Added field Descr to cloudbroker/image/listStacks response model
|
|
||||||
|
|
||||||
- Added field MemAllocationRatio to cloudbroker/image/listStacks response model
|
|
||||||
|
|
||||||
- Updated cloudapi/k8s/workersGroupByName response model
|
|
||||||
|
|
||||||
- Deleted field LBImageID from cloudbroker/k8ci/create request
|
|
||||||
|
|
||||||
- Deleted field ImageID from cloudbroker/lb/create request
|
|
||||||
|
|
||||||
- Deleted field Reason from cloudbroker/vins/extnetList request
|
|
||||||
|
|
||||||
- Added field CustomFields to cloudapi/kvmx86/create request
|
|
||||||
|
|
||||||
- Added field Driver to cloudapi/kvmx86/create request
|
|
||||||
|
|
||||||
- Added field Driver to cloudapi/kvmx86/createBlank request
|
|
||||||
|
|
||||||
### Bugfix
|
### Bugfix
|
||||||
- Changed the Excluded field type in cloudbroker/extnet/get response model
|
- Fix client and legacy-client, the cyclicity of sending requests has been removed
|
||||||
|
- Edit description field SSLSkipVerify in config/config and config/legacy-config
|
||||||
|
- Remove tags required fields ExtNetID VINSID Start in model CreateRequest in cloudapi/lb/create and cloudbroker/lb/create
|
||||||
|
- Add tags required fields BindingName BindingAddress BindingPort in model FrontendBindRequest in cloudapi/lb/frontend_bind
|
||||||
|
- Add tags required fields BindingAddress BindingPort in model FrontendBindUpdateRequest in cloudapi/lb/frontend_bind_update
|
||||||
|
- Remove tags omitempty in field Start in model kvmx86 and kvmppc in cloudapi and cloudbroker /create /mass_create
|
||||||
|
- Add field Driver in models cloudbroker/kvmx86/create and cloudbroker/kvmx86/create_blank
|
||||||
|
- Add field ExternalIp in model ItemDetailedInfo cloudbroker/k8s/models and cloudapi/k8s/models
|
||||||
|
- Add fields StackID and Reason in model CreateRequest cloudbroker/kvmppc
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- Add field UserData in cloudapi/bservice/group_add
|
||||||
|
- Add fields VinsId, LbSysctlParams, HighlyAvailable, AdditionalSANs, InitConfiguration, ClusterConfiguration, KubeletConfiguration, KubeProxyConfiguration, JoinConfiguration, UserData, ExtNetOnly, OidcCertificate in model request cloudapi/k8s/create and cloudbroker/k8s/create
|
||||||
|
- Add fields SysctlParams, HighlyAvailable in model CreateRequest in cloudapi/lb/create and cloudbroker/lb/create
|
||||||
|
- Add fields BackendHAIP, FrontendHAIP, PartK8s, SysctlParams in model RecordLB in cloudapi/lb/models and cloudbroker/lb/models
|
||||||
|
- Add models InfoStack, ItemStack, ListStacks cloudapi/stack/models
|
||||||
|
- Add field Routes and type Route in CreateInAccountRequest and CreateInRGRequest models in cloudapi/vins/create_in_rg and /cloudapi/vins/create_in_account
|
||||||
|
- Add field Enabled in model ItemVNFInterface in cloudapi/vins/models
|
||||||
|
- Add fields Routes in models RecordNAT, RecordDHCP, RecordGW and add type ListStaticRoutes, ListRoutes, ItemRoutes in cloudapi/vins/models
|
||||||
|
|
||||||
|
- Added new endpoints:
|
||||||
|
- cloudapi/k8s/get_worker_nodes_meta_data
|
||||||
|
- cloudapi/k8s/update_worker_nodes_meta_data
|
||||||
|
- cloudapi/lb/make_highly_available
|
||||||
|
- cloudapi/lb/updateSysctParams
|
||||||
|
- cloudapi/stack/get
|
||||||
|
- cloudapi/stack/list
|
||||||
|
- cloudapi/vins/static_route_list
|
||||||
|
- cloudapi/vins/static_route_access_grant
|
||||||
|
- cloudapi/vins/static_route_access_revoke
|
||||||
|
- cloudapi/vins/static_route_add
|
||||||
|
- cloudapi/vins/static_route_del
|
||||||
|
- cloudbroker/compute/set_custom_fields
|
||||||
|
- cloudbroker/k8s/get_worker_nodes_meta_data
|
||||||
|
- cloudbroker/k8s/update_worker_nodes_meta_data
|
||||||
|
- cloudbroker/lb/make_highly_available
|
||||||
|
- cloudbroker/lb/updateSysctParams
|
||||||
|
- cloudbroker/vins/static_route_list
|
||||||
|
- cloudbroker/vins/static_route_access_grant
|
||||||
|
- cloudbroker/vins/static_route_access_revoke
|
||||||
|
- cloudbroker/vins/static_route_add
|
||||||
|
- cloudbroker/vins/static_route_del
|
||||||
|
- cloudbroker/extnet/static_route_list
|
||||||
|
- cloudbroker/extnet/static_route_access_grant
|
||||||
|
- cloudbroker/extnet/static_route_access_revoke
|
||||||
|
- cloudbroker/extnet/static_route_add
|
||||||
|
- cloudbroker/extnet/static_route_del
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
56
README.md
56
README.md
@@ -10,6 +10,7 @@ Decort SDK - это библиотека, написанная на языке G
|
|||||||
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||||
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
||||||
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
|
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
|
||||||
|
- Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы
|
||||||
|
|
||||||
## Оглавление
|
## Оглавление
|
||||||
|
|
||||||
@@ -62,12 +63,11 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
- `BService` - управление группами виртуальных машин (computes);
|
- `BService` - управление группами виртуальных машин (computes);
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
- `ComputeCI` - управление конвейром для создания виртуальных машин;
|
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - управление конвейром для создания кластера;
|
- `K8CI` - получение информации о конвейере для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
@@ -75,6 +75,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
- `Locations` - получение информации о grid площадки;
|
- `Locations` - получение информации о grid площадки;
|
||||||
- `RG` - управление ресурсными группами аккаунта;
|
- `RG` - управление ресурсными группами аккаунта;
|
||||||
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
|
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
|
||||||
|
- `Stack` - получение информации о вычислительных узлах;
|
||||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||||
- `VINS` - управление виртуальными изолированными сетями.
|
- `VINS` - управление виртуальными изолированными сетями.
|
||||||
|
|
||||||
@@ -84,30 +85,39 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
||||||
|
|
||||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||||
|
- `APIAccess` - управление доступом к API и его объектам;
|
||||||
|
- `Backup` - управление резервным копированием;
|
||||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||||
- `Disks` - управление виртуальными дисками;
|
- `Disks` - управление виртуальными дисками;
|
||||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||||
|
- `FLIPGroup` - управление группами с «плавающими» ip адресами;
|
||||||
- `Grid` - управление площадками;
|
- `Grid` - управление площадками;
|
||||||
|
- `Group` - управление группами пользователей;
|
||||||
- `Image` - управление образами операционных систем;
|
- `Image` - управление образами операционных систем;
|
||||||
- `K8CI` - управление конвейром для создания кластера;
|
- `K8CI` - управление конвейром для создания кластера;
|
||||||
- `K8S` - управление кластерами kubernetes;
|
- `K8S` - управление кластерами kubernetes;
|
||||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||||
- `KVMx86` - создание виртуальной машины x86;
|
- `KVMx86` - создание виртуальной машины x86;
|
||||||
- `LB` - управление балансировщиками нагрузки;
|
- `LB` - управление балансировщиками нагрузки;
|
||||||
|
- `PCIDevice` - управление устройствами;
|
||||||
- `RG` - управление ресурсными группами аккаунта;
|
- `RG` - управление ресурсными группами аккаунта;
|
||||||
- `SEP` - управление storage endpoint (sep);
|
- `SEP` - управление storage endpoint (sep);
|
||||||
|
- `Stack` - получение информации о вычислительных узлах;
|
||||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||||
|
- `User` - управление пользователями (индивидуально);
|
||||||
|
- `VGPU` - управление виртуальными графическими процессорами;
|
||||||
- `VINS` - управление виртуальными изолированными сетями.
|
- `VINS` - управление виртуальными изолированными сетями.
|
||||||
|
|
||||||
## Работа с библиотекой
|
## Работа с библиотекой
|
||||||
|
|
||||||
Алгоритм работы с библиотекой выглядит следующим образом:
|
Алгоритм работы с библиотекой выглядит следующим образом:
|
||||||
|
|
||||||
1. Настройка конфигурации клиента.
|
1. Выполнение одного из действий:
|
||||||
2. Парсинг конфигурации из файла.
|
- настройка конфигурации клиента;
|
||||||
3. Создание клиента.
|
- парсинг конфигурации из файла.
|
||||||
4. Создание структуры запроса.
|
2. Создание клиента.
|
||||||
5. Выполнение запроса.
|
3. Создание структуры запроса.
|
||||||
|
4. Выполнение запроса.
|
||||||
|
|
||||||
### Настройка конфигурации клиента
|
### Настройка конфигурации клиента
|
||||||
|
|
||||||
@@ -120,7 +130,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации клиента
|
#### Пример конфигурации клиента
|
||||||
@@ -231,7 +241,6 @@ func main() {
|
|||||||
- `pkg/cloudapi/account` - для `Account`
|
- `pkg/cloudapi/account` - для `Account`
|
||||||
- `pkg/cloudapi/bservice` - для `Basic Service`
|
- `pkg/cloudapi/bservice` - для `Basic Service`
|
||||||
- `pkg/cloudapi/compute` - для `Compute`
|
- `pkg/cloudapi/compute` - для `Compute`
|
||||||
- `pkg/cloudapi/computeci` - для `ComputeCI`
|
|
||||||
- `pkg/cloudapi/disks` - для `Disks`
|
- `pkg/cloudapi/disks` - для `Disks`
|
||||||
- `pkg/cloudapi/extnet` - для `ExtNet`
|
- `pkg/cloudapi/extnet` - для `ExtNet`
|
||||||
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
||||||
@@ -243,24 +252,33 @@ func main() {
|
|||||||
- `pkg/cloudapi/lb` - для `LB`
|
- `pkg/cloudapi/lb` - для `LB`
|
||||||
- `pkg/cloudapi/locations` - для `Locations`
|
- `pkg/cloudapi/locations` - для `Locations`
|
||||||
- `pkg/cloudapi/rg` - для `RG`
|
- `pkg/cloudapi/rg` - для `RG`
|
||||||
- `pkg/cloudapi/sizes` - для `RG`
|
- `pkg/cloudapi/sizes` - для `Sizes`
|
||||||
|
- `pkg/cloudapi/stack` - для `Stack`
|
||||||
- `pkg/cloudapi/tasks` - для `Tasks`
|
- `pkg/cloudapi/tasks` - для `Tasks`
|
||||||
- `pkg/cloudapi/vins` - для `VINS`
|
- `pkg/cloudapi/vins` - для `VINS`
|
||||||
- **cloudbroker**:
|
- **cloudbroker**:
|
||||||
- `pkg/cloudbroker/account` - для `Account`
|
- `pkg/cloudbroker/account` - для `Account`
|
||||||
|
- `pkg/cloudbroker/apiaccess` - для `APIAccess`
|
||||||
|
- `pkg/cloudbroker/backup` - для `Backup`
|
||||||
- `pkg/cloudbroker/compute` - для `Compute`
|
- `pkg/cloudbroker/compute` - для `Compute`
|
||||||
- `pkg/cloudbroker/disks` - для `Disks`
|
- `pkg/cloudbroker/disks` - для `Disks`
|
||||||
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
||||||
|
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
|
||||||
- `pkg/cloudbroker/grid` - для `Grid`
|
- `pkg/cloudbroker/grid` - для `Grid`
|
||||||
|
- `pkg/cloudbroker/group` - для `Group`
|
||||||
- `pkg/cloudbroker/image` - для `Image`
|
- `pkg/cloudbroker/image` - для `Image`
|
||||||
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
||||||
- `pkg/cloudbroker/k8s` - для `K8S`
|
- `pkg/cloudbroker/k8s` - для `K8S`
|
||||||
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
||||||
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
||||||
- `pkg/cloudbroker/lb` - для `LB`
|
- `pkg/cloudbroker/lb` - для `LB`
|
||||||
|
- `pkg/cloudbroker/pcidevice` - для `PCIDevice`
|
||||||
- `pkg/cloudbroker/rg` - для `RG`
|
- `pkg/cloudbroker/rg` - для `RG`
|
||||||
- `pkg/cloudbroker/sep` - для `SEP`
|
- `pkg/cloudbroker/sep` - для `SEP`
|
||||||
|
- `pkg/cloudbroker/stack` - для `Stack`
|
||||||
- `pkg/cloudbroker/tasks` - для `Tasks`
|
- `pkg/cloudbroker/tasks` - для `Tasks`
|
||||||
|
- `pkg/cloudbroker/user` - для `User`
|
||||||
|
- `pkg/cloudbroker/vgpu` - для `VGPU`
|
||||||
- `pkg/cloudbroker/vins` - для `VINS`
|
- `pkg/cloudbroker/vins` - для `VINS`
|
||||||
|
|
||||||
Все поля структуры имеют описание, в которых содержится:
|
Все поля структуры имеют описание, в которых содержится:
|
||||||
@@ -397,7 +415,7 @@ func main() {
|
|||||||
|
|
||||||
Чтобы выполнить запрос, необходимо:
|
Чтобы выполнить запрос, необходимо:
|
||||||
|
|
||||||
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно соверать запросы.
|
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
|
||||||
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
|
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
|
||||||
|
|
||||||
Доступные методы для `.CloudAPI()`:
|
Доступные методы для `.CloudAPI()`:
|
||||||
@@ -405,7 +423,6 @@ func main() {
|
|||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
- `.BService()` - для работы с `BService`
|
- `.BService()` - для работы с `BService`
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
- `.ComputeCI()` - для работы с `ComputeCI`
|
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
||||||
@@ -418,37 +435,46 @@ func main() {
|
|||||||
- `.Locations()` - для работы с `Locations`
|
- `.Locations()` - для работы с `Locations`
|
||||||
- `.RG()` - для работы с `RG`
|
- `.RG()` - для работы с `RG`
|
||||||
- `.Sizes()` - для работы с `Sizes`
|
- `.Sizes()` - для работы с `Sizes`
|
||||||
|
- `.Stack()` - для работы с `Stack`
|
||||||
- `.Tasks()` - для работы с `Tasks`
|
- `.Tasks()` - для работы с `Tasks`
|
||||||
- `.VINS()` - для работы с `VINS`
|
- `.VINS()` - для работы с `VINS`
|
||||||
|
|
||||||
Доступные методы для `.CloudBroker()`:
|
Доступные методы для `.CloudBroker()`:
|
||||||
|
|
||||||
- `.Account()` - для работы с `Account`
|
- `.Account()` - для работы с `Account`
|
||||||
|
- `.APIAccess()` - для работы с `APIAccess`
|
||||||
|
- `.Backup()` - для работы с `Backup`
|
||||||
- `.Compute()` - для работы с `Compute`
|
- `.Compute()` - для работы с `Compute`
|
||||||
- `.Disks()` - для работы с `Disks`
|
- `.Disks()` - для работы с `Disks`
|
||||||
- `.ExtNet()` - для работы с `ExtNet`
|
- `.ExtNet()` - для работы с `ExtNet`
|
||||||
|
- `.FLIPGroup()` - для работы с `FLIPGroup`
|
||||||
- `.Grid()` - для работы с `Grid`
|
- `.Grid()` - для работы с `Grid`
|
||||||
|
- `.Group()` - для работы с `Group`
|
||||||
- `.Image()` - для работы с `Image`
|
- `.Image()` - для работы с `Image`
|
||||||
- `.K8CI()` - для работы с `K8CI`
|
- `.K8CI()` - для работы с `K8CI`
|
||||||
- `.K8S()` - для работы с `K8S`
|
- `.K8S()` - для работы с `K8S`
|
||||||
- `.KVMPPC()` - для работы с `KVMPPC`
|
- `.KVMPPC()` - для работы с `KVMPPC`
|
||||||
- `.KVMx86()` - для работы с `KVMX86`
|
- `.KVMx86()` - для работы с `KVMX86`
|
||||||
- `.LB()` - для работы с `LB`
|
- `.LB()` - для работы с `LB`
|
||||||
|
- `.PCIDevice()` - для работы с `PCIDevice`
|
||||||
- `.RG()` - для работы с `RG`
|
- `.RG()` - для работы с `RG`
|
||||||
- `.SEP()` - для работы с `SEP`
|
- `.SEP()` - для работы с `SEP`
|
||||||
|
- `.Stack()` - для работы с `Stack`
|
||||||
- `.Tasks()` - для работы с `Tasks`
|
- `.Tasks()` - для работы с `Tasks`
|
||||||
|
- `.User()` - для работы с `User`
|
||||||
|
- `.VGPU()` - для работы с `VGPU`
|
||||||
- `.VINS()` - для работы с `VINS`
|
- `.VINS()` - для работы с `VINS`
|
||||||
|
|
||||||
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
||||||
|
|
||||||
- контекст;
|
- контекст;
|
||||||
- структуру запроса.
|
- структуру запроса.
|
||||||
У кождой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
У каждой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
||||||
|
|
||||||
4. Обработать результат и ошибки.
|
4. Обработать результат и ошибки.
|
||||||
|
|
||||||
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
||||||
Общий вид вонвейра будет выглядеть так:
|
Общий вид конвейера будет выглядеть так:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
client.<API>.<группа>.<метод>
|
client.<API>.<группа>.<метод>
|
||||||
@@ -705,7 +731,7 @@ func main() {
|
|||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
#### Пример конфигурации legacy клиента
|
#### Пример конфигурации legacy клиента
|
||||||
|
|||||||
407
client.go
407
client.go
@@ -1,24 +1,34 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||||
|
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
|
k8s_cb"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP-client for platform
|
// HTTP-client for platform
|
||||||
type DecortClient struct {
|
type DecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
cfg config.Config
|
||||||
|
expiryTime time.Time
|
||||||
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Сlient builder
|
// Сlient builder
|
||||||
@@ -27,9 +37,25 @@ func New(cfg config.Config) *DecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expiryTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
return &DecortClient{
|
return &DecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
client: client.NewHttpClient(cfg),
|
client: &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
//nolint:gosec
|
||||||
|
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cfg: cfg,
|
||||||
|
expiryTime: expiryTime,
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +71,283 @@ func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||||
|
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
|
||||||
|
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
|
||||||
|
|
||||||
|
if okCa {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCaCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCaCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCaCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCaCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCaCreateReq.K8SCIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCaCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCaCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCaCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCaCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCaCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCaCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCaCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCaCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCaCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCaCreateReq.MasterCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCaCreateReq.MasterNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCaCreateReq.MasterRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCaCreateReq.MasterDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCaCreateReq.WorkerDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCaCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCaCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCaCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCaCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailable", strconv.FormatBool(k8sCaCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCaCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCaCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCaCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCaCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCaCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCaCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCaCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCaCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCaCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCaCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCaCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = dc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := dc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
} else if okCb {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCbCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCbCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCbCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCbCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCbCreateReq.K8CIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCbCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCbCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCbCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCbCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCbCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCbCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCbCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCbCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCbCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(k8sCbCreateReq.MasterCPU, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(k8sCbCreateReq.MasterNum, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(k8sCbCreateReq.MasterRAM, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(k8sCbCreateReq.MasterDisk, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(k8sCbCreateReq.WorkerCPU, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(k8sCbCreateReq.WorkerNum, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(k8sCbCreateReq.WorkerRAM, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(k8sCbCreateReq.WorkerDisk, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCbCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCbCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCbCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCbCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailable", strconv.FormatBool(k8sCbCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCbCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCbCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCbCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCbCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCbCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCbCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCbCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCbCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCbCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCbCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCbCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = dc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := dc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
values, err := query.Values(params)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -56,7 +359,11 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := dc.client.Do(req)
|
if err = dc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := dc.do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -73,3 +380,91 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
|||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dc *DecortClient) getToken(ctx context.Context) error {
|
||||||
|
dc.mutex.Lock()
|
||||||
|
defer dc.mutex.Unlock()
|
||||||
|
|
||||||
|
if dc.cfg.Token == "" || time.Now().After(dc.expiryTime) {
|
||||||
|
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret)
|
||||||
|
bodyReader := strings.NewReader(body)
|
||||||
|
|
||||||
|
dc.cfg.SSOURL = strings.TrimSuffix(dc.cfg.SSOURL, "/")
|
||||||
|
|
||||||
|
req, _ := http.NewRequestWithContext(ctx, "POST", dc.cfg.SSOURL+"/v1/oauth/access_token", bodyReader)
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
resp, err := dc.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot get token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
token := string(tokenBytes)
|
||||||
|
|
||||||
|
dc.cfg.Token = token
|
||||||
|
dc.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := dc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *DecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", ctype)
|
||||||
|
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := dc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ type Config struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
Retries uint64 `json:"retries" yaml:"retries"`
|
||||||
|
|
||||||
// Skip verify, true by default
|
// Skip verify
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type LegacyConfig struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
Retries uint64 `json:"retries" yaml:"retries"`
|
||||||
|
|
||||||
// Skip verify, true by default
|
// Skip verify
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
*d = Duration(tmp)
|
*d = Duration(tmp)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Invalid duration %v", value)
|
return fmt.Errorf("invalid duration %v", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
|
|||||||
*d = Duration(tmp)
|
*d = Duration(tmp)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Invalid duration %v", value)
|
return fmt.Errorf("invalid duration %v", value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewHttpClient(cfg config.Config) *http.Client {
|
|
||||||
|
|
||||||
transCfg := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var expiredTime time.Time
|
|
||||||
|
|
||||||
if cfg.Token != "" {
|
|
||||||
expiredTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &http.Client{
|
|
||||||
Transport: &transport{
|
|
||||||
base: transCfg,
|
|
||||||
retries: cfg.Retries,
|
|
||||||
clientID: cfg.AppID,
|
|
||||||
clientSecret: cfg.AppSecret,
|
|
||||||
ssoURL: cfg.SSOURL,
|
|
||||||
token: cfg.Token,
|
|
||||||
expiryTime: expiredTime,
|
|
||||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
},
|
|
||||||
|
|
||||||
Timeout: cfg.Timeout.Get(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/tls"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewLegacyHttpClient creates legacy HTTP Client
|
|
||||||
func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
|
||||||
transCfg := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return &http.Client{
|
|
||||||
Transport: &transportLegacy{
|
|
||||||
base: transCfg,
|
|
||||||
username: url.QueryEscape(cfg.Username),
|
|
||||||
password: url.QueryEscape(cfg.Password),
|
|
||||||
retries: cfg.Retries,
|
|
||||||
token: cfg.Token,
|
|
||||||
decortURL: cfg.DecortURL,
|
|
||||||
},
|
|
||||||
|
|
||||||
Timeout: cfg.Timeout.Get(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type transportLegacy struct {
|
|
||||||
base http.RoundTripper
|
|
||||||
username string
|
|
||||||
password string
|
|
||||||
retries uint64
|
|
||||||
token string
|
|
||||||
decortURL string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
|
|
||||||
if t.token == "" {
|
|
||||||
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(request.Context(), "POST", t.decortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
resp, err := t.base.RoundTrip(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return nil, fmt.Errorf("unable to get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
token := string(tokenBytes)
|
|
||||||
t.token = token
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenValue := fmt.Sprintf("&authkey=%s", t.token)
|
|
||||||
tokenReader := strings.NewReader(tokenValue)
|
|
||||||
|
|
||||||
newBody := io.MultiReader(request.Body, tokenReader)
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), newBody)
|
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
|
|
||||||
var resp *http.Response
|
|
||||||
var err error
|
|
||||||
for i := uint64(0); i < t.retries; i++ {
|
|
||||||
resp, err = t.base.RoundTrip(req)
|
|
||||||
if err == nil {
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type transport struct {
|
|
||||||
base http.RoundTripper
|
|
||||||
retries uint64
|
|
||||||
clientID string
|
|
||||||
clientSecret string
|
|
||||||
token string
|
|
||||||
ssoURL string
|
|
||||||
expiryTime time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
||||||
if t.token == "" || time.Now().After(t.expiryTime) {
|
|
||||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
t.ssoURL = strings.TrimSuffix(t.ssoURL, "/")
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.ssoURL+"/v1/oauth/access_token", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
resp, err := t.base.RoundTrip(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
token := string(tokenBytes)
|
|
||||||
|
|
||||||
t.token = token
|
|
||||||
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
req.Header.Add("Authorization", "bearer "+t.token)
|
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
|
|
||||||
var resp *http.Response
|
|
||||||
var err error
|
|
||||||
for i := uint64(0); i < t.retries; i++ {
|
|
||||||
resp, err = t.base.RoundTrip(req)
|
|
||||||
if err == nil {
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
resp.Body.Close()
|
|
||||||
}
|
|
||||||
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
|
||||||
time.Sleep(time.Second * 5)
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package validators
|
package validators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
)
|
)
|
||||||
|
|
||||||
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
|
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
|
||||||
@@ -263,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
|
|||||||
|
|
||||||
return StringInSlice(fieldValue, strictLooseValues)
|
return StringInSlice(fieldValue, strictLooseValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// name workerGroup must be more 3 symbol
|
||||||
|
func workerGroupNameValidator(fe validator.FieldLevel) bool {
|
||||||
|
fieldValue := fe.Field().String()
|
||||||
|
fieldValue = strings.Trim(fieldValue, " ")
|
||||||
|
|
||||||
|
return len(fieldValue) >= 3
|
||||||
|
}
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
|
|||||||
fe.Field(),
|
fe.Field(),
|
||||||
joinValues(flipgroupClientTypeValues))
|
joinValues(flipgroupClientTypeValues))
|
||||||
|
|
||||||
|
// k8s Validators
|
||||||
|
case "workerGroupName":
|
||||||
|
return fmt.Sprintf("%s %s must be more 3 symbol",
|
||||||
|
prefix,
|
||||||
|
fe.Field())
|
||||||
|
|
||||||
// KVM_X86/KVM_PPC Validators
|
// KVM_X86/KVM_PPC Validators
|
||||||
case "kvmNetType":
|
case "kvmNetType":
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||||
|
|||||||
@@ -180,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
271
legacy-client.go
271
legacy-client.go
@@ -1,23 +1,34 @@
|
|||||||
package decortsdk
|
package decortsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Legacy HTTP-client for platform
|
// Legacy HTTP-client for platform
|
||||||
type LegacyDecortClient struct {
|
type LegacyDecortClient struct {
|
||||||
decortURL string
|
decortURL string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
cfg config.LegacyConfig
|
||||||
|
expiryTime time.Time
|
||||||
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy client builder
|
// Legacy client builder
|
||||||
@@ -26,9 +37,25 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
|||||||
cfg.Retries = 5
|
cfg.Retries = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expiryTime time.Time
|
||||||
|
|
||||||
|
if cfg.Token != "" {
|
||||||
|
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
return &LegacyDecortClient{
|
return &LegacyDecortClient{
|
||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
client: client.NewLegacyHttpClient(cfg),
|
client: &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
//nolint:gosec
|
||||||
|
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cfg: cfg,
|
||||||
|
expiryTime: expiryTime,
|
||||||
|
mutex: &sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,18 +71,165 @@ func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
// DecortApiCall method for sending requests to the platform
|
||||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||||
|
if k8sCreateReq, ok := params.(k8s.CreateRequest); ok {
|
||||||
|
reqBody := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(reqBody)
|
||||||
|
if k8sCreateReq.OidcCertificate != "" {
|
||||||
|
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||||
|
_, _ = io.Copy(part, strings.NewReader(k8sCreateReq.OidcCertificate))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("name", k8sCreateReq.Name)
|
||||||
|
_ = writer.WriteField("rgId", strconv.FormatUint(k8sCreateReq.RGID, 10))
|
||||||
|
_ = writer.WriteField("k8ciId", strconv.FormatUint(k8sCreateReq.K8SCIID, 10))
|
||||||
|
_ = writer.WriteField("workerGroupName", k8sCreateReq.WorkerGroupName)
|
||||||
|
_ = writer.WriteField("networkPlugin", k8sCreateReq.NetworkPlugin)
|
||||||
|
|
||||||
|
if k8sCreateReq.MasterSEPID != 0 {
|
||||||
|
_ = writer.WriteField("masterSepId", strconv.FormatUint(k8sCreateReq.MasterSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterSEPPool != "" {
|
||||||
|
_ = writer.WriteField("masterSepPool", k8sCreateReq.MasterSEPPool)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerSEPID != 0 {
|
||||||
|
_ = writer.WriteField("workerSepId", strconv.FormatUint(k8sCreateReq.WorkerSEPID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerSEPPool != "" {
|
||||||
|
_ = writer.WriteField("workerSepPool", k8sCreateReq.WorkerSEPPool)
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCreateReq.Labels != nil {
|
||||||
|
for _, v := range k8sCreateReq.Labels {
|
||||||
|
_ = writer.WriteField("labels", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Taints != nil {
|
||||||
|
for _, v := range k8sCreateReq.Taints {
|
||||||
|
_ = writer.WriteField("taints", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Annotations != nil {
|
||||||
|
for _, v := range k8sCreateReq.Annotations {
|
||||||
|
_ = writer.WriteField("annotations", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if k8sCreateReq.MasterCPU != 0 {
|
||||||
|
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(k8sCreateReq.MasterCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterNum != 0 {
|
||||||
|
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(k8sCreateReq.MasterNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterRAM != 0 {
|
||||||
|
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(k8sCreateReq.MasterRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.MasterDisk != 0 {
|
||||||
|
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(k8sCreateReq.MasterDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerCPU != 0 {
|
||||||
|
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(k8sCreateReq.WorkerCPU), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerNum != 0 {
|
||||||
|
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(k8sCreateReq.WorkerNum), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerRAM != 0 {
|
||||||
|
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(k8sCreateReq.WorkerRAM), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.WorkerDisk != 0 {
|
||||||
|
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(k8sCreateReq.WorkerDisk), 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.ExtNetID != 0 {
|
||||||
|
_ = writer.WriteField("extnetId", strconv.FormatUint(k8sCreateReq.ExtNetID, 10))
|
||||||
|
}
|
||||||
|
if k8sCreateReq.VinsId != 0 {
|
||||||
|
_ = writer.WriteField("vinsId", strconv.FormatUint(k8sCreateReq.VinsId, 10))
|
||||||
|
}
|
||||||
|
if !k8sCreateReq.WithLB {
|
||||||
|
_ = writer.WriteField("withLB", strconv.FormatBool(k8sCreateReq.WithLB))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("highlyAvailable", strconv.FormatBool(k8sCreateReq.HighlyAvailable))
|
||||||
|
|
||||||
|
if k8sCreateReq.AdditionalSANs != nil {
|
||||||
|
for _, v := range k8sCreateReq.AdditionalSANs {
|
||||||
|
_ = writer.WriteField("additionalSANs", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k8sCreateReq.InitConfiguration != "" {
|
||||||
|
_ = writer.WriteField("initConfiguration", k8sCreateReq.InitConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.ClusterConfiguration != "" {
|
||||||
|
_ = writer.WriteField("clusterConfiguration", k8sCreateReq.ClusterConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.KubeletConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeletConfiguration", k8sCreateReq.KubeletConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.KubeProxyConfiguration != "" {
|
||||||
|
_ = writer.WriteField("kubeProxyConfiguration", k8sCreateReq.KubeProxyConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.JoinConfiguration != "" {
|
||||||
|
_ = writer.WriteField("joinConfiguration", k8sCreateReq.JoinConfiguration)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.Description != "" {
|
||||||
|
_ = writer.WriteField("desc", k8sCreateReq.Description)
|
||||||
|
}
|
||||||
|
if k8sCreateReq.UserData != "" {
|
||||||
|
_ = writer.WriteField("userData", k8sCreateReq.UserData)
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("extnetOnly", strconv.FormatBool(k8sCreateReq.ExtNetOnly))
|
||||||
|
_ = writer.FormDataContentType()
|
||||||
|
|
||||||
|
ct := writer.FormDataContentType()
|
||||||
|
|
||||||
|
if err := ldc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = writer.WriteField("authkey", ldc.cfg.Token)
|
||||||
|
|
||||||
|
writer.Close()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, reqBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := ldc.domp(req, ct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, errors.New(string(respBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
|
|
||||||
values, err := query.Values(params)
|
values, err := query.Values(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
body := strings.NewReader(values.Encode())
|
if err = ldc.getToken(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body := strings.NewReader(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := ldc.client.Do(req)
|
resp, err := ldc.do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -72,3 +246,88 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
|
|||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
|
||||||
|
ldc.mutex.Lock()
|
||||||
|
defer ldc.mutex.Unlock()
|
||||||
|
|
||||||
|
if ldc.cfg.Token == "" || time.Now().After(ldc.expiryTime) {
|
||||||
|
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password))
|
||||||
|
bodyReader := strings.NewReader(body)
|
||||||
|
|
||||||
|
req, _ := http.NewRequestWithContext(ctx, "POST", ldc.cfg.DecortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
resp, err := ldc.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to get token: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("unable to get token: %s", tokenBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
token := string(tokenBytes)
|
||||||
|
ldc.cfg.Token = token
|
||||||
|
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
|
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := ldc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ldc *LegacyDecortClient) domp(req *http.Request, ctype string) (*http.Response, error) {
|
||||||
|
req.Header.Add("Content-Type", ctype)
|
||||||
|
req.Header.Add("Authorization", "bearer "+ldc.cfg.Token)
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
// var resp *http.Response
|
||||||
|
// var err error
|
||||||
|
buf, _ := io.ReadAll(req.Body)
|
||||||
|
// req = req.Clone(req.Context())
|
||||||
|
|
||||||
|
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||||
|
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||||
|
resp, err := ldc.client.Do(req)
|
||||||
|
|
||||||
|
// if err == nil {
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
respBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
err = fmt.Errorf("%s", respBytes)
|
||||||
|
resp.Body.Close()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ type GroupAddRequest struct {
|
|||||||
// Time of Compute Group readiness
|
// Time of Compute Group readiness
|
||||||
// Required: false
|
// Required: false
|
||||||
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
|
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: false
|
||||||
|
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupAdd creates new Compute Group within BasicService.
|
// GroupAdd creates new Compute Group within BasicService.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type DiskDelRequest struct {
|
|||||||
|
|
||||||
// False if disk is to be deleted to recycle bin
|
// False if disk is to be deleted to recycle bin
|
||||||
// Required: true
|
// Required: true
|
||||||
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
|
Permanently bool `url:"permanently" json:"permanently"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiskDel delete disk and detach from compute
|
// DiskDel delete disk and detach from compute
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ type ListRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
|
|
||||||
|
// Find by sep ID
|
||||||
|
// Required: false
|
||||||
|
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
|
// Find by pool name
|
||||||
|
// Required: false
|
||||||
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ type ListUnattachedRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by sep ID
|
||||||
|
// Required: false
|
||||||
|
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
|
// Find by pool name
|
||||||
|
// Required: false
|
||||||
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// type Params []string
|
||||||
|
|
||||||
// Request struct for create kubernetes cluster
|
// Request struct for create kubernetes cluster
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// Name of Kubernetes cluster
|
// Name of Kubernetes cluster
|
||||||
@@ -24,7 +26,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Name for first worker group created with cluster
|
// Name for first worker group created with cluster
|
||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
|
||||||
|
|
||||||
// Network plugin
|
// Network plugin
|
||||||
// Must be one of these values: flannel, weawenet, calico
|
// Must be one of these values: flannel, weawenet, calico
|
||||||
@@ -98,18 +100,80 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
|
||||||
|
// ID of the ViNS to connect k8s cluster. If nothing is specified, ViNS will be created automatically
|
||||||
|
// Required: false
|
||||||
|
VinsId uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
||||||
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
||||||
// Required: false
|
// Required: false
|
||||||
WithLB bool `url:"withLB" json:"withLB"`
|
WithLB bool `url:"withLB" json:"withLB"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
||||||
|
|
||||||
|
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
|
||||||
|
// Required: false
|
||||||
|
AdditionalSANs []string `url:"additionalSANs,omitempty" json:"additionalSANs,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define settings and actions that should be performed before any other component in the cluster starts.
|
||||||
|
// It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
InitConfiguration string `url:"initConfiguration,omitempty" json:"initConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define global settings and configurations for the entire cluster.
|
||||||
|
// It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
ClusterConfiguration string `url:"clusterConfiguration,omitempty" json:"clusterConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster.
|
||||||
|
// It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeletConfiguration string `url:"kubeletConfiguration,omitempty" json:"kubeletConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster.
|
||||||
|
// It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeProxyConfiguration string `url:"kubeProxyConfiguration,omitempty" json:"kubeProxyConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings for joining a node to a cluster.
|
||||||
|
// It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
JoinConfiguration string `url:"joinConfiguration,omitempty" json:"joinConfiguration,omitempty"`
|
||||||
|
|
||||||
// Text description of this Kubernetes cluster
|
// Text description of this Kubernetes cluster
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: false
|
||||||
|
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||||
|
|
||||||
|
// Use only selected ExtNet for infrastructure connections
|
||||||
|
// Required: false
|
||||||
|
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
||||||
|
|
||||||
|
// Insert ssl certificate in x509 pem format
|
||||||
|
// Required: false
|
||||||
|
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// type wrapperCreateRequest struct {
|
||||||
|
// CreateRequest
|
||||||
|
// Params []string `url:"lbSysctlParams,omitempty"`
|
||||||
|
// }
|
||||||
|
|
||||||
// Create creates a new Kubernetes cluster in the specified Resource Group
|
// Create creates a new Kubernetes cluster in the specified Resource Group
|
||||||
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
@@ -117,6 +181,28 @@ func (k8s K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var params []string
|
||||||
|
|
||||||
|
// if len(req.LbSysctlParams) != 0 {
|
||||||
|
// params = make([]string, 0, len(req.LbSysctlParams))
|
||||||
|
|
||||||
|
// for r := range req.LbSysctlParams {
|
||||||
|
// b, err := json.Marshal(req.LbSysctlParams[r])
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// params = append(params, string(b))
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// params = []string{"[]"}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// reqWrapped := wrapperCreateRequest{
|
||||||
|
// CreateRequest: req,
|
||||||
|
// Params: params,
|
||||||
|
// }
|
||||||
|
|
||||||
url := "/cloudapi/k8s/create"
|
url := "/cloudapi/k8s/create"
|
||||||
|
|
||||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
|||||||
38
pkg/cloudapi/k8s/get_worker_nodes_meta_data.go
Normal file
38
pkg/cloudapi/k8s/get_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get worker group metadata by ID
|
||||||
|
type GetWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get worker group metadata by ID
|
||||||
|
func (k K8S) GetWorkerNodesMetaData(ctx context.Context, req GetWorkerNodesMetaDataRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/k8s/getWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
}
|
||||||
@@ -41,6 +41,9 @@ type ListK8SGroups []ItemK8SGroup
|
|||||||
|
|
||||||
// Detailed information
|
// Detailed information
|
||||||
type ItemDetailedInfo struct {
|
type ItemDetailedInfo struct {
|
||||||
|
// Externalip
|
||||||
|
Externalip string `json:"externalip"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
|||||||
48
pkg/cloudapi/k8s/update_worker_nodes_meta_data.go
Normal file
48
pkg/cloudapi/k8s/update_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add worker to a kubernetes cluster
|
||||||
|
type UpdateWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: true
|
||||||
|
UserData string `url:"userData" json:"userData" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WorkerAdd adds worker nodes to a kubernetes cluster
|
||||||
|
func (k K8S) UpdateWorkerNodesMetaData(ctx context.Context, req UpdateWorkerNodesMetaDataRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/k8s/updateWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package lb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Params []string
|
||||||
|
|
||||||
// Request struct for create load balancer
|
// Request struct for create load balancer
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// ID of the resource group where this load balancer instance will be located
|
// ID of the resource group where this load balancer instance will be located
|
||||||
@@ -20,39 +24,81 @@ type CreateRequest struct {
|
|||||||
Name string `url:"name" json:"name" validate:"required"`
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
// External network to connect this load balancer to
|
// External network to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||||
|
|
||||||
// Internal network (VINS) to connect this load balancer to
|
// Internal network (VINS) to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
||||||
|
|
||||||
// Start now Load balancer
|
// Start now Load balancer
|
||||||
// Required: true
|
// Required: false
|
||||||
Start bool `url:"start" json:"start" validate:"required"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Text description of this load balancer
|
// Text description of this load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Params []string `url:"sysctlParams,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Create method will create a new load balancer instance
|
// Create method will create a new load balancer instance
|
||||||
func (l LB) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (l LB) Create(ctx context.Context, req CreateRequest) (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 "", validators.ValidationError(validationError)
|
return 0, validators.ValidationError(validationError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.ExtNetID == 0 && req.VINSID == 0 {
|
||||||
|
return 0, errors.New("vinsId and extNetId cannot be both in the value 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/lb/create"
|
url := "/cloudapi/lb/create"
|
||||||
|
|
||||||
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := strings.ReplaceAll(string(res), "\"", "")
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,18 @@ type FrontendBindRequest struct {
|
|||||||
|
|
||||||
// Name of the binding to update
|
// Name of the binding to update
|
||||||
// Required: true
|
// Required: true
|
||||||
BindingName string `url:"bindingName" json:"bindingName"`
|
BindingName string `url:"bindingName" json:"bindingName" validate:"required"`
|
||||||
|
|
||||||
// If specified must be within the IP range of either Ext Net or ViNS,
|
// If specified must be within the IP range of either Ext Net or ViNS,
|
||||||
// where this load balancer is connected - new IP address to use for this binding.
|
// where this load balancer is connected - new IP address to use for this binding.
|
||||||
// If omitted, current IP address is retained
|
// If omitted, current IP address is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
|
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
|
||||||
|
|
||||||
// New port number to use for this binding.
|
// New port number to use for this binding.
|
||||||
// If omitted, current port number is retained
|
// If omitted, current port number is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrontendBind bind frontend from specified load balancer instance
|
// FrontendBind bind frontend from specified load balancer instance
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ type FrontendBindUpdateRequest struct {
|
|||||||
// If specified must be within the IP range of either Ext Net or ViNS,
|
// If specified must be within the IP range of either Ext Net or ViNS,
|
||||||
// where this load balancer is connected - new IP address to use for this binding.
|
// where this load balancer is connected - new IP address to use for this binding.
|
||||||
// If omitted, current IP address is retained
|
// If omitted, current IP address is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingAddress string `url:"bindingAddress,omitempty" json:"bindingAddress,omitempty"`
|
BindingAddress string `url:"bindingAddress" json:"bindingAddress" validate:"required"`
|
||||||
|
|
||||||
// New port number to use for this binding.
|
// New port number to use for this binding.
|
||||||
// If omitted, current port number is retained
|
// If omitted, current port number is retained
|
||||||
// Required: false
|
// Required: true
|
||||||
BindingPort uint64 `url:"bindingPort,omitempty" json:"bindingPort,omitempty"`
|
BindingPort uint64 `url:"bindingPort" json:"bindingPort" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
// FrontendBindUpdate updates binding for the specified load balancer frontend
|
||||||
|
|||||||
40
pkg/cloudapi/lb/make_highly_available.go
Normal file
40
pkg/cloudapi/lb/make_highly_available.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for make Load Balancer Highly available
|
||||||
|
type HighlyAvailableRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make Load Balancer Highly available
|
||||||
|
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return 0, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/lb/makeHighlyAvailable"
|
||||||
|
|
||||||
|
res, err := l.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
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@ type RecordLB struct {
|
|||||||
HAMode bool `json:"HAmode"`
|
HAMode bool `json:"HAmode"`
|
||||||
|
|
||||||
// Access Control List
|
// Access Control List
|
||||||
ACL interface{} `json:"acl"`
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
// List of load balancer backends
|
// List of load balancer backends
|
||||||
Backends ListBackends `json:"backends"`
|
Backends ListBackends `json:"backends"`
|
||||||
@@ -32,6 +35,9 @@ type RecordLB struct {
|
|||||||
// External network ID
|
// External network ID
|
||||||
ExtNetID uint64 `json:"extnetId"`
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
// List of load balancer frontends
|
// List of load balancer frontends
|
||||||
Frontends ListFrontends `json:"frontends"`
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
@@ -53,6 +59,9 @@ type RecordLB struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Part K8s
|
||||||
|
PartK8s bool `json:"partK8s"`
|
||||||
|
|
||||||
// Primary node
|
// Primary node
|
||||||
PrimaryNode RecordNode `json:"primaryNode"`
|
PrimaryNode RecordNode `json:"primaryNode"`
|
||||||
|
|
||||||
@@ -68,6 +77,9 @@ type RecordLB struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []interface{} `json:"sysctlParams"`
|
||||||
|
|
||||||
// Tech status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
|
|||||||
72
pkg/cloudapi/lb/updateSysctParams.go
Normal file
72
pkg/cloudapi/lb/updateSysctParams.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for update sysct params for lb
|
||||||
|
type UpdateSysctParamsRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: true
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperUpdateSysctParamsRequest struct {
|
||||||
|
UpdateSysctParamsRequest
|
||||||
|
Params []string `url:"sysctlParams" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create method will create a new load balancer instance
|
||||||
|
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperUpdateSysctParamsRequest{
|
||||||
|
UpdateSysctParamsRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/lb/updateSysctParams"
|
||||||
|
|
||||||
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
10
pkg/cloudapi/stack.go
Normal file
10
pkg/cloudapi/stack.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package cloudapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/stack"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Accessing the Stack method group
|
||||||
|
func (ca *CloudAPI) Stack() *stack.Stack {
|
||||||
|
return stack.New(ca.client)
|
||||||
|
}
|
||||||
42
pkg/cloudapi/stack/get.go
Normal file
42
pkg/cloudapi/stack/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get info of stack
|
||||||
|
type GetRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: true
|
||||||
|
StackId uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get stack details by ID
|
||||||
|
func (i Stack) Get(ctx context.Context, req GetRequest) (*InfoStack, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/stack/get"
|
||||||
|
|
||||||
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := InfoStack{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
53
pkg/cloudapi/stack/list.go
Normal file
53
pkg/cloudapi/stack/list.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get list stack
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by type
|
||||||
|
// Required: false
|
||||||
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStacks gets list stack
|
||||||
|
func (i Stack) List(ctx context.Context, req ListRequest) (*ListStacks, error) {
|
||||||
|
url := "/cloudapi/stack/list"
|
||||||
|
|
||||||
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStacks{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
53
pkg/cloudapi/stack/models.go
Normal file
53
pkg/cloudapi/stack/models.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
// Main information about stack
|
||||||
|
type InfoStack struct {
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
|
// Descr
|
||||||
|
Descr string `json:"descr"`
|
||||||
|
|
||||||
|
// Drivers
|
||||||
|
Drivers []string `json:"drivers"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Mem allocation ratio
|
||||||
|
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Information about stack in list
|
||||||
|
type ItemStack struct {
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of stacks
|
||||||
|
type ListStacks struct {
|
||||||
|
|
||||||
|
//List
|
||||||
|
Data []ItemStack `json:"data"`
|
||||||
|
|
||||||
|
//Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
16
pkg/cloudapi/stack/stack.go
Normal file
16
pkg/cloudapi/stack/stack.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Lists all the stack.
|
||||||
|
package stack
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to stack
|
||||||
|
type Stack struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for stack endpoint
|
||||||
|
func New(client interfaces.Caller) *Stack {
|
||||||
|
return &Stack{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,24 @@ package vins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
// Destination network
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Request struct for create VINS in account
|
// Request struct for create VINS in account
|
||||||
type CreateInAccountRequest struct {
|
type CreateInAccountRequest struct {
|
||||||
// VINS name
|
// VINS name
|
||||||
@@ -33,6 +45,15 @@ type CreateInAccountRequest struct {
|
|||||||
// Number of pre created reservations
|
// Number of pre created reservations
|
||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
||||||
|
|
||||||
|
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||||
|
// Required: false
|
||||||
|
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequestInAcc struct {
|
||||||
|
CreateInAccountRequest
|
||||||
|
Routes []string `url:"routes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInAccount creates VINS in account level
|
// CreateInAccount creates VINS in account level
|
||||||
@@ -44,9 +65,31 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
if len(req.Routes) != 0 {
|
||||||
|
routes = make([]string, 0, len(req.Routes))
|
||||||
|
|
||||||
|
for r := range req.Routes {
|
||||||
|
b, err := json.Marshal(req.Routes[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
routes = append(routes, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routes = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequestInAcc{
|
||||||
|
CreateInAccountRequest: req,
|
||||||
|
Routes: routes,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/vins/createInAccount"
|
url := "/cloudapi/vins/createInAccount"
|
||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package vins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -36,7 +37,16 @@ type CreateInRGRequest struct {
|
|||||||
|
|
||||||
// Number of pre created reservations
|
// Number of pre created reservations
|
||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
||||||
|
|
||||||
|
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||||
|
// Required: false
|
||||||
|
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequestInRG struct {
|
||||||
|
CreateInRGRequest
|
||||||
|
Routes []string `url:"routes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInRG creates VINS in resource group level
|
// CreateInRG creates VINS in resource group level
|
||||||
@@ -48,9 +58,31 @@ func (v VINS) CreateInRG(ctx context.Context, req CreateInRGRequest) (uint64, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
if len(req.Routes) != 0 {
|
||||||
|
routes = make([]string, 0, len(req.Routes))
|
||||||
|
|
||||||
|
for r := range req.Routes {
|
||||||
|
b, err := json.Marshal(req.Routes[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
routes = append(routes, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routes = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequestInRG{
|
||||||
|
CreateInRGRequest: req,
|
||||||
|
Routes: routes,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/vins/createInRG"
|
url := "/cloudapi/vins/createInRG"
|
||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,6 +252,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"`
|
||||||
|
|
||||||
@@ -378,6 +381,9 @@ type RecordNAT struct {
|
|||||||
// Pure virtual
|
// Pure virtual
|
||||||
PureVirtual bool `json:"pureVirtual"`
|
PureVirtual bool `json:"pureVirtual"`
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
Routes ListRoutes `json:"routes"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
@@ -397,9 +403,11 @@ type NATConfig struct {
|
|||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
|
|
||||||
// List NAT rules
|
// List NAT rules
|
||||||
Rules ListNATRules `json:"rules"`
|
Rules ListNATRulesConfig `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListNATRulesConfig []ItemNATRule
|
||||||
|
|
||||||
// Main information about GW
|
// Main information about GW
|
||||||
type RecordGW struct {
|
type RecordGW struct {
|
||||||
// CKey
|
// CKey
|
||||||
@@ -441,6 +449,9 @@ type RecordGW struct {
|
|||||||
// Pure virtual
|
// Pure virtual
|
||||||
PureVirtual bool `json:"pureVirtual"`
|
PureVirtual bool `json:"pureVirtual"`
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
Routes ListRoutes `json:"routes"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
@@ -528,6 +539,9 @@ type RecordDHCP struct {
|
|||||||
// Pure virtual
|
// Pure virtual
|
||||||
PureVirtual bool `json:"pureVirtual"`
|
PureVirtual bool `json:"pureVirtual"`
|
||||||
|
|
||||||
|
// Routes
|
||||||
|
Routes ListRoutes `json:"routes"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
@@ -565,14 +579,44 @@ type RecordDHCPConfig struct {
|
|||||||
Reservations ListReservations `json:"reservations"`
|
Reservations ListReservations `json:"reservations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of static routes
|
||||||
|
type ListStaticRoutes struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemRoutes `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of Routes
|
||||||
|
type ListRoutes []ItemRoutes
|
||||||
|
|
||||||
|
// Detailed information about Routes
|
||||||
|
type ItemRoutes struct {
|
||||||
|
//Compute Id
|
||||||
|
ComputeIds []uint64 `json:"computeIds"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `json:"gateway"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `json:"netmask"`
|
||||||
|
}
|
||||||
|
|
||||||
// Detailed information about VINS
|
// Detailed information about VINS
|
||||||
type RecordVINS struct {
|
type RecordVINS struct {
|
||||||
// Main information about VNF device
|
// Main information about VNF device
|
||||||
VNFDev RecordVNFDev `json:"VNFDev"`
|
VNFDev RecordVNFDev `json:"VNFDev"`
|
||||||
|
|
||||||
// CKey
|
|
||||||
CKey string `json:"_ckey"`
|
|
||||||
|
|
||||||
// Account ID
|
// Account ID
|
||||||
AccountID uint64 `json:"accountId"`
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
@@ -582,12 +626,24 @@ type RecordVINS struct {
|
|||||||
// List of VINS computes
|
// List of VINS computes
|
||||||
Computes ListVINSComputes `json:"computes"`
|
Computes ListVINSComputes `json:"computes"`
|
||||||
|
|
||||||
|
// Created by
|
||||||
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
|
// Created time
|
||||||
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
// Default GW
|
// Default GW
|
||||||
DefaultGW string `json:"defaultGW"`
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
// Default QOS
|
// Default QOS
|
||||||
DefaultQOS QOS `json:"defaultQos"`
|
DefaultQOS QOS `json:"defaultQos"`
|
||||||
|
|
||||||
|
// Deleted by
|
||||||
|
DeletedBy string `json:"deletedBy"`
|
||||||
|
|
||||||
|
// Deleted time
|
||||||
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
|||||||
48
pkg/cloudapi/vins/static_route_access_grant.go
Normal file
48
pkg/cloudapi/vins/static_route_access_grant.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for grant access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessGrantRequest struct {
|
||||||
|
// ViNS ID to grant access
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to grant access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to grant access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grant access to static route to Compute/ViNS
|
||||||
|
func (v VINS) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/vins/staticRouteAccessGrant"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
48
pkg/cloudapi/vins/static_route_access_revoke.go
Normal file
48
pkg/cloudapi/vins/static_route_access_revoke.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for revoke access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessRevokeRequest struct {
|
||||||
|
// ViNS ID to revoke access
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to revoke access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to revoke access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke access to static route to Compute/ViNS
|
||||||
|
func (v VINS) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/vins/staticRouteAccessRevoke"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
56
pkg/cloudapi/vins/static_route_add.go
Normal file
56
pkg/cloudapi/vins/static_route_add.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add static route
|
||||||
|
type StaticRouteAddRequest struct {
|
||||||
|
// VINS ID
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
// Required: true
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network mask in 255.255.255.255 format
|
||||||
|
// Required: true
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
// Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
// Required: true
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs which have access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticRouteAdd add new static route to ViNS
|
||||||
|
func (v VINS) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/vins/staticRouteAdd"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
44
pkg/cloudapi/vins/static_route_del.go
Normal file
44
pkg/cloudapi/vins/static_route_del.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for remove static route from ViNS
|
||||||
|
type StaticRouteDelRequest struct {
|
||||||
|
// ViNS ID to remove static route from
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to remove, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove static route from ViNS
|
||||||
|
func (v VINS) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/vins/staticRouteDel"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
42
pkg/cloudapi/vins/static_route_list.go
Normal file
42
pkg/cloudapi/vins/static_route_list.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package vins
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for static route list
|
||||||
|
type StaticRouteListRequest struct {
|
||||||
|
// ViNS ID to show list of static routes
|
||||||
|
// Required: true
|
||||||
|
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show list of static routes for ViNS
|
||||||
|
func (v VINS) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/vins/staticRouteList"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStaticRoutes{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ type DeleteUserRequest struct {
|
|||||||
|
|
||||||
// Recursively revoke access rights from owned cloudspaces and vmachines
|
// Recursively revoke access rights from owned cloudspaces and vmachines
|
||||||
// Required: false
|
// Required: false
|
||||||
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
|
RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteUser revokes user access from the account
|
// DeleteUser revokes user access from the account
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type DisableRequest struct {
|
|||||||
|
|
||||||
// Reason to disable
|
// Reason to disable
|
||||||
// Required: true
|
// Required: true
|
||||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable disables an account
|
// Disable disables an account
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type EnableRequest struct {
|
|||||||
|
|
||||||
// Reason to enable
|
// Reason to enable
|
||||||
// Required: true
|
// Required: true
|
||||||
Reason string `url:"reason" json:"reason" validate:"required"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable enables an account
|
// Enable enables an account
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type ListVINSRequest struct {
|
|||||||
|
|
||||||
// Find by VINS ID
|
// Find by VINS ID
|
||||||
// Required: false
|
// Required: false
|
||||||
VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"`
|
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
// Find by name
|
// Find by name
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type DiskDelRequest struct {
|
|||||||
|
|
||||||
// False if disk is to be deleted to recycle bin
|
// False if disk is to be deleted to recycle bin
|
||||||
// Required: true
|
// Required: true
|
||||||
Permanently bool `url:"permanently" json:"permanently" validate:"required"`
|
Permanently bool `url:"permanently" json:"permanently"`
|
||||||
|
|
||||||
// Reason for action
|
// Reason for action
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
43
pkg/cloudbroker/compute/set_custom_fields.go
Normal file
43
pkg/cloudbroker/compute/set_custom_fields.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package compute
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
// Request struct for setting customFields values for the Compute
|
||||||
|
type SetCustomFieldsRequest struct {
|
||||||
|
// ID of the compute
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
|
||||||
|
// Custom fields for Compute. Must be dict.
|
||||||
|
// Required: true
|
||||||
|
CustomFields string `url:"customFields" json:"customFields" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCustomFields sets customFields values for the Compute
|
||||||
|
func (c Compute) SetCustomFields(ctx context.Context, req SetCustomFieldsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/compute/setCustomFields"
|
||||||
|
|
||||||
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -40,6 +40,14 @@ type ListRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
|
|
||||||
|
// Find by sep ID
|
||||||
|
// Required: false
|
||||||
|
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
|
// Find by pool name
|
||||||
|
// Required: false
|
||||||
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
// Find by shared, true or false
|
|
||||||
// Required: false
|
|
||||||
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
|
|
||||||
|
|
||||||
// Type of the disks
|
// Type of the disks
|
||||||
// Required: false
|
// Required: false
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||||
|
|
||||||
|
// Find by sep ID
|
||||||
|
// Required: false
|
||||||
|
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||||
|
|
||||||
|
// Find by pool name
|
||||||
|
// Required: false
|
||||||
|
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||||
|
|
||||||
// Page number
|
// Page number
|
||||||
// Required: false
|
// Required: false
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|||||||
@@ -2,12 +2,24 @@ package extnet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
// Destination network
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Request struct for create external network
|
// Request struct for create external network
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// External network name
|
// External network name
|
||||||
@@ -70,6 +82,15 @@ type CreateRequest struct {
|
|||||||
// OpenvSwith bridge name for ExtNet connection
|
// OpenvSwith bridge name for ExtNet connection
|
||||||
// Required: false
|
// Required: false
|
||||||
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
OVSBridge string `url:"ovsBridge,omitempty" json:"ovsBridge,omitempty"`
|
||||||
|
|
||||||
|
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||||
|
// Required: false
|
||||||
|
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Routes []string `url:"routes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates new external network into platform
|
// Create creates new external network into platform
|
||||||
@@ -81,9 +102,31 @@ func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
if len(req.Routes) != 0 {
|
||||||
|
routes = make([]string, 0, len(req.Routes))
|
||||||
|
|
||||||
|
for r := range req.Routes {
|
||||||
|
b, err := json.Marshal(req.Routes[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
routes = append(routes, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routes = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Routes: routes,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/extnet/create"
|
url := "/cloudbroker/extnet/create"
|
||||||
|
|
||||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,3 +151,33 @@ type RecordExtNet struct {
|
|||||||
// List reservations
|
// List reservations
|
||||||
Reservations ListReservations `json:"reservations"`
|
Reservations ListReservations `json:"reservations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List of static routes
|
||||||
|
type ListStaticRoutes struct {
|
||||||
|
// Data
|
||||||
|
Data []ItemRoutes `json:"data"`
|
||||||
|
|
||||||
|
// Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed information about Routes
|
||||||
|
type ItemRoutes struct {
|
||||||
|
//Compute Id
|
||||||
|
ComputeIds []uint64 `json:"computeIds"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `json:"gateway"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `json:"netmask"`
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
48
pkg/cloudbroker/extnet/static_route_access_grant.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for grant access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessGrantRequest struct {
|
||||||
|
// ExtNet ID to grant access
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to grant access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to grant access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grant access to static route to Compute/ViNS
|
||||||
|
func (v ExtNet) StaticRouteAccessGrant(ctx context.Context, req StaticRouteAccessGrantRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAccessGrant"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
48
pkg/cloudbroker/extnet/static_route_access_revoke.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for revoke access to static route to Compute/ViNS
|
||||||
|
type StaticRouteAccessRevokeRequest struct {
|
||||||
|
// ExtNet ID to revoke access
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to revoke access, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs to revoke access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Revoke access to static route to Compute/ViNS
|
||||||
|
func (v ExtNet) StaticRouteAccessRevoke(ctx context.Context, req StaticRouteAccessRevokeRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAccessRevoke"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
56
pkg/cloudbroker/extnet/static_route_add.go
Normal file
56
pkg/cloudbroker/extnet/static_route_add.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add static route
|
||||||
|
type StaticRouteAddRequest struct {
|
||||||
|
// ExtNet ID to add static route
|
||||||
|
// Required: true
|
||||||
|
ExtNetId uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network
|
||||||
|
// Required: true
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
// Destination network mask in 255.255.255.255 format
|
||||||
|
// Required: true
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
// Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
// Required: true
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
|
||||||
|
// List of Compute IDs which have access to this route
|
||||||
|
// Required: false
|
||||||
|
ComputeIds []uint64 `url:"computeIds,omitempty" json:"computeIds,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticRouteAdd add new static route to ViNS
|
||||||
|
func (v ExtNet) StaticRouteAdd(ctx context.Context, req StaticRouteAddRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteAdd"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/extnet/static_route_del.go
Normal file
44
pkg/cloudbroker/extnet/static_route_del.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for remove static route from ViNS
|
||||||
|
type StaticRouteDelRequest struct {
|
||||||
|
// ExtNet ID to remove static route from
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
|
||||||
|
// Route ID to remove, can be found in staticRouteList
|
||||||
|
// Required: true
|
||||||
|
RouteId uint64 `url:"routeId" json:"routeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove static route from ViNS
|
||||||
|
func (v ExtNet) StaticRouteDel(ctx context.Context, req StaticRouteDelRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteDel"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/extnet/static_route_list.go
Normal file
42
pkg/cloudbroker/extnet/static_route_list.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package extnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for static route list
|
||||||
|
type StaticRouteListRequest struct {
|
||||||
|
// ExtNet ID to show list of static routes
|
||||||
|
// Required: true
|
||||||
|
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show list of static routes for ViNS
|
||||||
|
func (v ExtNet) StaticRouteList(ctx context.Context, req StaticRouteListRequest) (*ListStaticRoutes, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/extnet/staticRouteList"
|
||||||
|
|
||||||
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStaticRoutes{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
10
pkg/cloudbroker/flipgoup.go
Normal file
10
pkg/cloudbroker/flipgoup.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/flipgroup"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Accessing the FLIPGroup method group
|
||||||
|
func (cb *CloudBroker) FLIPGroup() *flipgroup.FLIPGroup {
|
||||||
|
return flipgroup.New(cb.client)
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/flipgroup/compute_add.go
Normal file
44
pkg/cloudbroker/flipgroup/compute_add.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add compute instance
|
||||||
|
type ComputeAddRequest struct {
|
||||||
|
// ID of the Floating IP group to add compute instance to
|
||||||
|
// Required: true
|
||||||
|
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the compute instance to add to this group
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeAdd add compute instance to the Floating IP group
|
||||||
|
func (f FLIPGroup) ComputeAdd(ctx context.Context, req ComputeAddRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/flipgroup/computeAdd"
|
||||||
|
|
||||||
|
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/flipgroup/compute_remove.go
Normal file
44
pkg/cloudbroker/flipgroup/compute_remove.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for remove compute instance
|
||||||
|
type ComputeRemoveRequest struct {
|
||||||
|
// ID of the Floating IP group to remove compute instance from
|
||||||
|
// Required: true
|
||||||
|
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the compute instance to remove
|
||||||
|
// Required: true
|
||||||
|
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeRemove remove compute instance from the Floating IP group
|
||||||
|
func (f FLIPGroup) ComputeRemove(ctx context.Context, req ComputeRemoveRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/flipgroup/computeRemove"
|
||||||
|
|
||||||
|
res, err := f.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
|
||||||
|
}
|
||||||
71
pkg/cloudbroker/flipgroup/create.go
Normal file
71
pkg/cloudbroker/flipgroup/create.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for create FLIPGroup
|
||||||
|
type CreateRequest struct {
|
||||||
|
// Account ID
|
||||||
|
// Required: true
|
||||||
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// FLIPGroup name
|
||||||
|
// Required: true
|
||||||
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
|
// Network type
|
||||||
|
// Should be one of:
|
||||||
|
// - EXTNET
|
||||||
|
// - VINS
|
||||||
|
// Required: true
|
||||||
|
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
||||||
|
|
||||||
|
// ID of external network or VINS
|
||||||
|
// Required: true
|
||||||
|
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||||
|
|
||||||
|
// Type of client
|
||||||
|
// - 'compute'
|
||||||
|
// - 'vins' (will be later)
|
||||||
|
// Required: true
|
||||||
|
ClientType string `url:"clientType" json:"clientType" validate:"flipgroupClientType"`
|
||||||
|
|
||||||
|
// IP address to associate with this group. If empty, the platform will autoselect IP address
|
||||||
|
// Required: false
|
||||||
|
IP string `url:"ip,omitempty" json:"ip,omitempty"`
|
||||||
|
|
||||||
|
// Text description of this FLIPGorup instance
|
||||||
|
// Required: false
|
||||||
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create method will create a new FLIPGorup in the specified Account
|
||||||
|
func (f FLIPGroup) Create(ctx context.Context, req CreateRequest) (*RecordFLIPGroupCreated, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/flipgroup/create"
|
||||||
|
|
||||||
|
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := RecordFLIPGroupCreated{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
40
pkg/cloudbroker/flipgroup/delete.go
Normal file
40
pkg/cloudbroker/flipgroup/delete.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for delete FLIPGroup
|
||||||
|
type DeleteRequest struct {
|
||||||
|
// FLIPGroup ID
|
||||||
|
// Required: true
|
||||||
|
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete method wil delete Floating IP group
|
||||||
|
func (f FLIPGroup) 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/flipgroup/delete"
|
||||||
|
|
||||||
|
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
48
pkg/cloudbroker/flipgroup/edit.go
Normal file
48
pkg/cloudbroker/flipgroup/edit.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for edit FLIPGroup
|
||||||
|
type EditRequest struct {
|
||||||
|
// FLIPGroup ID
|
||||||
|
// Required: true
|
||||||
|
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||||
|
|
||||||
|
// FLIPGroup name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// FLIPGroup description
|
||||||
|
// Required: false
|
||||||
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit edits FLIPGroup fields
|
||||||
|
func (f FLIPGroup) Edit(ctx context.Context, req EditRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/flipgroup/edit"
|
||||||
|
|
||||||
|
res, err := f.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
|
||||||
|
}
|
||||||
18
pkg/cloudbroker/flipgroup/flipgroup.go
Normal file
18
pkg/cloudbroker/flipgroup/flipgroup.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// API to manage FLIPGroup instances
|
||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Structure for creating request to FLIPGroup
|
||||||
|
type FLIPGroup struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for FLIPGroup endpoints
|
||||||
|
func New(client interfaces.Caller) *FLIPGroup {
|
||||||
|
return &FLIPGroup{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/flipgroup/get.go
Normal file
42
pkg/cloudbroker/flipgroup/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get information about FLIPGroup
|
||||||
|
type GetRequest struct {
|
||||||
|
// FLIPGroup ID
|
||||||
|
// Required: true
|
||||||
|
FLIPGroupID uint64 `url:"flipgroupId" json:"flipgroupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gets details of the specified Floating IP group
|
||||||
|
func (f FLIPGroup) Get(ctx context.Context, req GetRequest) (*RecordFLIPGroup, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/flipgroup/get"
|
||||||
|
|
||||||
|
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := RecordFLIPGroup{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
65
pkg/cloudbroker/flipgroup/list.go
Normal file
65
pkg/cloudbroker/flipgroup/list.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get list FLIPGroup available to the current user
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by vinsId
|
||||||
|
// Required: false
|
||||||
|
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
|
// Find by VINS name
|
||||||
|
// Required: false
|
||||||
|
VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"`
|
||||||
|
|
||||||
|
// Find by extnetId
|
||||||
|
// Required: false
|
||||||
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
|
||||||
|
// Find by IP
|
||||||
|
// Reuqired: false
|
||||||
|
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
|
||||||
|
|
||||||
|
// Find by resource group ID
|
||||||
|
// Reuqired: false
|
||||||
|
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
||||||
|
|
||||||
|
// Find by id
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// 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 FLIPGroup managed cluster instances available to the current user
|
||||||
|
func (f FLIPGroup) List(ctx context.Context, req ListRequest) (*ListFLIPGroups, error) {
|
||||||
|
url := "/cloudbroker/flipgroup/list"
|
||||||
|
|
||||||
|
res, err := f.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListFLIPGroups{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
169
pkg/cloudbroker/flipgroup/models.go
Normal file
169
pkg/cloudbroker/flipgroup/models.go
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
// Main information about FLIPGroup
|
||||||
|
type RecordFLIPGroupCreated struct {
|
||||||
|
// Default GW
|
||||||
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// IP
|
||||||
|
IP string `json:"ip"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network mask
|
||||||
|
NetMask uint64 `json:"netmask"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordFLIPGroup struct {
|
||||||
|
// Account ID
|
||||||
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
// Account name
|
||||||
|
AccountName string `json:"accountName"`
|
||||||
|
|
||||||
|
// List of client IDs
|
||||||
|
ClientIDs []uint64 `json:"clientIds"`
|
||||||
|
|
||||||
|
// Client names
|
||||||
|
ClientNames []string `json:"clientNames"`
|
||||||
|
|
||||||
|
// Client type
|
||||||
|
ClientType string `json:"clientType"`
|
||||||
|
|
||||||
|
// Connection ID
|
||||||
|
ConnID uint64 `json:"connId"`
|
||||||
|
|
||||||
|
// Connection type
|
||||||
|
ConnType string `json:"connType"`
|
||||||
|
|
||||||
|
// Created by
|
||||||
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
|
// Created time
|
||||||
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
|
// Default GW
|
||||||
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
|
// Deleted by
|
||||||
|
DeletedBy string `json:"deletedBy"`
|
||||||
|
|
||||||
|
// Deleted time
|
||||||
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// IP
|
||||||
|
IP string `json:"ip"`
|
||||||
|
|
||||||
|
// Milestones
|
||||||
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network ID
|
||||||
|
NetID uint64 `json:"netId"`
|
||||||
|
|
||||||
|
// Network type
|
||||||
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
|
// Network
|
||||||
|
Network string `json:"network"`
|
||||||
|
|
||||||
|
// Resource group ID
|
||||||
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
// Resource group name
|
||||||
|
RGName string `json:"rgName"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Updated by
|
||||||
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
|
||||||
|
// Updated time
|
||||||
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed information about FLIPGroup
|
||||||
|
type ItemFLIPGroup struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
// Account ID
|
||||||
|
AccountID uint64 `json:"accountId"`
|
||||||
|
|
||||||
|
// List of client IDs
|
||||||
|
ClientIDs []uint64 `json:"clientIds"`
|
||||||
|
|
||||||
|
// Client type
|
||||||
|
ClientType string `json:"clientType"`
|
||||||
|
|
||||||
|
// Connection ID
|
||||||
|
ConnID uint64 `json:"connId"`
|
||||||
|
|
||||||
|
// Connection type
|
||||||
|
ConnType string `json:"connType"`
|
||||||
|
|
||||||
|
// Default GW
|
||||||
|
DefaultGW string `json:"defaultGW"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// IP
|
||||||
|
IP string `json:"ip"`
|
||||||
|
|
||||||
|
// Milestones
|
||||||
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Network ID
|
||||||
|
NetID uint64 `json:"netId"`
|
||||||
|
|
||||||
|
// Network type
|
||||||
|
NetType string `json:"netType"`
|
||||||
|
|
||||||
|
// NetMask
|
||||||
|
NetMask uint64 `json:"netmask"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of FLIPGroup
|
||||||
|
type ListFLIPGroups struct {
|
||||||
|
Data []ItemFLIPGroup `json:"data"`
|
||||||
|
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/flipgroup/serialize.go
Normal file
43
pkg/cloudbroker/flipgroup/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package flipgroup
|
||||||
|
|
||||||
|
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 (lfg ListFLIPGroups) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(lfg.Data) == 0 {
|
||||||
|
return []byte{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(lfg, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(lfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (ifg ItemFLIPGroup) Serialize(params ...string) (serialization.Serialized, error) {
|
||||||
|
if len(params) > 1 {
|
||||||
|
prefix := params[0]
|
||||||
|
indent := params[1]
|
||||||
|
|
||||||
|
return json.MarshalIndent(ifg, prefix, indent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(ifg)
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package grid
|
|||||||
|
|
||||||
// FilterByID returns ListGrids with specified ID.
|
// FilterByID returns ListGrids with specified ID.
|
||||||
func (lg ListGrids) FilterByID(id uint64) ListGrids {
|
func (lg ListGrids) FilterByID(id uint64) ListGrids {
|
||||||
predicate := func(rg RecordGrid) bool {
|
predicate := func(rg ItemGridList) bool {
|
||||||
return rg.ID == id
|
return rg.ID == id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ func (lg ListGrids) FilterByID(id uint64) ListGrids {
|
|||||||
|
|
||||||
// FilterByName returns ListGrids with specified Name.
|
// FilterByName returns ListGrids with specified Name.
|
||||||
func (lg ListGrids) FilterByName(name string) ListGrids {
|
func (lg ListGrids) FilterByName(name string) ListGrids {
|
||||||
predicate := func(rg RecordGrid) bool {
|
predicate := func(rg ItemGridList) bool {
|
||||||
return rg.Name == name
|
return rg.Name == name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ func (lg ListGrids) FilterByName(name string) ListGrids {
|
|||||||
|
|
||||||
// FilterByLocationCode returns ListGrids with specified LocationCode.
|
// FilterByLocationCode returns ListGrids with specified LocationCode.
|
||||||
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
|
func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
|
||||||
predicate := func(rg RecordGrid) bool {
|
predicate := func(rg ItemGridList) bool {
|
||||||
return rg.LocationCode == locationCode
|
return rg.LocationCode == locationCode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ func (lg ListGrids) FilterByLocationCode(locationCode string) ListGrids {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FilterFunc allows filtering ListGrids based on a user-specified predicate.
|
// FilterFunc allows filtering ListGrids based on a user-specified predicate.
|
||||||
func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
|
func (lg ListGrids) FilterFunc(predicate func(ItemGridList) bool) ListGrids {
|
||||||
var result ListGrids
|
var result ListGrids
|
||||||
|
|
||||||
for _, item := range lg.Data {
|
for _, item := range lg.Data {
|
||||||
@@ -44,9 +44,9 @@ func (lg ListGrids) FilterFunc(predicate func(RecordGrid) bool) ListGrids {
|
|||||||
|
|
||||||
// FindOne returns first found RecordGrid.
|
// FindOne returns first found RecordGrid.
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (lg ListGrids) FindOne() RecordGrid {
|
func (lg ListGrids) FindOne() ItemGridList {
|
||||||
if len(lg.Data) == 0 {
|
if len(lg.Data) == 0 {
|
||||||
return RecordGrid{}
|
return ItemGridList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lg.Data[0]
|
return lg.Data[0]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package grid
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var grids = ListGrids{
|
var grids = ListGrids{
|
||||||
Data: []RecordGrid{
|
Data: []ItemGridList{
|
||||||
{
|
{
|
||||||
Resources: Resources{
|
Resources: Resources{
|
||||||
Current: RecordResource{
|
Current: RecordResource{
|
||||||
@@ -123,7 +123,7 @@ func TestFilterByLocationCode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
func TestFilterFunc(t *testing.T) {
|
||||||
actual := grids.FilterFunc(func(rg RecordGrid) bool {
|
actual := grids.FilterFunc(func(rg ItemGridList) bool {
|
||||||
return rg.GID == 777
|
return rg.GID == 777
|
||||||
}).
|
}).
|
||||||
FindOne()
|
FindOne()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type RecordResourcesConsumption struct {
|
|||||||
Reserved RecordResource `json:"Reserved"`
|
Reserved RecordResource `json:"Reserved"`
|
||||||
|
|
||||||
// GID
|
// GID
|
||||||
GID uint64 `json:"gid"`
|
GID uint64 `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResourceConsumption struct {
|
type ListResourceConsumption struct {
|
||||||
@@ -67,6 +67,27 @@ type DiskUsage struct {
|
|||||||
|
|
||||||
// Detailed information about grid
|
// Detailed information about grid
|
||||||
type RecordGrid struct {
|
type RecordGrid struct {
|
||||||
|
// Flag
|
||||||
|
Flag string `json:"flag"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Location code
|
||||||
|
LocationCode string `json:"locationCode"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Information about grid
|
||||||
|
type ItemGridList struct {
|
||||||
// Resource information
|
// Resource information
|
||||||
Resources Resources `json:"Resources"`
|
Resources Resources `json:"Resources"`
|
||||||
|
|
||||||
@@ -92,7 +113,7 @@ type RecordGrid struct {
|
|||||||
// List Grids
|
// List Grids
|
||||||
type ListGrids struct {
|
type ListGrids struct {
|
||||||
//Data
|
//Data
|
||||||
Data []RecordGrid `json:"data"`
|
Data []ItemGridList `json:"data"`
|
||||||
|
|
||||||
// Entry count
|
// Entry count
|
||||||
EntryCount uint64 `json:"entryCount"`
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ type DeleteRequest struct {
|
|||||||
|
|
||||||
// Whether to completely delete the image
|
// Whether to completely delete the image
|
||||||
// Required: false
|
// Required: false
|
||||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
Permanently bool `url:"permanently" json:"permanently"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes image by ID
|
// Delete deletes image by ID
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ type ListACL []ACL
|
|||||||
// History information
|
// History information
|
||||||
type History struct {
|
type History struct {
|
||||||
// GUID
|
// GUID
|
||||||
GUID uint64 `json:"guid"`
|
GUID GUID `json:"guid"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
@@ -171,6 +171,20 @@ type History struct {
|
|||||||
Timestamp uint64 `json:"timestamp"`
|
Timestamp uint64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GUID string
|
||||||
|
|
||||||
|
func (r *GUID) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
|
if b[0] == '"' {
|
||||||
|
*r = GUID(string(b[1:len(b)-1]))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
*r = GUID(string(b))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// List history
|
// List history
|
||||||
type ListHistory []History
|
type ListHistory []History
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package k8ci
|
|||||||
// FilterByID returns ListK8CI with specified ID.
|
// FilterByID returns ListK8CI with specified ID.
|
||||||
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
||||||
predicate := func(ikc ItemK8CI) bool {
|
predicate := func(ikc ItemK8CI) bool {
|
||||||
return ikc.RecordK8CI.ID == id
|
return ikc.RecordK8CIList.ID == id
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc.FilterFunc(predicate)
|
return lkc.FilterFunc(predicate)
|
||||||
@@ -12,7 +12,7 @@ func (lkc ListK8CI) FilterByID(id uint64) ListK8CI {
|
|||||||
// FilterByName returns ListK8CI with specified Name.
|
// FilterByName returns ListK8CI with specified Name.
|
||||||
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
func (lkc ListK8CI) FilterByName(name string) ListK8CI {
|
||||||
predicate := func(ikc ItemK8CI) bool {
|
predicate := func(ikc ItemK8CI) bool {
|
||||||
return ikc.RecordK8CI.Name == name
|
return ikc.RecordK8CIList.Name == name
|
||||||
}
|
}
|
||||||
|
|
||||||
return lkc.FilterFunc(predicate)
|
return lkc.FilterFunc(predicate)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ var k8ciItems = ListK8CI{
|
|||||||
Data: []ItemK8CI{
|
Data: []ItemK8CI{
|
||||||
{
|
{
|
||||||
CreatedTime: 123902139,
|
CreatedTime: 123902139,
|
||||||
RecordK8CI: RecordK8CI{
|
RecordK8CIList: RecordK8CIList{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 1,
|
GUID: 1,
|
||||||
@@ -17,7 +17,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 2,
|
MaxMasterCount: 2,
|
||||||
MaxWorkerCount: 3,
|
MaxWorkerCount: 3,
|
||||||
Name: "purple_snake",
|
Name: "purple_snake",
|
||||||
SharedWith: []interface{}{},
|
SharedWith: []uint64{},
|
||||||
Status: "ENABLED",
|
Status: "ENABLED",
|
||||||
Version: "1",
|
Version: "1",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
@@ -26,7 +26,7 @@ var k8ciItems = ListK8CI{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CreatedTime: 123902232,
|
CreatedTime: 123902232,
|
||||||
RecordK8CI: RecordK8CI{
|
RecordK8CIList: RecordK8CIList{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 2,
|
GUID: 2,
|
||||||
@@ -37,7 +37,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 3,
|
MaxMasterCount: 3,
|
||||||
MaxWorkerCount: 5,
|
MaxWorkerCount: 5,
|
||||||
Name: "green_giant",
|
Name: "green_giant",
|
||||||
SharedWith: []interface{}{},
|
SharedWith: []uint64{},
|
||||||
Status: "DISABLED",
|
Status: "DISABLED",
|
||||||
Version: "2",
|
Version: "2",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
@@ -46,7 +46,7 @@ var k8ciItems = ListK8CI{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
CreatedTime: 123902335,
|
CreatedTime: 123902335,
|
||||||
RecordK8CI: RecordK8CI{
|
RecordK8CIList: RecordK8CIList{
|
||||||
Description: "",
|
Description: "",
|
||||||
GID: 0,
|
GID: 0,
|
||||||
GUID: 3,
|
GUID: 3,
|
||||||
@@ -57,7 +57,7 @@ var k8ciItems = ListK8CI{
|
|||||||
MaxMasterCount: 5,
|
MaxMasterCount: 5,
|
||||||
MaxWorkerCount: 9,
|
MaxWorkerCount: 9,
|
||||||
Name: "magenta_cloud",
|
Name: "magenta_cloud",
|
||||||
SharedWith: []interface{}{},
|
SharedWith: []uint64{},
|
||||||
Status: "ENABLED",
|
Status: "ENABLED",
|
||||||
Version: "3",
|
Version: "3",
|
||||||
WorkerDriver: "KVM_X86",
|
WorkerDriver: "KVM_X86",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package k8ci
|
package k8ci
|
||||||
|
|
||||||
// Main information about K8CI
|
// Main information about K8CI in List
|
||||||
type ItemK8CI struct {
|
type ItemK8CI struct {
|
||||||
// Created time
|
// Created time
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
// Detailed information about K8CI
|
// Detailed information about K8CI
|
||||||
RecordK8CI
|
RecordK8CIList
|
||||||
}
|
}
|
||||||
|
|
||||||
// List K8CI
|
// List K8CI
|
||||||
@@ -17,7 +17,55 @@ type ListK8CI struct {
|
|||||||
EntryCount uint64 `json:"entryCount"`
|
EntryCount uint64 `json:"entryCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detailed information about K8CI
|
// Detailed information about K8CI in List
|
||||||
|
type RecordK8CIList struct {
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Load balancer image ID
|
||||||
|
LBImageID uint64 `json:"lbImageId"`
|
||||||
|
|
||||||
|
// Master driver
|
||||||
|
MasterDriver string `json:"masterDriver"`
|
||||||
|
|
||||||
|
// Master image ID
|
||||||
|
MasterImageID uint64 `json:"masterImageId"`
|
||||||
|
|
||||||
|
// Max master count
|
||||||
|
MaxMasterCount uint64 `json:"maxMasterCount"`
|
||||||
|
|
||||||
|
// Max worker count
|
||||||
|
MaxWorkerCount uint64 `json:"maxWorkerCount"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Shared with
|
||||||
|
SharedWith []uint64 `json:"sharedWith"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Version string `json:"version"`
|
||||||
|
|
||||||
|
// Worker driver
|
||||||
|
WorkerDriver string `json:"workerDriver"`
|
||||||
|
|
||||||
|
// Worker image ID
|
||||||
|
WorkerImageID uint64 `json:"workerImageId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed information about K8CI
|
||||||
type RecordK8CI struct {
|
type RecordK8CI struct {
|
||||||
// Description
|
// Description
|
||||||
Description string `json:"desc"`
|
Description string `json:"desc"`
|
||||||
@@ -52,8 +100,11 @@ type RecordK8CI struct {
|
|||||||
// Name
|
// Name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
//NetworkPlugins
|
||||||
|
NetworkPlugins []string `json:"networkPlugins"`
|
||||||
|
|
||||||
// Shared with
|
// Shared with
|
||||||
SharedWith []interface{} `json:"sharedWith"`
|
SharedWith []uint64 `json:"sharedWith"`
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// type Params []string
|
||||||
|
|
||||||
// Request struct for create K8S
|
// Request struct for create K8S
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// Name of kubernetes cluster
|
// Name of kubernetes cluster
|
||||||
@@ -24,7 +26,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Name for first worker group created with cluster
|
// Name for first worker group created with cluster
|
||||||
// Required: true
|
// Required: true
|
||||||
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"`
|
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
|
||||||
|
|
||||||
// Network plugin
|
// Network plugin
|
||||||
// Must be one of these values: flunnel, weawenet, calico
|
// Must be one of these values: flunnel, weawenet, calico
|
||||||
@@ -100,16 +102,77 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
||||||
|
|
||||||
|
// ID of the ViNS to connect k8s cluster. If nothing is specified, ViNS will be created automatically
|
||||||
|
// Required: false
|
||||||
|
VinsId uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
||||||
|
|
||||||
// Create kubernetes cluster with masters nodes behind load balancer if true.
|
// Create kubernetes cluster with masters nodes behind load balancer if true.
|
||||||
// Otherwise give all cluster nodes direct external addresses from selected external network
|
// Otherwise give all cluster nodes direct external addresses from selected external network
|
||||||
// Required: false
|
// Required: false
|
||||||
WithLB bool `url:"withLB" json:"withLB"`
|
WithLB bool `url:"withLB" json:"withLB"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
LbSysctlParams string `url:"lbSysctlParams,omitempty" json:"lbSysctlParams,omitempty"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
||||||
|
|
||||||
|
// Optional extra Subject Alternative Names (SANs) to use for the API Server serving certificate. Can be both IP addresses and DNS names
|
||||||
|
// Required: false
|
||||||
|
AdditionalSANs []string `url:"additionalSANs,omitempty" json:"additionalSANs,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define settings and actions that should be performed before any other component in the cluster starts.
|
||||||
|
// It allows you to configure things like node registration, network setup, and other initialization tasks. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
InitConfiguration string `url:"initConfiguration,omitempty" json:"initConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to define global settings and configurations for the entire cluster.
|
||||||
|
// It includes parameters such as cluster name, DNS settings, authentication methods, and other cluster-wide configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
ClusterConfiguration string `url:"clusterConfiguration,omitempty" json:"clusterConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kubelet, which is the primary node agent that runs on each node in the cluster.
|
||||||
|
// It includes parameters such as node IP address, resource allocation, pod eviction policies, and other Kubelet-specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeletConfiguration string `url:"kubeletConfiguration,omitempty" json:"kubeletConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings of the Kube-proxy, which is responsible for network proxying and load balancing within the cluster.
|
||||||
|
// It includes parameters such as proxy mode, cluster IP ranges, and other Kube-proxy specific configurations.
|
||||||
|
// Insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
KubeProxyConfiguration string `url:"kubeProxyConfiguration,omitempty" json:"kubeProxyConfiguration,omitempty"`
|
||||||
|
|
||||||
|
// Is used to configure the behavior and settings for joining a node to a cluster.
|
||||||
|
// It includes parameters such as the cluster's control plane endpoint, token, and certificate key. insert a valid JSON string with all levels of nesting
|
||||||
|
// Required: false
|
||||||
|
JoinConfiguration string `url:"joinConfiguration,omitempty" json:"joinConfiguration,omitempty"`
|
||||||
|
|
||||||
// Text description of this kubernetes cluster
|
// Text description of this kubernetes cluster
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: false
|
||||||
|
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||||
|
|
||||||
|
// Use only selected ExtNet for infrastructure connections
|
||||||
|
// Required: false
|
||||||
|
ExtNetOnly bool `url:"extnetOnly,omitempty" json:"extnetOnly,omitempty"`
|
||||||
|
|
||||||
|
// Insert ssl certificate in x509 pem format
|
||||||
|
// Required: false
|
||||||
|
OidcCertificate string `url:"oidcCertificate,omitempty" json:"oidcCertificate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// type wrapperCreateRequest struct {
|
||||||
|
// CreateRequest
|
||||||
|
// Params []string `url:"lbSysctlParams,omitempty"`
|
||||||
|
// }
|
||||||
|
|
||||||
// Create creates a new kubernetes cluster in the specified resource group
|
// Create creates a new kubernetes cluster in the specified resource group
|
||||||
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -119,6 +182,28 @@ func (k K8S) Create(ctx context.Context, req CreateRequest) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var params []string
|
||||||
|
|
||||||
|
// if len(req.LbSysctlParams) != 0 {
|
||||||
|
// params = make([]string, 0, len(req.LbSysctlParams))
|
||||||
|
|
||||||
|
// for r := range req.LbSysctlParams {
|
||||||
|
// b, err := json.Marshal(req.LbSysctlParams[r])
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// params = append(params, string(b))
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// params = []string{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// reqWrapped := wrapperCreateRequest{
|
||||||
|
// CreateRequest: req,
|
||||||
|
// Params: params,
|
||||||
|
// }
|
||||||
|
|
||||||
url := "/cloudbroker/k8s/create"
|
url := "/cloudbroker/k8s/create"
|
||||||
|
|
||||||
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
|||||||
38
pkg/cloudbroker/k8s/get_worker_nodes_meta_data.go
Normal file
38
pkg/cloudbroker/k8s/get_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get worker group metadata by ID
|
||||||
|
type GetWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get worker group metadata by ID
|
||||||
|
func (k K8S) GetWorkerNodesMetaData(ctx context.Context, req GetWorkerNodesMetaDataRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/k8s/getWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@ package k8s
|
|||||||
|
|
||||||
// Deteiled information
|
// Deteiled information
|
||||||
type ItemDetailedInfo struct {
|
type ItemDetailedInfo struct {
|
||||||
|
// External Ip
|
||||||
|
ExternalIp string `json:"externalip"`
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
@@ -11,7 +14,7 @@ type ItemDetailedInfo struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
// Status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
48
pkg/cloudbroker/k8s/update_worker_nodes_meta_data.go
Normal file
48
pkg/cloudbroker/k8s/update_worker_nodes_meta_data.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package k8s
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for add worker to a kubernetes cluster
|
||||||
|
type UpdateWorkerNodesMetaDataRequest struct {
|
||||||
|
// Kubernetes cluster ID
|
||||||
|
// Required: true
|
||||||
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the workers compute group
|
||||||
|
// Required: true
|
||||||
|
WorkersGroupID uint64 `url:"workersGroupId" json:"workersGroupId" validate:"required"`
|
||||||
|
|
||||||
|
// Meta data for working group computes, format YAML "user_data": 1111
|
||||||
|
// Required: true
|
||||||
|
UserData string `url:"userData" json:"userData" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// WorkerAdd adds worker nodes to a kubernetes cluster
|
||||||
|
func (k K8S) UpdateWorkerNodesMetaData(ctx context.Context, req UpdateWorkerNodesMetaDataRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/k8s/updateWorkerNodesMetaData"
|
||||||
|
|
||||||
|
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -79,7 +79,11 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
|
// Stack ID
|
||||||
|
// Required: false
|
||||||
|
StackID uint64 `url:"stackId,omitempty" json:"stackId,omitempty"`
|
||||||
|
|
||||||
// System name
|
// System name
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -88,6 +92,10 @@ type CreateRequest struct {
|
|||||||
// Compute purpose
|
// Compute purpose
|
||||||
// Required: false
|
// Required: false
|
||||||
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
IPAType string `url:"ipaType,omitempty" json:"ipaType,omitempty"`
|
||||||
|
|
||||||
|
// Reason for action
|
||||||
|
// Required: false
|
||||||
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateRequest struct {
|
type wrapperCreateRequest struct {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ type MassCreateRequest struct {
|
|||||||
|
|
||||||
// Start after create of not
|
// Start after create of not
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Reason to action
|
// Reason to action
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// Start VM upon success
|
// Start VM upon success
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Stack ID
|
// Stack ID
|
||||||
// Required: false
|
// Required: false
|
||||||
@@ -97,6 +97,10 @@ type CreateRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
CustomField string `url:"customFields,omitempty" json:"customFields,omitempty"`
|
CustomField string `url:"customFields,omitempty" json:"customFields,omitempty"`
|
||||||
|
|
||||||
|
//Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
|
||||||
|
// Required: false
|
||||||
|
Driver string `url:"driver,omitempty" json:"driver,omitempty"`
|
||||||
|
|
||||||
// Reason for action
|
// Reason for action
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ type CreateBlankRequest struct {
|
|||||||
// Text description of this VM
|
// Text description of this VM
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
|
||||||
|
//Type of compute Stateful (KVM_X86) or Stateless (SVA_KVM_X86)
|
||||||
|
// Required: false
|
||||||
|
Driver string `url:"driver,omitempty" json:"driver,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type wrapperCreateBlankRequest struct {
|
type wrapperCreateBlankRequest struct {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ type MassCreateRequest struct {
|
|||||||
|
|
||||||
// Start after create of not
|
// Start after create of not
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start,omitempty" json:"start,omitempty"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Reason to action
|
// Reason to action
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package lb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Params []string
|
||||||
|
|
||||||
// Request struct for create load balancer
|
// Request struct for create load balancer
|
||||||
type CreateRequest struct {
|
type CreateRequest struct {
|
||||||
// ID of the resource group where this load balancer instance will be located
|
// ID of the resource group where this load balancer instance will be located
|
||||||
@@ -20,22 +24,35 @@ type CreateRequest struct {
|
|||||||
Name string `url:"name" json:"name" validate:"required"`
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
// External network to connect this load balancer to
|
// External network to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
ExtNetID uint64 `url:"extnetId" json:"extnetId" validate:"required"`
|
ExtNetID uint64 `url:"extnetId" json:"extnetId"`
|
||||||
|
|
||||||
// Internal network (VINS) to connect this load balancer to
|
// Internal network (VINS) to connect this load balancer to
|
||||||
// Required: true
|
// Required: false
|
||||||
VINSID uint64 `url:"vinsId" json:"vinsId" validate:"required"`
|
VINSID uint64 `url:"vinsId" json:"vinsId"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: false
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
|
// Use Highly Available schema for LB deploy
|
||||||
|
// Required: false
|
||||||
|
HighlyAvailable bool `url:"highlyAvailable,omitempty" json:"highlyAvailable,omitempty"`
|
||||||
|
|
||||||
// Start now Load balancer
|
// Start now Load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
Start bool `url:"start" json:"start" validate:"required"`
|
Start bool `url:"start" json:"start"`
|
||||||
|
|
||||||
// Text description of this load balancer
|
// Text description of this load balancer
|
||||||
// Required: false
|
// Required: false
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequest struct {
|
||||||
|
CreateRequest
|
||||||
|
Params []string `url:"sysctlParams,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Create method will create a new load balancer instance
|
// Create method will create a new load balancer instance
|
||||||
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -45,9 +62,35 @@ func (lb LB) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if req.ExtNetID == 0 && req.VINSID == 0 {
|
||||||
|
return 0, errors.New("vinsId and extNetId cannot be both in the value 0")
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequest{
|
||||||
|
CreateRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/lb/create"
|
url := "/cloudbroker/lb/create"
|
||||||
|
|
||||||
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := lb.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// FilterByID returns ListLB with specified ID.
|
// FilterByID returns ListLB with specified ID.
|
||||||
func (ll ListLB) FilterByID(id uint64) ListLB {
|
func (ll ListLB) FilterByID(id uint64) ListLB {
|
||||||
predicate := func(rlb RecordLB) bool {
|
predicate := func(rlb ItemLBList) bool {
|
||||||
return rlb.ID == id
|
return rlb.ID == id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ func (ll ListLB) FilterByID(id uint64) ListLB {
|
|||||||
|
|
||||||
// FilterByName returns ListLB with specified Name.
|
// FilterByName returns ListLB with specified Name.
|
||||||
func (ll ListLB) FilterByName(name string) ListLB {
|
func (ll ListLB) FilterByName(name string) ListLB {
|
||||||
predicate := func(rlb RecordLB) bool {
|
predicate := func(rlb ItemLBList) bool {
|
||||||
return rlb.Name == name
|
return rlb.Name == name
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,22 +27,13 @@ func (ll ListLB) FilterByName(name string) ListLB {
|
|||||||
|
|
||||||
// FilterByExtNetID returns ListLB with specified ExtNetID.
|
// FilterByExtNetID returns ListLB with specified ExtNetID.
|
||||||
func (ll ListLB) FilterByExtNetID(extNetID uint64) ListLB {
|
func (ll ListLB) FilterByExtNetID(extNetID uint64) ListLB {
|
||||||
predicate := func(rlb RecordLB) bool {
|
predicate := func(rlb ItemLBList) bool {
|
||||||
return rlb.ExtNetID == extNetID
|
return rlb.ExtNetID == extNetID
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll.FilterFunc(predicate)
|
return ll.FilterFunc(predicate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterByImageID returns ListLB with specified ImageID.
|
|
||||||
func (ll ListLB) FilterByImageID(imageID uint64) ListLB {
|
|
||||||
predicate := func(rlb RecordLB) bool {
|
|
||||||
return rlb.ImageID == imageID
|
|
||||||
}
|
|
||||||
|
|
||||||
return ll.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
// FilterByK8SID returns ListLB used by specified K8S cluster.
|
||||||
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
|
func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListLB, error) {
|
||||||
caller := k8s.New(decortClient)
|
caller := k8s.New(decortClient)
|
||||||
@@ -56,7 +47,7 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate := func(rlb RecordLB) bool {
|
predicate := func(rlb ItemLBList) bool {
|
||||||
return cluster.LBID == rlb.ID
|
return cluster.LBID == rlb.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +57,7 @@ func (ll ListLB) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
// FilterFunc allows filtering ListLB based on a user-specified predicate.
|
||||||
func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB {
|
func (ll ListLB) FilterFunc(predicate func(ItemLBList) bool) ListLB {
|
||||||
var result ListLB
|
var result ListLB
|
||||||
|
|
||||||
for _, item := range ll.Data {
|
for _, item := range ll.Data {
|
||||||
@@ -82,9 +73,9 @@ func (ll ListLB) FilterFunc(predicate func(RecordLB) bool) ListLB {
|
|||||||
|
|
||||||
// FindOne returns first found RecordLB
|
// FindOne returns first found RecordLB
|
||||||
// If none was found, returns an empty struct.
|
// If none was found, returns an empty struct.
|
||||||
func (ll ListLB) FindOne() RecordLB {
|
func (ll ListLB) FindOne() ItemLBList {
|
||||||
if len(ll.Data) == 0 {
|
if len(ll.Data) == 0 {
|
||||||
return RecordLB{}
|
return ItemLBList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ll.Data[0]
|
return ll.Data[0]
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package lb
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var lbs = ListLB{
|
var lbs = ListLB{
|
||||||
Data: []RecordLB{
|
Data: []ItemLBList{
|
||||||
{
|
{
|
||||||
HAMode: true,
|
HAMode: true,
|
||||||
CKey: "",
|
|
||||||
Meta: []interface{}{},
|
|
||||||
ACL: []interface{}{},
|
ACL: []interface{}{},
|
||||||
Backends: []ItemBackend{},
|
Backends: []ItemBackend{},
|
||||||
CreatedBy: "test_user_1",
|
CreatedBy: "test_user_1",
|
||||||
@@ -22,7 +20,6 @@ var lbs = ListLB{
|
|||||||
GID: 212,
|
GID: 212,
|
||||||
GUID: 1,
|
GUID: 1,
|
||||||
ID: 1,
|
ID: 1,
|
||||||
ImageID: 2121,
|
|
||||||
Milestones: 129000,
|
Milestones: 129000,
|
||||||
Name: "k8s-lb-test-1",
|
Name: "k8s-lb-test-1",
|
||||||
PrimaryNode: Node{},
|
PrimaryNode: Node{},
|
||||||
@@ -37,8 +34,6 @@ var lbs = ListLB{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
HAMode: false,
|
HAMode: false,
|
||||||
CKey: "",
|
|
||||||
Meta: []interface{}{},
|
|
||||||
ACL: []interface{}{},
|
ACL: []interface{}{},
|
||||||
Backends: []ItemBackend{},
|
Backends: []ItemBackend{},
|
||||||
CreatedBy: "test_user_2",
|
CreatedBy: "test_user_2",
|
||||||
@@ -53,7 +48,6 @@ var lbs = ListLB{
|
|||||||
GID: 212,
|
GID: 212,
|
||||||
GUID: 2,
|
GUID: 2,
|
||||||
ID: 2,
|
ID: 2,
|
||||||
ImageID: 2129,
|
|
||||||
Milestones: 129013,
|
Milestones: 129013,
|
||||||
Name: "k8s-lb-test-2",
|
Name: "k8s-lb-test-2",
|
||||||
PrimaryNode: Node{},
|
PrimaryNode: Node{},
|
||||||
@@ -68,8 +62,6 @@ var lbs = ListLB{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
HAMode: true,
|
HAMode: true,
|
||||||
CKey: "",
|
|
||||||
Meta: []interface{}{},
|
|
||||||
ACL: []interface{}{},
|
ACL: []interface{}{},
|
||||||
Backends: []ItemBackend{},
|
Backends: []ItemBackend{},
|
||||||
CreatedBy: "te2t_user_3",
|
CreatedBy: "te2t_user_3",
|
||||||
@@ -84,7 +76,6 @@ var lbs = ListLB{
|
|||||||
GID: 212,
|
GID: 212,
|
||||||
GUID: 3,
|
GUID: 3,
|
||||||
ID: 3,
|
ID: 3,
|
||||||
ImageID: 2139,
|
|
||||||
Milestones: 129025,
|
Milestones: 129025,
|
||||||
Name: "k8s-lb-test-3",
|
Name: "k8s-lb-test-3",
|
||||||
PrimaryNode: Node{},
|
PrimaryNode: Node{},
|
||||||
@@ -125,16 +116,8 @@ func TestFilterByExtNetID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterByImageID(t *testing.T) {
|
|
||||||
actual := lbs.FilterByImageID(2139).FindOne()
|
|
||||||
|
|
||||||
if actual.ImageID != 2139 {
|
|
||||||
t.Fatal("expected ImageID 2139, found: ", actual.ImageID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
func TestFilterFunc(t *testing.T) {
|
||||||
actual := lbs.FilterFunc(func(rl RecordLB) bool {
|
actual := lbs.FilterFunc(func(rl ItemLBList) bool {
|
||||||
return rl.Status == "DISABLED"
|
return rl.Status == "DISABLED"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
40
pkg/cloudbroker/lb/make_highly_available.go
Normal file
40
pkg/cloudbroker/lb/make_highly_available.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for make Load Balancer Highly available
|
||||||
|
type HighlyAvailableRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make Load Balancer Highly available
|
||||||
|
func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/lb/makeHighlyAvailable"
|
||||||
|
|
||||||
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -136,7 +136,7 @@ type Node struct {
|
|||||||
// List of load balancers
|
// List of load balancers
|
||||||
type ListLB struct {
|
type ListLB struct {
|
||||||
// Data
|
// Data
|
||||||
Data []RecordLB `json:"data"`
|
Data []ItemLBList `json:"data"`
|
||||||
|
|
||||||
// Entry count
|
// Entry count
|
||||||
EntryCount uint64 `json:"entryCount"`
|
EntryCount uint64 `json:"entryCount"`
|
||||||
@@ -156,6 +156,84 @@ type RecordLB struct {
|
|||||||
// Access Control List
|
// Access Control List
|
||||||
ACL []interface{} `json:"acl"`
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
|
// List of load balancer backends
|
||||||
|
Backends ListBackends `json:"backends"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// DPAPI password
|
||||||
|
DPAPIPassword string `json:"dpApiPassword"`
|
||||||
|
|
||||||
|
// DPAPI user
|
||||||
|
DPAPIUser string `json:"dpApiUser"`
|
||||||
|
|
||||||
|
// External network ID
|
||||||
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
|
// List of load balancer frontends
|
||||||
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Image ID
|
||||||
|
ImageID uint64 `json:"imageId"`
|
||||||
|
|
||||||
|
// Milestones
|
||||||
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Part K8s
|
||||||
|
PartK8s bool `json:"partK8s"`
|
||||||
|
|
||||||
|
// Primary node
|
||||||
|
PrimaryNode Node `json:"primaryNode"`
|
||||||
|
|
||||||
|
// Resource group ID
|
||||||
|
RGID uint64 `json:"rgId"`
|
||||||
|
|
||||||
|
// Secondary node
|
||||||
|
SecondaryNode Node `json:"secondaryNode"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []string `json:"sysctlParams"`
|
||||||
|
|
||||||
|
// Tech status
|
||||||
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
|
// VINS ID
|
||||||
|
VINSID uint64 `json:"vinsId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed information about load balancer in List
|
||||||
|
type ItemLBList struct {
|
||||||
|
// HAMode
|
||||||
|
HAMode bool `json:"HAmode"`
|
||||||
|
|
||||||
|
// Access Control List
|
||||||
|
ACL []interface{} `json:"acl"`
|
||||||
|
|
||||||
|
// BackendHAIP
|
||||||
|
BackendHAIP string `json:"backendHAIP"`
|
||||||
|
|
||||||
// List of load balancer backends
|
// List of load balancer backends
|
||||||
Backends ListBackends `json:"backends"`
|
Backends ListBackends `json:"backends"`
|
||||||
|
|
||||||
@@ -183,6 +261,9 @@ type RecordLB struct {
|
|||||||
// External network ID
|
// External network ID
|
||||||
ExtNetID uint64 `json:"extnetId"`
|
ExtNetID uint64 `json:"extnetId"`
|
||||||
|
|
||||||
|
// FrontendHAIP
|
||||||
|
FrontendHAIP string `json:"frontendHAIP"`
|
||||||
|
|
||||||
// List of load balancer frontends
|
// List of load balancer frontends
|
||||||
Frontends ListFrontends `json:"frontends"`
|
Frontends ListFrontends `json:"frontends"`
|
||||||
|
|
||||||
@@ -195,9 +276,6 @@ type RecordLB struct {
|
|||||||
// ID
|
// ID
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
// Image ID
|
|
||||||
ImageID uint64 `json:"imageId"`
|
|
||||||
|
|
||||||
// Milestones
|
// Milestones
|
||||||
Milestones uint64 `json:"milestones"`
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
@@ -219,6 +297,9 @@ type RecordLB struct {
|
|||||||
// Status
|
// Status
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Sysctl Params
|
||||||
|
SysctlParams []string `json:"sysctlParams"`
|
||||||
|
|
||||||
// Tech status
|
// Tech status
|
||||||
TechStatus string `json:"techStatus"`
|
TechStatus string `json:"techStatus"`
|
||||||
|
|
||||||
|
|||||||
72
pkg/cloudbroker/lb/updateSysctParams.go
Normal file
72
pkg/cloudbroker/lb/updateSysctParams.go
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package lb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for update sysct params for lb
|
||||||
|
type UpdateSysctParamsRequest struct {
|
||||||
|
// ID of the LB instance
|
||||||
|
// Required: true
|
||||||
|
LBID uint64 `url:"lbId" json:"lbId" validate:"required"`
|
||||||
|
|
||||||
|
// Custom sysctl values for Load Balancer instance. Applied on boot
|
||||||
|
// Required: true
|
||||||
|
SysctlParams Params `url:"-" json:"sysctlParams" validate:"required,dive"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperUpdateSysctParamsRequest struct {
|
||||||
|
UpdateSysctParamsRequest
|
||||||
|
Params []string `url:"sysctlParams" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create method will create a new load balancer instance
|
||||||
|
func (l LB) UpdateSysctParams(ctx context.Context, req UpdateSysctParamsRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var params []string
|
||||||
|
|
||||||
|
if len(req.SysctlParams) != 0 {
|
||||||
|
params = make([]string, 0, len(req.SysctlParams))
|
||||||
|
|
||||||
|
for r := range req.SysctlParams {
|
||||||
|
b, err := json.Marshal(req.SysctlParams[r])
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
params = append(params, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
params = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperUpdateSysctParamsRequest{
|
||||||
|
UpdateSysctParamsRequest: req,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/lb/updateSysctParams"
|
||||||
|
|
||||||
|
res, err := l.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -24,10 +24,31 @@ type Total struct {
|
|||||||
UsageLimit uint64 `json:"usage_limit"`
|
UsageLimit uint64 `json:"usage_limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ByPool struct {
|
||||||
|
|
||||||
|
// Disk count
|
||||||
|
DiskCount uint64 `json:"disk_count"`
|
||||||
|
|
||||||
|
// Disk usage
|
||||||
|
DiskUsage uint64 `json:"disk_usage"`
|
||||||
|
|
||||||
|
// Snapshot count
|
||||||
|
SnapshotCount uint64 `json:"snapshot_count"`
|
||||||
|
|
||||||
|
// Snapshot usage
|
||||||
|
SnapshotUsage uint64 `json:"snapshot_usage"`
|
||||||
|
|
||||||
|
// Usage
|
||||||
|
Usage uint64 `json:"usage"`
|
||||||
|
|
||||||
|
// Usage limit
|
||||||
|
UsageLimit uint64 `json:"usage_limit"`
|
||||||
|
}
|
||||||
|
|
||||||
// Main information about consumption
|
// Main information about consumption
|
||||||
type RecordConsumption struct {
|
type RecordConsumption struct {
|
||||||
// By pool
|
// By pool
|
||||||
ByPool map[string]interface{} `json:"byPool"`
|
ByPool map[string]ByPool `json:"byPool"`
|
||||||
|
|
||||||
// Total resource information
|
// Total resource information
|
||||||
Total Total `json:"total"`
|
Total Total `json:"total"`
|
||||||
@@ -70,6 +91,9 @@ type RecordPool struct {
|
|||||||
|
|
||||||
// List URIs
|
// List URIs
|
||||||
URIs ListURIs `json:"uris"`
|
URIs ListURIs `json:"uris"`
|
||||||
|
|
||||||
|
// Usage Limit
|
||||||
|
UsageLimit uint64 `json:"usage_limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SEP config
|
// SEP config
|
||||||
|
|||||||
10
pkg/cloudbroker/stack.go
Normal file
10
pkg/cloudbroker/stack.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Accessing the Stack method group
|
||||||
|
func (cb *CloudBroker) Stack() *stack.Stack {
|
||||||
|
return stack.New(cb.client)
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/stack/get.go
Normal file
42
pkg/cloudbroker/stack/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get list stack
|
||||||
|
type GetRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: true
|
||||||
|
StackId uint64 `url:"stackId" json:"stackId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get stack details by ID
|
||||||
|
func (i Stack) Get(ctx context.Context, req GetRequest) (*InfoStack, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/stack/get"
|
||||||
|
|
||||||
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := InfoStack{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
53
pkg/cloudbroker/stack/list.go
Normal file
53
pkg/cloudbroker/stack/list.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for get list stack
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by type
|
||||||
|
// Required: false
|
||||||
|
Type string `url:"type,omitempty" json:"type,omitempty"`
|
||||||
|
|
||||||
|
// Find by status
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListStacks gets list stack
|
||||||
|
func (i Stack) List(ctx context.Context, req ListRequest) (*ListStacks, error) {
|
||||||
|
url := "/cloudbroker/stack/list"
|
||||||
|
|
||||||
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListStacks{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
164
pkg/cloudbroker/stack/models.go
Normal file
164
pkg/cloudbroker/stack/models.go
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
package stack
|
||||||
|
|
||||||
|
// Main information about stack
|
||||||
|
type InfoStack struct {
|
||||||
|
// CKey
|
||||||
|
Ckey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
//API URL
|
||||||
|
APIURL string `json:"apiUrl"`
|
||||||
|
|
||||||
|
//API key
|
||||||
|
Apikey string `json:"apikey"`
|
||||||
|
|
||||||
|
// App ID
|
||||||
|
AppID string `json:"appId"`
|
||||||
|
|
||||||
|
// CPU allocation ratio
|
||||||
|
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// Descr
|
||||||
|
Descr string `json:"descr"`
|
||||||
|
|
||||||
|
// Drivers
|
||||||
|
Drivers []string `json:"drivers"`
|
||||||
|
|
||||||
|
// Eco
|
||||||
|
Eco interface{} `json:"eco"`
|
||||||
|
|
||||||
|
// Error
|
||||||
|
Error uint64 `json:"error"`
|
||||||
|
|
||||||
|
// Grid ID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
// List image IDs
|
||||||
|
Images []uint64 `json:"images"`
|
||||||
|
|
||||||
|
// Login
|
||||||
|
Login string `json:"login"`
|
||||||
|
|
||||||
|
// Mem allocation ratio
|
||||||
|
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Packegas
|
||||||
|
Packages Packages `json:"packages"`
|
||||||
|
|
||||||
|
//Password
|
||||||
|
Password string `json:"passwd"`
|
||||||
|
|
||||||
|
// Reference ID
|
||||||
|
ReferenceID string `json:"referenceId"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
// Type
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of stacks
|
||||||
|
type ListStacks struct {
|
||||||
|
|
||||||
|
//List
|
||||||
|
Data []InfoStack `json:"data"`
|
||||||
|
|
||||||
|
//Entry count
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Package
|
||||||
|
type Packages struct {
|
||||||
|
|
||||||
|
// LibvirtBin
|
||||||
|
LibvirtBin LibvirtBin `json:"libvirt-bin"`
|
||||||
|
|
||||||
|
// Lvm2Lockd
|
||||||
|
Lvm2Lockd Lvm2Lockd `json:"lvm2-lockd"`
|
||||||
|
|
||||||
|
// OpenvswitchCommon
|
||||||
|
OpenvswitchCommon OpenvswitchCommon `json:"openvswitch-common"`
|
||||||
|
|
||||||
|
// OpenvswitchSwitch
|
||||||
|
OpenvswitchSwitch OpenvswitchSwitch `json:"openvswitch-switch"`
|
||||||
|
|
||||||
|
// QemuSystemX86
|
||||||
|
QemuSystemX86 QemuSystemX86 `json:"qemu-system-x86"`
|
||||||
|
|
||||||
|
// Sanlock
|
||||||
|
Sanlock Sanlock `json:"sanlock"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LibvirtBin
|
||||||
|
type LibvirtBin struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lvm2Lockd
|
||||||
|
type Lvm2Lockd struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenvswitchCommon
|
||||||
|
type OpenvswitchCommon struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenvswitchSwitch
|
||||||
|
type OpenvswitchSwitch struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// QemuSystemX86
|
||||||
|
type QemuSystemX86 struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanlock
|
||||||
|
type Sanlock struct {
|
||||||
|
|
||||||
|
// InstalledSize
|
||||||
|
InstalledSize string `json:"installed_size"`
|
||||||
|
|
||||||
|
// Version
|
||||||
|
Ver string `json:"ver"`
|
||||||
|
}
|
||||||
16
pkg/cloudbroker/stack/stack.go
Normal file
16
pkg/cloudbroker/stack/stack.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Lists all the stack.
|
||||||
|
package stack
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to stack
|
||||||
|
type Stack struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for stack endpoint
|
||||||
|
func New(client interfaces.Caller) *Stack {
|
||||||
|
return &Stack{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,24 @@ package vins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
// Destination network
|
||||||
|
Destination string `url:"destination" json:"destination" validate:"required"`
|
||||||
|
|
||||||
|
//Destination network mask in 255.255.255.255 format
|
||||||
|
Netmask string `url:"netmask" json:"netmask" validate:"required"`
|
||||||
|
|
||||||
|
//Next hop host, IP address from ViNS ID free IP pool
|
||||||
|
Gateway string `url:"gateway" json:"gateway" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Request struct for create VINS in account
|
// Request struct for create VINS in account
|
||||||
type CreateInAccountRequest struct {
|
type CreateInAccountRequest struct {
|
||||||
// VINS name
|
// VINS name
|
||||||
@@ -34,11 +46,20 @@ type CreateInAccountRequest struct {
|
|||||||
// Required: false
|
// Required: false
|
||||||
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
PreReservationsNum uint64 `url:"preReservationsNum,omitempty" json:"preReservationsNum,omitempty"`
|
||||||
|
|
||||||
|
// List of static routes, each item must have destination, netmask, and gateway fields
|
||||||
|
// Required: false
|
||||||
|
Routes []Route `url:"-" json:"routes,omitempty" validate:"omitempty,dive"`
|
||||||
|
|
||||||
// Reason for action
|
// Reason for action
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type wrapperCreateRequestInAcc struct {
|
||||||
|
CreateInAccountRequest
|
||||||
|
Routes []string `url:"routes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// CreateInAccount creates VINS in account level
|
// CreateInAccount creates VINS in account level
|
||||||
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
@@ -48,9 +69,31 @@ func (v VINS) CreateInAccount(ctx context.Context, req CreateInAccountRequest) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var routes []string
|
||||||
|
|
||||||
|
if len(req.Routes) != 0 {
|
||||||
|
routes = make([]string, 0, len(req.Routes))
|
||||||
|
|
||||||
|
for r := range req.Routes {
|
||||||
|
b, err := json.Marshal(req.Routes[r])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
routes = append(routes, string(b))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
routes = []string{"[]"}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateRequestInAcc{
|
||||||
|
CreateInAccountRequest: req,
|
||||||
|
Routes: routes,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/vins/createInAccount"
|
url := "/cloudbroker/vins/createInAccount"
|
||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user