Compare commits
4 Commits
main
...
1.5.8-k8s-
Author | SHA1 | Date |
---|---|---|
|
1972956aeb | 1 year ago |
|
afcbc7e749 | 1 year ago |
|
0b3de4df7f | 1 year ago |
|
c0608d08b9 | 1 year ago |
@ -1,40 +1,4 @@
|
|||||||
## Version 1.10.1
|
## Version 1.6.0-beta
|
||||||
|
|
||||||
### Добавлено
|
|
||||||
|
|
||||||
#### compute
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-268 | Вычисляемое поле `PreferredCPU` в моделях `RecordCompute, ItemCompute, InfoCompute` в cloudapi/compute и cloudbroker/compute |
|
|
||||||
| BGOS-268 | Опциональное поле `PreferredCPU` в структурах `ResizeRequest, UpdateRequest` в cloudapi/compute и cloudbroker/compute |
|
|
||||||
|
|
||||||
#### kvmx86
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-268 | Опциональное поле `PreferredCPU` в структурах `CreateRequest, CreateBlankRequest` в cloudapi/kvmx86 и cloudbroker/kvmx86 |
|
|
||||||
|
|
||||||
#### node
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-270 | Вычисляемые поля `DPDK, UEFIFirmwareFile` в модели `ItemNode` в cloudbroker/node |
|
|
||||||
| BGOS-271 | Вычисляемые поля `DPDK, NetworkMode, ToActive, ToInstalling, ToMaintenance, ToRestricted` в моделях `RecordNode` в cloudbroker/node |
|
|
||||||
|
|
||||||
#### sep
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-273 | Вычисляемое поле `MultipathNum` в модели `RecordSEP` cloudbroker/sep |
|
|
||||||
|
|
||||||
#### vins
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-265 | Вычисляемое поле `AccoundID` в модели `ItemReservation` в cloudbroker/vins |
|
|
||||||
|
|
||||||
### Удалено
|
|
||||||
|
|
||||||
#### sep
|
|
||||||
| Идентификатор<br>задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-272 | Вычисляемые поля `_ckey,_meta` в модели `RecordSEP` в cloudbroker/sep |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Bugfix
|
||||||
|
- Refactored client, made it concurrent safe
|
@ -0,0 +1,62 @@
|
|||||||
|
# Decort SDK
|
||||||
|
|
||||||
|
Decort SDK is a library, written in GO (Golang) for interact with the **DECORT** API.
|
||||||
|
The library contents structures and methods for requesting to an user (cloudapi) and admin (cloudbroker) groups of API.
|
||||||
|
Also the library have structures for responses.
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
|
||||||
|
- [Install](#install)
|
||||||
|
- [API List](#api-list)
|
||||||
|
- [Examples](#examples)
|
||||||
|
- [Examples2](#examples2)
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||||
|
```
|
||||||
|
|
||||||
|
## API List
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/kvmx86"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg := config.Config{
|
||||||
|
AppID: "<APPID>",
|
||||||
|
AppSecret: "<APPSECRET>",
|
||||||
|
SSOURL: "https://sso.digitalenergy.online",
|
||||||
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
|
Retries: 5,
|
||||||
|
}
|
||||||
|
client := decort.New(cfg)
|
||||||
|
req := kvmx86.CreateRequest{
|
||||||
|
RGID: 123,
|
||||||
|
Name: "compute",
|
||||||
|
CPU: 4,
|
||||||
|
RAM: 4096,
|
||||||
|
ImageID: 321,
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := client.KVMX86().Create(context.Background(), req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(res)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples2
|
@ -1,216 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BVSConfig struct {
|
|
||||||
// ServiceAccount username
|
|
||||||
// Required: true
|
|
||||||
// Example : "osh_mikoev"
|
|
||||||
Username string `json:"username" yaml:"username" validate:"required"`
|
|
||||||
|
|
||||||
// ServiceAccount password
|
|
||||||
// Required: true
|
|
||||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
|
||||||
Password string `json:"password" yaml:"password" validate:"required"`
|
|
||||||
|
|
||||||
// Domain name
|
|
||||||
// Required: true
|
|
||||||
// Example: "dynamix"
|
|
||||||
Domain string `json:"domain" yaml:"domain" validate:"required"`
|
|
||||||
|
|
||||||
// Application (client) identifier for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Required: true
|
|
||||||
// Example: "ewqfrvea7s890avw804389qwguf234h0otfi3w4eiu"
|
|
||||||
AppID string `json:"appId" yaml:"appId" validate:"required"`
|
|
||||||
|
|
||||||
// Application (client) secret code for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Example: "frvet09rvesfis0c9erv9fsov0vsdfi09ovds0f"
|
|
||||||
AppSecret string `json:"appSecret" yaml:"appSecret" validate:"required"`
|
|
||||||
|
|
||||||
// Platform authentication service address
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://sso.digitalenergy.online"
|
|
||||||
SSOURL string `json:"ssoUrl" yaml:"ssoUrl" validate:"url"`
|
|
||||||
|
|
||||||
// The address of the platform on which the actions are planned
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://mr4.digitalenergy.online"
|
|
||||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
|
||||||
|
|
||||||
// JWT platform token
|
|
||||||
// Required: false
|
|
||||||
// Example: "qwqwdfwv68979we0q9bfv7e9sbvd89798qrwv97ff"
|
|
||||||
Token Token `json:"token" yaml:"token"`
|
|
||||||
|
|
||||||
// Amount platform request attempts
|
|
||||||
// Default value: 5
|
|
||||||
// Required: false
|
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
|
||||||
|
|
||||||
// Skip verify
|
|
||||||
// Required: false
|
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
|
||||||
|
|
||||||
// HTTP client timeout, unlimited if left empty
|
|
||||||
// Required: false
|
|
||||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
|
||||||
|
|
||||||
// The path of the configuration file entry
|
|
||||||
// Required: false
|
|
||||||
PathCfg string `json:"path_cfg" yaml:"path_cfg"`
|
|
||||||
|
|
||||||
// The path of the token file entry
|
|
||||||
// Required: false
|
|
||||||
PathToken string `json:"path_token" yaml:"path_token"`
|
|
||||||
|
|
||||||
// The number of minutes before the expiration of the token, a refresh will be made
|
|
||||||
// Required: false
|
|
||||||
TimeToRefresh int64 `json:"timeToRefresh" yaml:"timeToRefresh"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Token struct {
|
|
||||||
// AccessToken is the token that authorizes and authenticates
|
|
||||||
// the requests.
|
|
||||||
// Required: false
|
|
||||||
AccessToken string `json:"access_token" yaml:"access_token"`
|
|
||||||
|
|
||||||
// TokenType is the type of token.
|
|
||||||
// The Type method returns either this or "Bearer", the default.
|
|
||||||
// Required: false
|
|
||||||
TokenType string `json:"token_type" yaml:"token_type"`
|
|
||||||
|
|
||||||
// RefreshToken is a token that's used by the application
|
|
||||||
// (as opposed to the user) to refresh the access token
|
|
||||||
// if it expires.
|
|
||||||
// Required: false
|
|
||||||
RefreshToken string `json:"refresh_token" yaml:"refresh_token"`
|
|
||||||
|
|
||||||
// Expiry is the optional expiration time of the access token.
|
|
||||||
// Required: false
|
|
||||||
Expiry time.Time `json:"expiry" yaml:"expiry"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTimeout is used to set HTTP client timeout.
|
|
||||||
func (c *BVSConfig) SetTimeout(dur time.Duration) {
|
|
||||||
c.Timeout = Duration(dur)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
|
||||||
func ParseConfigBVSJSON(path string) (BVSConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config BVSConfig
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigJSON parses Token from specified JSON-formatted file.
|
|
||||||
func ParseTokenBVSJSON(path string) (Token, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var token Token
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseTokenBVSYAML parses Token from specified YAML-formatted file.
|
|
||||||
func ParseTokenBVSYAML(path string) (Token, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var token Token
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigYAML parses Config from specified YAML-formatted file.
|
|
||||||
func ParseConfigBVSYAML(path string) (BVSConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config BVSConfig
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Token) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(t, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c BVSConfig) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(c, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(c)
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
// UniversalConfig combines configurations for different types of clients
|
|
||||||
type UniversalConfig struct {
|
|
||||||
Decs3oConfig *Config `json:"decs3oConfig,omitempty" yaml:"decs3oConfig,omitempty"`
|
|
||||||
BVSConfig *BVSConfig `json:"bvsConfig,omitempty" yaml:"bvsConfig,omitempty"`
|
|
||||||
LegacyConfig *LegacyConfig `json:"legacyConfig,omitempty" yaml:"legacyConfig,omitempty"`
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package interfaces
|
|
||||||
|
|
||||||
// Interface to valiate RAM values
|
|
||||||
type RequestWithRAM interface {
|
|
||||||
// GetRAM returns RAM values
|
|
||||||
GetRAM() map[string]uint64
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
const (
|
|
||||||
RESTMACHINE = "/restmachine"
|
|
||||||
|
|
||||||
// RAM_DIVISIBILITY sets divisibility of RAM value
|
|
||||||
RAM_DIVISIBILITY uint64 = 128
|
|
||||||
)
|
|
||||||
|
|
||||||
var FileName = map[string]string{
|
|
||||||
"OidcCertificate": "ca.crt",
|
|
||||||
}
|
|
||||||
|
|
||||||
var K8sValues = []string{"labels", "taints", "annotations, additionalSANs"}
|
|
@ -1,41 +0,0 @@
|
|||||||
package multierror
|
|
||||||
|
|
||||||
func Join(errs ...error) error {
|
|
||||||
n := 0
|
|
||||||
for _, err := range errs {
|
|
||||||
if err != nil {
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if n == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
e := &joinError{
|
|
||||||
errs: make([]error, 0, n),
|
|
||||||
}
|
|
||||||
for _, err := range errs {
|
|
||||||
if err != nil {
|
|
||||||
e.errs = append(e.errs, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
type joinError struct {
|
|
||||||
errs []error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *joinError) Error() string {
|
|
||||||
var b []byte
|
|
||||||
for i, err := range e.errs {
|
|
||||||
if i > 0 {
|
|
||||||
b = append(b, '\n')
|
|
||||||
}
|
|
||||||
b = append(b, err.Error()...)
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *joinError) Unwrap() []error {
|
|
||||||
return e.errs
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for download the resources tracking files for an account
|
||||||
|
type GetConsumptionRequest struct {
|
||||||
|
// ID an account
|
||||||
|
// Required: true
|
||||||
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||||
|
|
||||||
|
// Epoch represents the start time
|
||||||
|
// Required: true
|
||||||
|
Start uint64 `url:"start" json:"start" validate:"required"`
|
||||||
|
|
||||||
|
// Epoch represents the end time
|
||||||
|
// Required: true
|
||||||
|
End uint64 `url:"end" json:"end" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConsumption downloads the resources tracking files for an account within a given period
|
||||||
|
func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/account/getConsumption"
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConsumptionGet downloads the resources tracking files for an account within a given period
|
||||||
|
func (a Account) GetConsumptionGet(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return "", validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudapi/account/getConsumption"
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(res), nil
|
||||||
|
}
|
@ -1,73 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
// IDs gets array of AccountIDs from ListAccounts struct
|
|
||||||
func (la ListAccounts) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(la.Data))
|
|
||||||
for _, acc := range la.Data {
|
|
||||||
res = append(res, acc.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of ComputeIDs from ListComputes struct
|
|
||||||
func (lc ListComputes) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lc.Data))
|
|
||||||
for _, c := range lc.Data {
|
|
||||||
res = append(res, c.ComputeID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of DiskIDs from ListDisks struct
|
|
||||||
func (ld ListDisks) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(ld.Data))
|
|
||||||
for _, d := range ld.Data {
|
|
||||||
res = append(res, d.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of FLIPGroupIDs from ListFLIPGroups struct
|
|
||||||
func (fg ListFLIPGroups) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(fg.Data))
|
|
||||||
for _, g := range fg.Data {
|
|
||||||
res = append(res, g.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of AccountIDs from ListResourceConsumption struct
|
|
||||||
func (rc ListResourceConsumption) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(rc.Data))
|
|
||||||
for _, r := range rc.Data {
|
|
||||||
res = append(res, r.AccountID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of RGIDs from ListRG struct
|
|
||||||
func (rg ListRG) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(rg.Data))
|
|
||||||
for _, g := range rg.Data {
|
|
||||||
res = append(res, g.RGID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of TemplateIDs from ListTemplates struct
|
|
||||||
func (lt ListTemplates) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lt.Data))
|
|
||||||
for _, t := range lt.Data {
|
|
||||||
res = append(res, t.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of VINSIDs from ListVINS struct
|
|
||||||
func (lv ListVINS) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lv.Data))
|
|
||||||
for _, v := range lv.Data {
|
|
||||||
res = append(res, v.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package cloudapi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/audit"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Accessing the Stack method group
|
|
||||||
func (ca *CloudAPI) Audit() *audit.Audit {
|
|
||||||
return audit.New(ca.client)
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
|
||||||
|
|
||||||
// Structure for creating request to audit
|
|
||||||
type Audit struct {
|
|
||||||
client interfaces.Caller
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builder for audit endpoint
|
|
||||||
func New(client interfaces.Caller) *Audit{
|
|
||||||
return &Audit{
|
|
||||||
client: client,
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetRequest struct to get information about account
|
|
||||||
type GetRequest struct {
|
|
||||||
// Audit GUID
|
|
||||||
// Required: true
|
|
||||||
AuditGuid string `url:"auditGuid" json:"auditGuid" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets information about audit as a RecordAudit struct
|
|
||||||
func (a Audit) Get(ctx context.Context, req GetRequest) (*RecordAudit, error) {
|
|
||||||
res, err := a.GetRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := RecordAudit{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRaw gets information about audit as an array of bytes
|
|
||||||
func (a Audit) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/audit/get"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
// Main info about audit
|
|
||||||
type RecordAudit struct {
|
|
||||||
|
|
||||||
// Arguments
|
|
||||||
Arguments string `json:"args"`
|
|
||||||
|
|
||||||
// Call
|
|
||||||
Call string `json:"call"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Kwargs
|
|
||||||
Kwargs string `json:"kwargs"`
|
|
||||||
|
|
||||||
// RemoteAddr
|
|
||||||
RemoteAddr string `json:"remote_addr"`
|
|
||||||
|
|
||||||
// Response time
|
|
||||||
ResponseTime float64 `json:"responsetime"`
|
|
||||||
|
|
||||||
// Result
|
|
||||||
Result string `json:"result"`
|
|
||||||
|
|
||||||
// Status code
|
|
||||||
StatusCode uint64 `json:"statuscode"`
|
|
||||||
|
|
||||||
// Tags
|
|
||||||
Tags string `json:"tags"`
|
|
||||||
|
|
||||||
// Timestamp
|
|
||||||
Timestamp float64 `json:"timestamp"`
|
|
||||||
|
|
||||||
// TimestampEnd
|
|
||||||
TimestampEnd float64 `json:"timestampEnd"`
|
|
||||||
|
|
||||||
// User
|
|
||||||
User string `json:"user"`
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
// IDs gets array of BasicServiceIDs from ListBasicServices struct
|
|
||||||
func (lbs ListBasicServices) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lbs.Data))
|
|
||||||
for _, bs := range lbs.Data {
|
|
||||||
res = append(res, bs.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of ComputeIDs from ListComputes struct
|
|
||||||
func (lc ListComputes) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lc))
|
|
||||||
for _, c := range lc {
|
|
||||||
res = append(res, c.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of GroupIDs from ListGroups struct
|
|
||||||
func (lg ListGroups) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lg))
|
|
||||||
for _, g := range lg {
|
|
||||||
res = append(res, g.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs gets array of GroupComputeIDs from ListGroupComputes struct
|
|
||||||
func (lgc ListGroupComputes) IDs() []uint64 {
|
|
||||||
res := make([]uint64, 0, len(lgc))
|
|
||||||
for _, gc := range lgc {
|
|
||||||
res = append(res, gc.ID)
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package compute
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BootDiskSetRequest struct to set boot disk for compute
|
|
||||||
type BootDiskSetRequest struct {
|
|
||||||
// ID of compute instance
|
|
||||||
// Required: true
|
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the disk to set as boot
|
|
||||||
// Required: true
|
|
||||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// BootDiskSet sets boot disk for compute
|
|
||||||
func (c Compute) BootDiskSet(ctx context.Context, req BootDiskSetRequest) (bool, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/compute/bootDiskSet"
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package compute
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ChangeIPRequest struct to change IP for network
|
|
||||||
type ChangeIPRequest struct {
|
|
||||||
// ID of compute instance
|
|
||||||
// Required: true
|
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
||||||
|
|
||||||
// Network type
|
|
||||||
// 'EXTNET' for connect to external network directly
|
|
||||||
// 'VINS' for connect to ViNS
|
|
||||||
// Required: true
|
|
||||||
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
|
||||||
|
|
||||||
// Network ID for connect to
|
|
||||||
// For EXTNET - external network ID
|
|
||||||
// For VINS - VINS ID
|
|
||||||
// Required: true
|
|
||||||
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
|
||||||
|
|
||||||
// IP address to which we will change the existing one, it must be from the same subnet
|
|
||||||
// Required: true
|
|
||||||
IPAddr string `url:"ipAddr" json:"ipAddr" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangeIP change reserved IP for compute instance
|
|
||||||
func (c Compute) ChangeIP(ctx context.Context, req ChangeIPRequest) (bool, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/compute/changeIp"
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue