v1.0.0
This commit is contained in:
@@ -3,37 +3,68 @@ package disks
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create disk
|
||||
type CreateRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
GID uint64 `url:"gid"`
|
||||
Name string `url:"name"`
|
||||
// ID of the account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId"`
|
||||
|
||||
// ID of the grid (platform)
|
||||
// Required: true
|
||||
GID uint64 `url:"gid"`
|
||||
|
||||
// Name of disk
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
|
||||
// Description of disk
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
Type string `url:"type"`
|
||||
SSDSize uint64 `url:"ssdSize"`
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
|
||||
// Size in GB, default is 0
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
|
||||
// Type of disk
|
||||
// - B=Boot
|
||||
// - D=Data
|
||||
// - T=Temp
|
||||
// Required: true
|
||||
Type string `url:"type"`
|
||||
|
||||
// Size in GB default is 0
|
||||
// Required: false
|
||||
SSDSize uint64 `url:"ssdSize,omitempty"`
|
||||
|
||||
// Max IOPS disk can perform defaults to 2000
|
||||
// Required: false
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
|
||||
// Storage endpoint provider ID to create disk
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sep_id,omitempty"`
|
||||
|
||||
// Pool name to create disk
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty"`
|
||||
}
|
||||
|
||||
func (drq CreateRequest) Validate() error {
|
||||
func (drq CreateRequest) validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
if drq.GID == 0 {
|
||||
return errors.New("validation-error: field GID must be set")
|
||||
}
|
||||
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
validate := validators.StringInSlice(drq.Type, []string{"B", "D", "T"})
|
||||
if !validate {
|
||||
return errors.New("validation-error: field must be B, D or T")
|
||||
@@ -42,8 +73,9 @@ func (drq CreateRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create creates a disk
|
||||
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -61,4 +93,4 @@ func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,26 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request for delete disk
|
||||
type DeleteRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Detach bool `url:"detach,omitempty"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
Reason string `url:"reason,omitempty"`
|
||||
// ID of disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
|
||||
// Detach disk from machine first
|
||||
// Required: false
|
||||
Detach bool `url:"detach,omitempty"`
|
||||
|
||||
// Whether to completely delete the disk, works only with non attached disks
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
|
||||
// Reason to delete
|
||||
// Required: false
|
||||
Reason string `url:"reason,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DeleteRequest) Validate() error {
|
||||
func (drq DeleteRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -22,8 +34,9 @@ func (drq DeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete deletes disk by ID
|
||||
func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -41,4 +54,4 @@ func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,23 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for multiple disks
|
||||
type DeleteDisksRequest struct {
|
||||
DiskIDS []uint64 `url:"diskIds"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
// List of disk ids to delete
|
||||
// Required: true
|
||||
DisksIDs []uint64 `url:"diskIds"`
|
||||
|
||||
// Reason for deleting the disks
|
||||
// Required: true
|
||||
Reason string `url:"reason"`
|
||||
|
||||
// Whether to completely delete the disks, works only with non attached disks
|
||||
// Required: false
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DeleteDisksRequest) Validate() error {
|
||||
if len(drq.DiskIDS) == 0 {
|
||||
func (drq DeleteDisksRequest) validate() error {
|
||||
if len(drq.DisksIDs) == 0 {
|
||||
return errors.New("validation-error: field DiskIDs must be set")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
@@ -24,8 +33,9 @@ func (drq DeleteDisksRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDisks deletes multiple disks permanently
|
||||
func (d Disks) DeleteDisks(ctx context.Context, req DeleteDisksRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// API Actor for managing Disk. This actor is a final API for admin to manage Disk
|
||||
package disks
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to disks
|
||||
type Disks struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for disks endpoints
|
||||
func New(client interfaces.Caller) *Disks {
|
||||
return &Disks{
|
||||
client: client,
|
||||
|
||||
@@ -7,11 +7,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get information about disk
|
||||
type GetRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
}
|
||||
|
||||
func (drq GetRequest) Validate() error {
|
||||
func (drq GetRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -19,8 +22,10 @@ func (drq GetRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*Disk, error) {
|
||||
err := req.Validate()
|
||||
// Get gets disk details
|
||||
// Notice: the devicename field is the name as it is passed to the kernel (kname in linux) for unattached disks this field has no relevant value
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*RecordDisk, error) {
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -32,12 +37,12 @@ func (d Disks) Get(ctx context.Context, req GetRequest) (*Disk, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disk := Disk{}
|
||||
info := RecordDisk{}
|
||||
|
||||
err = json.Unmarshal(res, &disk)
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &disk, nil
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
@@ -7,25 +7,70 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for limit IO
|
||||
type LimitIORequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
TotalBytesSec uint64 `url:"total_bytes_sec,omitempty"`
|
||||
ReadBytesSec uint64 `url:"total_bytes_sec,omitempty"`
|
||||
WriteBytesSec uint64 `url:"write_bytes_sec,omitempty"`
|
||||
TotalIOPSSec uint64 `url:"total_iops_sec,omitempty"`
|
||||
ReadIOPSSec uint64 `url:"read_iops_sec,omitempty"`
|
||||
WriteIOPSSec uint64 `url:"write_iops_sec,omitempty"`
|
||||
// ID of the disk to limit
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
|
||||
// Alias for total_iops_sec for backwards compatibility
|
||||
// Required: false
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
|
||||
// TotalBytesSec
|
||||
// Required: false
|
||||
TotalBytesSec uint64 `url:"total_bytes_sec,omitempty"`
|
||||
|
||||
// ReadBytesSec
|
||||
// Required: false
|
||||
ReadBytesSec uint64 `url:"read_bytes_sec,omitempty"`
|
||||
|
||||
// WriteBytesSec
|
||||
// Required: false
|
||||
WriteBytesSec uint64 `url:"write_bytes_sec,omitempty"`
|
||||
|
||||
// TotalIOPSSec
|
||||
// Required: false
|
||||
TotalIOPSSec uint64 `url:"total_iops_sec,omitempty"`
|
||||
|
||||
// ReadIOPSSec
|
||||
// Required: false
|
||||
ReadIOPSSec uint64 `url:"read_iops_sec,omitempty"`
|
||||
|
||||
// WriteIOPSSec
|
||||
// Required: false
|
||||
WriteIOPSSec uint64 `url:"write_iops_sec,omitempty"`
|
||||
|
||||
// TotalBytesSecMax
|
||||
// Required: false
|
||||
TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty"`
|
||||
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty"`
|
||||
|
||||
// ReadBytesSecMax
|
||||
// Required: false
|
||||
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty"`
|
||||
|
||||
// WriteBytesSecMax
|
||||
// Required: false
|
||||
WriteBytesSecMax uint64 `url:"write_bytes_sec_max,omitempty"`
|
||||
TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"`
|
||||
ReadIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"`
|
||||
WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty"`
|
||||
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty"`
|
||||
|
||||
// TotalIOPSSecMax
|
||||
// Required: false
|
||||
TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty"`
|
||||
|
||||
// ReadIOPSSecMax
|
||||
// Required: false
|
||||
ReadIOPSSecMax uint64 `url:"read_iops_sec_max,omitempty"`
|
||||
|
||||
// WriteIOPSSecMax
|
||||
// Required: false
|
||||
WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty"`
|
||||
|
||||
// SizeIOPSSec
|
||||
// Required: false
|
||||
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty"`
|
||||
}
|
||||
|
||||
func (drq LimitIORequest) Validate() error {
|
||||
func (drq LimitIORequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -33,14 +78,17 @@ func (drq LimitIORequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LimitIO limit IO for a certain disk
|
||||
// total and read/write options are not allowed to be combined
|
||||
// see http://libvirt.org/formatdomain.html#elementsDisks iotune section for more details
|
||||
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/limitIO"
|
||||
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -52,4 +100,4 @@ func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,26 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list/list_deleted of disks
|
||||
type ListRequest struct {
|
||||
// ID of the account the disks belong to
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
|
||||
// Type of the disks
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list the created disks belonging to an account
|
||||
func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/list"
|
||||
|
||||
@@ -21,12 +34,12 @@ func (d Disks) List(ctx context.Context, req ListRequest) (ListDisks, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listDisks := ListDisks{}
|
||||
list := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &listDisks)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listDisks, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -3,25 +3,29 @@ package disks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted disks
|
||||
type ListDeletedRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (drq ListDeletedRequest) Validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
// ID of the account the disks belong to
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
|
||||
// Type of the disks
|
||||
// Required: false
|
||||
Type string `url:"type,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list the deleted disks based on filter
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) {
|
||||
url := "/cloudbroker/disks/listDeleted"
|
||||
|
||||
@@ -30,12 +34,12 @@ func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDel
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deletedDisks := ListDeletedDisks{}
|
||||
list := ListDeletedDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &deletedDisks)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deletedDisks, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -6,10 +6,14 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list types of disks
|
||||
type ListTypesRequest struct {
|
||||
// Show detailed disk types by seps
|
||||
// Required: false
|
||||
Detailed bool `url:"detailed"`
|
||||
}
|
||||
|
||||
// ListTypes gets list defined disk types
|
||||
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface{}, error) {
|
||||
url := "/cloudbroker/disks/listTypes"
|
||||
|
||||
@@ -18,13 +22,13 @@ func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) ([]interface
|
||||
return nil, err
|
||||
}
|
||||
|
||||
typesList := make([]interface{}, 0)
|
||||
list := make([]interface{}, 0)
|
||||
|
||||
err = json.Unmarshal(res, &typesList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typesList, nil
|
||||
return list, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -3,23 +3,26 @@ package disks
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list unattached disk
|
||||
type ListUnattachedRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
// ID of the account
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (drq ListUnattachedRequest) Validate() error {
|
||||
if drq.AccountID == 0 {
|
||||
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattached, error) {
|
||||
// ListUnattached gets list of unattached disks
|
||||
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (ListUnattachedDisks, error) {
|
||||
url := "/cloudbroker/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
@@ -27,13 +30,12 @@ func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (L
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListUnattached{}
|
||||
list := ListUnattachedDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -1,101 +1,271 @@
|
||||
package disks
|
||||
|
||||
// Main information about IO tune
|
||||
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"`
|
||||
// ReadBytesSec
|
||||
ReadBytesSec uint64 `json:"read_bytes_sec"`
|
||||
|
||||
// ReadBytesSecMax
|
||||
ReadBytesSecMax uint64 `json:"read_bytes_sec_max"`
|
||||
|
||||
// ReadIOPSSec
|
||||
ReadIOPSSec uint64 `json:"read_iops_sec"`
|
||||
|
||||
// ReadIOPSSecMax
|
||||
ReadIOPSSecMax uint64 `json:"read_iops_sec_max"`
|
||||
|
||||
// SizeIOPSSec
|
||||
SizeIOPSSec uint64 `json:"size_iops_sec"`
|
||||
|
||||
// TotalBytesSec
|
||||
TotalBytesSec uint64 `json:"total_bytes_sec"`
|
||||
|
||||
// TotalBytesSecMax
|
||||
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"`
|
||||
|
||||
// TotalIOPSSec
|
||||
TotalIOPSSec uint64 `json:"total_iops_sec"`
|
||||
|
||||
// TotalIOPSSecMax
|
||||
TotalIOPSSecMax uint64 `json:"total_iops_sec_max"`
|
||||
|
||||
// WriteBytesSec
|
||||
WriteBytesSec uint64 `json:"write_bytes_sec"`
|
||||
|
||||
// WriteBytesSecMax
|
||||
WriteBytesSecMax uint64 `json:"write_bytes_sec_max"`
|
||||
WriteIOPSSec uint64 `json:"write_iops_sec"`
|
||||
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
|
||||
|
||||
// WriteIOPSSec
|
||||
WriteIOPSSec uint64 `json:"write_iops_sec"`
|
||||
|
||||
// WriteIOPSSecMax
|
||||
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
AccountID uint64 `json:"accountId"`
|
||||
AccountName string `json:"accountName"`
|
||||
ACL map[string]interface{} `json:"acl"`
|
||||
BootPartition uint64 `json:"bootPartition"`
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
Desc string `json:"desc"`
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
DiskPath string `json:"diskPath"`
|
||||
GID uint64 `json:"gid"`
|
||||
GUID uint64 `json:"guid"`
|
||||
ID uint64 `json:"id"`
|
||||
ImageID uint64 `json:"imageId"`
|
||||
Images []uint64 `json:"images"`
|
||||
IOTune IOTune `json:"iotune"`
|
||||
Iqn string `json:"iqn"`
|
||||
Login string `json:"login"`
|
||||
Milestones uint64 `json:"milestones"`
|
||||
Name string `json:"name"`
|
||||
Order uint64 `json:"order"`
|
||||
Params string `json:"params"`
|
||||
ParentID uint64 `json:"parentId"`
|
||||
Passwd string `json:"passwd"`
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
Pool string `json:"pool"`
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
ReferenceID string `json:"referenceId"`
|
||||
ResID string `json:"resId"`
|
||||
ResName string `json:"resName"`
|
||||
Role string `json:"role"`
|
||||
SepID uint64 `json:"sepId"`
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
SizeUsed uint64 `json:"sizeUsed"`
|
||||
Snapshots []Snapshot `json:"snapshots"`
|
||||
Status string `json:"status"`
|
||||
TechStatus string `json:"techStatus"`
|
||||
Type string `json:"type"`
|
||||
VMID uint64 `json:"vmid"`
|
||||
// Main information about disks
|
||||
type InfoDisk struct {
|
||||
// Account ID
|
||||
AccountID uint64 `json:"accountId"`
|
||||
|
||||
// Account name
|
||||
AccountName string `json:"accountName"`
|
||||
|
||||
// Access Control Control
|
||||
ACL map[string]interface{} `json:"acl"`
|
||||
|
||||
// Boot partition
|
||||
BootPartition uint64 `json:"bootPartition"`
|
||||
|
||||
// Created time
|
||||
CreatedTime uint64 `json:"createdTime"`
|
||||
|
||||
// Deleted time
|
||||
DeletedTime uint64 `json:"deletedTime"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Destruction time
|
||||
DestructionTime uint64 `json:"destructionTime"`
|
||||
|
||||
// Disk path
|
||||
DiskPath string `json:"diskPath"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GUID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Image ID
|
||||
ImageID uint64 `json:"imageId"`
|
||||
|
||||
// List of image IDs
|
||||
Images []uint64 `json:"images"`
|
||||
|
||||
// IOTune
|
||||
IOTune IOTune `json:"iotune"`
|
||||
|
||||
// IQN
|
||||
IQN string `json:"iqn"`
|
||||
|
||||
// Login
|
||||
Login string `json:"login"`
|
||||
|
||||
// Milestones
|
||||
Milestones uint64 `json:"milestones"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Order
|
||||
Order uint64 `json:"order"`
|
||||
|
||||
// Params
|
||||
Params string `json:"params"`
|
||||
|
||||
// Parent ID
|
||||
ParentID uint64 `json:"parentId"`
|
||||
|
||||
// Password
|
||||
Password string `json:"passwd"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
|
||||
// Pool
|
||||
Pool string `json:"pool"`
|
||||
|
||||
// Purge attempts
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
|
||||
// Purge time
|
||||
PurgeTime uint64 `json:"purgeTime"`
|
||||
|
||||
// Reality device number
|
||||
RealityDeviceNumber uint64 `json:"realityDeviceNumber"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
// Resource name
|
||||
ResName string `json:"resName"`
|
||||
|
||||
// Role
|
||||
Role string `json:"role"`
|
||||
|
||||
// SEP ID
|
||||
SEPID uint64 `json:"sepId"`
|
||||
|
||||
// Size max
|
||||
SizeMax uint64 `json:"sizeMax"`
|
||||
|
||||
// Size used
|
||||
SizeUsed uint64 `json:"sizeUsed"`
|
||||
|
||||
// List snapshots
|
||||
Snapshots ListSnapshots `json:"snapshots"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Tech status
|
||||
TechStatus string `json:"techStatus"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"vmid"`
|
||||
}
|
||||
|
||||
type Disk struct {
|
||||
// Detailed indormation about disk
|
||||
type RecordDisk struct {
|
||||
// Device name
|
||||
DeviceName string `json:"devicename"`
|
||||
SepType string `json:"sepType"`
|
||||
Info
|
||||
|
||||
// SEP type
|
||||
SEPType string `json:"sepType"`
|
||||
|
||||
// Main information about disk
|
||||
InfoDisk
|
||||
}
|
||||
|
||||
type ListDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
// Main information for list disks
|
||||
type ItemDisk struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Compute name
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
|
||||
// Machine ID
|
||||
MachineID uint64 `json:"machineId"`
|
||||
|
||||
// Machine name
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
|
||||
// Detailed information about disk
|
||||
RecordDisk
|
||||
}
|
||||
|
||||
type ListDeletedDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
// List disks
|
||||
type ListDisks []ItemDisk
|
||||
|
||||
// Main information about deleted disk
|
||||
type ItemDeletedDisk struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Compute name
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
|
||||
// Machine ID
|
||||
MachineID uint64 `json:"machineId"`
|
||||
|
||||
// Machine name
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Detailed information about disk
|
||||
RecordDisk
|
||||
|
||||
// Updated by
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type ListUnattached []struct {
|
||||
CKey string `json:"_ckey"`
|
||||
// List deleted disks
|
||||
type ListDeletedDisks []ItemDeletedDisk
|
||||
|
||||
// Main information about unattached disk
|
||||
type ItemUnattachedDisk struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Info
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Main information about disk
|
||||
InfoDisk
|
||||
|
||||
// Updated by
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Updated time
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type Snapshot struct {
|
||||
GUID string `json:"guid"`
|
||||
Label string `json:"label"`
|
||||
ResID string `json:"resId"`
|
||||
// List unattached disks
|
||||
type ListUnattachedDisks []ItemUnattachedDisk
|
||||
|
||||
// Main information about snapshot
|
||||
type ItemSnapshot struct {
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Label
|
||||
Label string `json:"label"`
|
||||
|
||||
// Resource ID
|
||||
ResID string `json:"resId"`
|
||||
|
||||
// SnapSet GUID
|
||||
SnapSetGUID string `json:"snapSetGuid"`
|
||||
|
||||
// SnapSet time
|
||||
SnapSetTime uint64 `json:"snapSetTime"`
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
// List snapshots
|
||||
type ListSnapshots []ItemSnapshot
|
||||
|
||||
@@ -7,16 +7,21 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for rename disk
|
||||
type RenameRequest struct {
|
||||
// ID of the disk to rename
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Name string `url:"name"`
|
||||
|
||||
// New name of disk
|
||||
// Required: true
|
||||
Name string `url:"name"`
|
||||
}
|
||||
|
||||
func (drq RenameRequest) Validate() error {
|
||||
func (drq RenameRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
@@ -24,8 +29,9 @@ func (drq RenameRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rename rename disk
|
||||
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -43,5 +49,4 @@ func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for resize disk
|
||||
type ResizeRequest struct {
|
||||
// ID of the disk to resize
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Size uint64 `url:"size"`
|
||||
|
||||
// New size of the disk in GB
|
||||
// Required: true
|
||||
Size uint64 `url:"size"`
|
||||
}
|
||||
|
||||
func (drq ResizeRequest) Validate() error {
|
||||
func (drq ResizeRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -22,8 +28,12 @@ func (drq ResizeRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Resize resize disk
|
||||
// Returns 200 if disk is resized online, else will return 202,
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to computes. Only unassigned disks and disks, assigned with "old" virtual machines.
|
||||
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -41,11 +51,14 @@ func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
// Resize2 resize disk
|
||||
// Returns 200 if disk is resized online, else will return 202,
|
||||
// in that case please stop and start your machine after changing the disk size, for your changes to be reflected.
|
||||
// This method will not be used for disks, assigned to "old" virtual machines. Only unassigned disks and disks, assigned with computes.
|
||||
func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -63,5 +76,4 @@ func (d Disks) Resize2(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for restore a deleted unattached disk
|
||||
type RestoreRequest struct {
|
||||
// ID of the disk to restore
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
|
||||
// Reason for restoring the disk
|
||||
// Required: true
|
||||
Reason string `url:"reason"`
|
||||
}
|
||||
|
||||
func (drq RestoreRequest) Validate() error {
|
||||
func (drq RestoreRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -23,8 +29,9 @@ func (drq RestoreRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Restore restore a deleted unattached disk from recycle bin
|
||||
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -42,5 +49,4 @@ func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -6,14 +6,29 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for search
|
||||
type SearchRequest struct {
|
||||
// ID of the account to search for the Disk
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty"`
|
||||
Name string `url:"name,omitempty"`
|
||||
ShowAll bool `url:"show_all,omitempty"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
// Name of the Disk to search for
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty"`
|
||||
|
||||
// If false, then disks having one of the statuses are not listed
|
||||
// Required: false
|
||||
ShowAll bool `url:"show_all,omitempty"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
// Search search disks
|
||||
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/search"
|
||||
|
||||
@@ -22,13 +37,12 @@ func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListDisks{}
|
||||
list := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
@@ -7,12 +7,18 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for delete snapshot
|
||||
type SnapshotDeleteRequest struct {
|
||||
// ID of disk to delete
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Label string `url:"label"`
|
||||
|
||||
// Label of the snapshot to delete
|
||||
// Required: false
|
||||
Label string `url:"label"`
|
||||
}
|
||||
|
||||
func (drq SnapshotDeleteRequest) Validate() error {
|
||||
func (drq SnapshotDeleteRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -23,8 +29,9 @@ func (drq SnapshotDeleteRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotDelete deletes a snapshot
|
||||
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -42,5 +49,4 @@ func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (b
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,22 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for rollback snapshot
|
||||
type SnapshotRollbackRequest struct {
|
||||
DiskID uint64 `url:"diskId"`
|
||||
Label string `url:"label"`
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId"`
|
||||
|
||||
// Label of the snapshot to rollback
|
||||
// Required: true
|
||||
Label string `url:"label"`
|
||||
|
||||
// Timestamp of the snapshot to rollback
|
||||
// Required: true
|
||||
TimeStamp uint64 `url:"timestamp"`
|
||||
}
|
||||
|
||||
func (drq SnapshotRollbackRequest) Validate() error {
|
||||
func (drq SnapshotRollbackRequest) validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
@@ -27,8 +36,9 @@ func (drq SnapshotRollbackRequest) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SnapshotRollback rollback an individual disk snapshot
|
||||
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
err := req.validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -46,5 +56,4 @@ func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user