Merge 'dev' into 'main'

This commit is contained in:
stSolo
2022-10-03 16:56:47 +03:00
parent 6271fa6d45
commit 5fd450382c
400 changed files with 14394 additions and 13407 deletions

View File

@@ -1,77 +1,67 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type CreateRequest struct {
AccountId uint64 `url:"accountId"`
GID uint64 `url:"gid"`
Name string `url:"name"`
Description string `url:"description,omitempty"`
Size uint64 `url:"size,omitempty"`
Type string `url:"type"`
SSDSize uint64 `url:"ssdSize,omitempty"`
IOps uint64 `url:"iops"`
SepId uint64 `url:"sep_id,omitempty"`
Pool string `url:"pool,omitempty"`
}
func (drq CreateRequest) Validate() error {
if drq.AccountId == 0 {
return errors.New("validation-error: field AccountId can not be empty or equal to 0")
}
if drq.GID == 0 {
return errors.New("validation-error: field Gid can not be empty or equal to 0")
}
if drq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
if !validType {
return errors.New("validation-error: field Type must be set as B, D or T")
}
if drq.IOps == 0 {
return errors.New("validation-error: field IOps must be set")
}
return nil
}
func (d Disks) Create(ctx context.Context, req CreateRequest, options ...opts.DecortOpts) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/disks/create"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, 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
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
type CreateRequest struct {
AccountID uint64 `url:"accountId"`
GID uint64 `url:"gid"`
Name string `url:"name"`
Description string `url:"description,omitempty"`
Size uint64 `url:"size,omitempty"`
Type string `url:"type"`
SSDSize uint64 `url:"ssdSize,omitempty"`
IOps uint64 `url:"iops"`
SepID uint64 `url:"sep_id,omitempty"`
Pool string `url:"pool,omitempty"`
}
func (drq CreateRequest) Validate() error {
if drq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if drq.GID == 0 {
return errors.New("validation-error: field GID can not be empty or equal to 0")
}
if drq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
validType := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
if !validType {
return errors.New("validation-error: field Type must be set as B, D or T")
}
if drq.IOps == 0 {
return errors.New("validation-error: field IOps must be set")
}
return nil
}
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.Validate()
if err != nil {
return 0, err
}
url := "/cloudapi/disks/create"
res, err := d.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
}

View File

@@ -1,53 +1,43 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DeleteRequest struct {
DiskId uint64 `url:"diskId"`
Detach bool `url:"detach,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (d DeleteRequest) Validate() error {
if d.DiskId == 0 {
return errors.New("validation-error: field DiskId must be set")
}
return nil
}
func (d Disks) Delete(ctx context.Context, req DeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/delete"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type DeleteRequest struct {
DiskID uint64 `url:"diskId"`
Detach bool `url:"detach,omitempty"`
Permanently bool `url:"permanently,omitempty"`
Reason string `url:"reason,omitempty"`
}
func (d DeleteRequest) Validate() error {
if d.DiskID == 0 {
return errors.New("validation-error: field DiskID must be set")
}
return nil
}
func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/delete"
res, err := d.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
}

View File

@@ -1,55 +1,44 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type DisksDeleteRequest struct {
DisksIds []uint64 `url:"diskIds"`
Reason string `url:"reason"`
Permanently bool `url:"permanently"`
}
func (drq DisksDeleteRequest) Validate() error {
if len(drq.DisksIds) == 0 {
return errors.New("validation-error: field DisksIds must include one or more disks ids")
}
return nil
}
func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/deleteDisks"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type DisksDeleteRequest struct {
DisksIDs []uint64 `url:"diskIds"`
Reason string `url:"reason"`
Permanently bool `url:"permanently"`
}
func (drq DisksDeleteRequest) Validate() error {
if len(drq.DisksIDs) == 0 {
return errors.New("validation-error: field DisksIDs must include one or more disks ids")
}
return nil
}
func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/deleteDisks"
res, err := d.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
}

View File

@@ -1,15 +1,15 @@
package disks
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Disks struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Disks {
return &Disks{
client,
}
}
package disks
import (
"github.com/rudecs/decort-sdk/interfaces"
)
type Disks struct {
client interfaces.Caller
}
func New(client interfaces.Caller) *Disks {
return &Disks{
client,
}
}

View File

@@ -1,55 +1,44 @@
package disks
import (
"context"
"encoding/json"
"errors"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type GetRequest struct {
DiskId uint64 `url:"diskId"`
}
func (drq GetRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
return nil
}
func (d Disks) Get(ctx context.Context, req GetRequest, options ...opts.DecortOpts) (*DiskRecord, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/disks/get"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
disk := &DiskRecord{}
err = json.Unmarshal(res, disk)
if err != nil {
return nil, err
}
return disk, nil
}
package disks
import (
"context"
"encoding/json"
"errors"
"net/http"
)
type GetRequest struct {
DiskID uint64 `url:"diskId"`
}
func (drq GetRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (d Disks) Get(ctx context.Context, req GetRequest) (*DiskRecord, error) {
err := req.Validate()
if err != nil {
return nil, err
}
url := "/cloudapi/disks/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
disk := &DiskRecord{}
err = json.Unmarshal(res, disk)
if err != nil {
return nil, err
}
return disk, nil
}

View File

@@ -1,67 +1,56 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type LimitIORequest struct {
DiskId uint64 `url:"diskId"`
IOps uint64 `url:"iops"`
TotalBytesSec uint64 `url:"total_bytes_sec"`
ReadBytesSec uint64 `url:"read_bytes_sec"`
WriteBytesSec uint64 `url:"write_bytes_sec"`
TotalIOpsSec uint64 `url:"total_iops_sec"`
ReadIOpsSec uint64 `url:"read_iops_sec"`
WriteIOpsSec uint64 `url:"write_iops_sec"`
TotalBytesSecMax uint64 `url:"total_bytes_sec_max"`
ReadBytesSecMax uint64 `url:"read_bytes_sec_max"`
WriteBytesSecMax uint64 `url:"write_bytes_sec_max"`
TotalIOpsSecMax uint64 `url:"total_iops_sec_max"`
ReadIOpsSecMax uint64 `url:"read_iops_sec_max"`
WriteIOpsSecMax uint64 `url:"write_iops_sec_max"`
SizeIOpsSec uint64 `url:"size_iops_sec"`
}
func (drq LimitIORequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
return nil
}
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/limitIO"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type LimitIORequest struct {
DiskID uint64 `url:"diskId"`
IOps uint64 `url:"iops"`
TotalBytesSec uint64 `url:"total_bytes_sec"`
ReadBytesSec uint64 `url:"read_bytes_sec"`
WriteBytesSec uint64 `url:"write_bytes_sec"`
TotalIOpsSec uint64 `url:"total_iops_sec"`
ReadIOpsSec uint64 `url:"read_iops_sec"`
WriteIOpsSec uint64 `url:"write_iops_sec"`
TotalBytesSecMax uint64 `url:"total_bytes_sec_max"`
ReadBytesSecMax uint64 `url:"read_bytes_sec_max"`
WriteBytesSecMax uint64 `url:"write_bytes_sec_max"`
TotalIOpsSecMax uint64 `url:"total_iops_sec_max"`
ReadIOpsSecMax uint64 `url:"read_iops_sec_max"`
WriteIOpsSecMax uint64 `url:"write_iops_sec_max"`
SizeIOpsSec uint64 `url:"size_iops_sec"`
}
func (drq LimitIORequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
return nil
}
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/limitIO"
res, err := d.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
}

View File

@@ -1,72 +1,54 @@
package disks
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListRequest struct {
AccountId uint64 `url:"accountId,omitempty"`
Type string `url:"type,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (d Disks) List(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (DiskList, error) {
url := "/disks/list"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}
func (d Disks) ListDeleted(ctx context.Context, req ListRequest, options ...opts.DecortOpts) (DiskList, error) {
url := "/disks/listDeleted"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}
package disks
import (
"context"
"encoding/json"
"net/http"
)
type ListRequest struct {
AccountID uint64 `url:"accountId,omitempty"`
Type string `url:"type,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
}
func (d Disks) List(ctx context.Context, req ListRequest) (DiskList, error) {
url := "/cloudapi/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}
func (d Disks) ListDeleted(ctx context.Context, req ListRequest) (DiskList, error) {
url := "/disks/listDeleted"
prefix := "/cloudapi"
url = prefix + url
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}

View File

@@ -1,41 +1,30 @@
package disks
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListTypesRequest struct {
Detailed bool `url:"detailed"`
}
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest, options ...opts.DecortOpts) ([]interface{}, error) {
url := "/disks/listTypes"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
typesList := make([]interface{}, 0)
err = json.Unmarshal(res, &typesList)
if err != nil {
return nil, err
}
return typesList, nil
}
package disks
import (
"context"
"encoding/json"
"net/http"
)
type ListTypesRequest struct {
Detailed bool `url:"detailed"`
}
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) {
url := "/cloudapi/disks/listTypes"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
typesList := make([]interface{}, 0)
err = json.Unmarshal(res, &typesList)
if err != nil {
return nil, err
}
return typesList, nil
}

View File

@@ -1,41 +1,30 @@
package disks
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ListUnattachedRequest struct {
AccountId uint64 `url:"accountId"`
}
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest, options ...opts.DecortOpts) (DiskList, error) {
url := "/disks/listUnattached"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}
package disks
import (
"context"
"encoding/json"
"net/http"
)
type ListUnattachedRequest struct {
AccountID uint64 `url:"accountId"`
}
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (DiskList, error) {
url := "/cloudapi/disks/listUnattached"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}

View File

@@ -1,116 +1,116 @@
package disks
type Disk struct {
Acl map[string]interface{} `json:"acl"`
AccountID int `json:"accountId"`
AccountName string `json:"accountName"`
BootPartition int `json:"bootPartition"`
CreatedTime uint64 `json:"createdTime"`
ComputeID int `json:"computeId"`
ComputeName string `json:"computeName"`
DeletedTime uint64 `json:"deletedTime"`
DeviceName string `json:"devicename"`
Description string `json:"desc"`
DestructionTime uint64 `json:"destructionTime"`
GID uint64 `json:"gid"`
ID uint64 `json:"id"`
ImageID uint64 `json:"imageId"`
Images []uint64 `json:"images"`
IOTune IOTune `json:"iotune"`
MachineId int `json:"machineId"`
MachineName string `json:"machineName"`
Name string `json:"name"`
Order int `json:"order"`
Params string `json:"params"`
ParentId uint64 `json:"parentId"`
PciSlot uint64 `json:"pciSlot"`
Pool string `json:"pool"`
PurgeTime uint64 `json:"purgeTime"`
ResID string `json:"resId"`
ResName string `json:"resName"`
Role string `json:"role"`
SepType string `json:"sepType"`
SepID int `json:"sepId"` // NOTE: absent from compute/get output
SizeMax int `json:"sizeMax"`
Snapshots []Snapshot `json:"snapshots"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
VMID int `json:"vmid"`
}
type Snapshot struct {
Guid string `json:"guid"`
Label string `json:"label"`
ResId string `json:"resId"`
SnapSetGuid string `json:"snapSetGuid"`
SnapSetTime uint64 `json:"snapSetTime"`
TimeStamp uint64 `json:"timestamp"`
}
type SnapshotList []Snapshot
type IOTune struct {
ReadBytesSec int `json:"read_bytes_sec"`
ReadBytesSecMax int `json:"read_bytes_sec_max"`
ReadIopsSec int `json:"read_iops_sec"`
ReadIopsSecMax int `json:"read_iops_sec_max"`
SizeIopsSec int `json:"size_iops_sec"`
TotalBytesSec int `json:"total_bytes_sec"`
TotalBytesSecMax int `json:"total_bytes_sec_max"`
TotalIopsSec int `json:"total_iops_sec"`
TotalIopsSecMax int `json:"total_iops_sec_max"`
WriteBytesSec int `json:"write_bytes_sec"`
WriteBytesSecMax int `json:"write_bytes_sec_max"`
WriteIopsSec int `json:"write_iops_sec"`
WriteIopsSecMax int `json:"write_iops_sec_max"`
}
type DiskList []Disk
type DisksTypesListCoomon []string
type DisksTypesListDetailed struct {
Pools []Pool `json:"pools"`
SepId uint64 `json:"sepId"`
}
type Pool struct {
Name string `json:"name"`
Types []string `json:"types"`
}
type DiskRecord struct {
Acl map[string]interface{} `json:"acl"`
AccountID int `json:"accountId"`
AccountName string `json:"accountName"`
CreatedTime uint64 `json:"createdTime"`
DeletedTime uint64 `json:"deletedTime"`
DeviceName string `json:"devicename"`
Description string `json:"desc"`
DestructionTime uint64 `json:"destructionTime"`
GID int `json:"gid"`
ID uint `json:"id"`
ImageID int `json:"imageId"`
Images []int `json:"images"`
IOTune IOTune `json:"iotune"`
Name string `json:"name"`
Order int `json:"order"`
Params string `json:"params"`
ParentId int `json:"parentId"`
PciSlot int `json:"pciSlot"`
Pool string `json:"pool"`
PurgeTime uint64 `json:"purgeTime"`
ResID string `json:"resId"`
ResName string `json:"resName"`
Role string `json:"role"`
SepType string `json:"sepType"`
SepID int `json:"sepId"` // NOTE: absent from compute/get output
SizeMax int `json:"sizeMax"`
SizeUsed int `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space
Snapshots []Snapshot `json:"snapshots"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
VMID int `json:"vmid"`
}
package disks
type Disk struct {
ACL map[string]interface{} `json:"acl"`
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
BootPartition uint64 `json:"bootPartition"`
CreatedTime uint64 `json:"createdTime"`
ComputeID uint64 `json:"computeId"`
ComputeName string `json:"computeName"`
DeletedTime uint64 `json:"deletedTime"`
DeviceName string `json:"devicename"`
Description string `json:"desc"`
DestructionTime uint64 `json:"destructionTime"`
GID uint64 `json:"gid"`
ID uint64 `json:"id"`
ImageID uint64 `json:"imageId"`
Images []uint64 `json:"images"`
IOTune IOTune `json:"iotune"`
MachineID uint64 `json:"machineId"`
MachineName string `json:"machineName"`
Name string `json:"name"`
Order uint64 `json:"order"`
Params string `json:"params"`
ParentID uint64 `json:"parentId"`
PciSlot uint64 `json:"pciSlot"`
Pool string `json:"pool"`
PurgeTime uint64 `json:"purgeTime"`
ResID string `json:"resId"`
ResName string `json:"resName"`
Role string `json:"role"`
SepType string `json:"sepType"`
SepID uint64 `json:"sepId"` // NOTE: absent from compute/get output
SizeMax uint64 `json:"sizeMax"`
Snapshots []Snapshot `json:"snapshots"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
VMID uint64 `json:"vmid"`
}
type Snapshot struct {
Guid string `json:"guid"`
Label string `json:"label"`
ResID string `json:"resId"`
SnapSetGuid string `json:"snapSetGuid"`
SnapSetTime uint64 `json:"snapSetTime"`
TimeStamp uint64 `json:"timestamp"`
}
type SnapshotList []Snapshot
type IOTune struct {
ReadBytesSec uint64 `json:"read_bytes_sec"`
ReadBytesSecMax uint64 `json:"read_bytes_sec_max"`
ReadIopsSec uint64 `json:"read_iops_sec"`
ReadIopsSecMax uint64 `json:"read_iops_sec_max"`
SizeIopsSec uint64 `json:"size_iops_sec"`
TotalBytesSec uint64 `json:"total_bytes_sec"`
TotalBytesSecMax uint64 `json:"total_bytes_sec_max"`
TotalIopsSec uint64 `json:"total_iops_sec"`
TotalIopsSecMax uint64 `json:"total_iops_sec_max"`
WriteBytesSec uint64 `json:"write_bytes_sec"`
WriteBytesSecMax uint64 `json:"write_bytes_sec_max"`
WriteIopsSec uint64 `json:"write_iops_sec"`
WriteIopsSecMax uint64 `json:"write_iops_sec_max"`
}
type DiskList []Disk
type DisksTypesListCoomon []string
type DisksTypesListDetailed struct {
Pools []Pool `json:"pools"`
SepID uint64 `json:"sepId"`
}
type Pool struct {
Name string `json:"name"`
Types []string `json:"types"`
}
type DiskRecord struct {
ACL map[string]interface{} `json:"acl"`
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
CreatedTime uint64 `json:"createdTime"`
DeletedTime uint64 `json:"deletedTime"`
DeviceName string `json:"devicename"`
Description string `json:"desc"`
DestructionTime uint64 `json:"destructionTime"`
GID uint64 `json:"gid"`
ID uint64 `json:"id"`
ImageID uint64 `json:"imageId"`
Images []uint64 `json:"images"`
IOTune IOTune `json:"iotune"`
Name string `json:"name"`
Order uint64 `json:"order"`
Params string `json:"params"`
ParentID uint64 `json:"parentId"`
PciSlot uint64 `json:"pciSlot"`
Pool string `json:"pool"`
PurgeTime uint64 `json:"purgeTime"`
ResID string `json:"resId"`
ResName string `json:"resName"`
Role string `json:"role"`
SepType string `json:"sepType"`
SepID uint64 `json:"sepId"` // NOTE: absent from compute/get output
SizeMax uint64 `json:"sizeMax"`
SizeUsed uint64 `json:"sizeUsed"` // sum over all snapshots of this disk to report total consumed space
Snapshots []Snapshot `json:"snapshots"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
Type string `json:"type"`
VMID uint64 `json:"vmid"`
}

View File

@@ -1,58 +1,47 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RenameRequest struct {
DiskId uint64 `url:"diskId"`
Name string `url:"name"`
}
func (drq RenameRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
if drq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
return nil
}
func (d Disks) Rename(ctx context.Context, req RenameRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/rename"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type RenameRequest struct {
DiskID uint64 `url:"diskId"`
Name string `url:"name"`
}
func (drq RenameRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if drq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
return nil
}
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/rename"
res, err := d.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
}

View File

@@ -1,89 +1,71 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type ResizeRequest struct {
DiskId uint64 `url:"diskId"`
Size uint64 `url:"size"`
}
func (drq ResizeRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
if drq.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
return nil
}
func (d Disks) Resize(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/resize"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
func (d Disks) Resize2(ctx context.Context, req ResizeRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/resize2"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type ResizeRequest struct {
DiskID uint64 `url:"diskId"`
Size uint64 `url:"size"`
}
func (drq ResizeRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if drq.Size == 0 {
return errors.New("validation-error: field Size can not be empty or equal to 0")
}
return nil
}
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/resize"
res, err := d.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
}
func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/resize2"
prefix := "/cloudapi"
url = prefix + url
res, err := d.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
}

View File

@@ -1,58 +1,47 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type RestoreRequest struct {
DiskId uint64 `url:"diskId"`
Reason string `url:"reason"`
}
func (drq RestoreRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
if drq.Reason == "" {
return errors.New("validation-error: field Reason can not be empty")
}
return nil
}
func (d Disks) Restore(ctx context.Context, req RestoreRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/restore"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type RestoreRequest struct {
DiskID uint64 `url:"diskId"`
Reason string `url:"reason"`
}
func (drq RestoreRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if drq.Reason == "" {
return errors.New("validation-error: field Reason can not be empty")
}
return nil
}
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/restore"
res, err := d.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
}

View File

@@ -1,43 +1,32 @@
package disks
import (
"context"
"encoding/json"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SearchRequest struct {
AccountId uint64 `url:"accountId,omitempty"`
Name string `url:"name,omitempty"`
ShowAll bool `url:"show_all,omitempty"`
}
func (d Disks) Search(ctx context.Context, req SearchRequest, options ...opts.DecortOpts) (DiskList, error) {
url := "/disks/search"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}
package disks
import (
"context"
"encoding/json"
"net/http"
)
type SearchRequest struct {
AccountID uint64 `url:"accountId,omitempty"`
Name string `url:"name,omitempty"`
ShowAll bool `url:"show_all,omitempty"`
}
func (d Disks) Search(ctx context.Context, req SearchRequest) (DiskList, error) {
url := "/cloudapi/disks/search"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
diskList := DiskList{}
err = json.Unmarshal(res, &diskList)
if err != nil {
return nil, err
}
return diskList, nil
}

View File

@@ -1,58 +1,47 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotDeleteRequest struct {
DiskId uint64 `url:"diskId"`
Label string `url:"label"`
}
func (drq SnapshotDeleteRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
if drq.Label == "" {
return errors.New("validation-error: field Label can not be empty")
}
return nil
}
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/snapshotDelete"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type SnapshotDeleteRequest struct {
DiskID uint64 `url:"diskId"`
Label string `url:"label"`
}
func (drq SnapshotDeleteRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if drq.Label == "" {
return errors.New("validation-error: field Label can not be empty")
}
return nil
}
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/snapshotDelete"
res, err := d.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
}

View File

@@ -1,59 +1,48 @@
package disks
import (
"context"
"errors"
"strconv"
"github.com/rudecs/decort-sdk/opts"
"github.com/rudecs/decort-sdk/typed"
)
type SnapshotRollbackRequest struct {
DiskId uint64 `url:"diskId"`
Label string `url:"label"`
TimeStamp uint64 `url:"timestamp"`
}
func (drq SnapshotRollbackRequest) Validate() error {
if drq.DiskId == 0 {
return errors.New("validation-error: field DiskId can not be empty or equal to 0")
}
if drq.Label == "" && drq.TimeStamp == 0 {
return errors.New("validation-error: field Label or field TimeStamp can not be empty")
}
return nil
}
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest, options ...opts.DecortOpts) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/disks/snapshotRollback"
prefix := "/cloudapi"
option := opts.New(options)
if option != nil {
if option.IsAdmin {
prefix = "/" + option.AdminValue
}
}
url = prefix + url
res, err := d.client.DecortApiCall(ctx, typed.POST, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
package disks
import (
"context"
"errors"
"net/http"
"strconv"
)
type SnapshotRollbackRequest struct {
DiskID uint64 `url:"diskId"`
Label string `url:"label"`
TimeStamp uint64 `url:"timestamp"`
}
func (drq SnapshotRollbackRequest) Validate() error {
if drq.DiskID == 0 {
return errors.New("validation-error: field DiskID can not be empty or equal to 0")
}
if drq.Label == "" && drq.TimeStamp == 0 {
return errors.New("validation-error: field Label or field TimeStamp can not be empty")
}
return nil
}
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := req.Validate()
if err != nil {
return false, err
}
url := "/cloudapi/disks/snapshotRollback"
res, err := d.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
}