Merge 'dev' into 'main'
This commit is contained in:
64
pkg/cloudbroker/disks/create.go
Normal file
64
pkg/cloudbroker/disks/create.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/rudecs/decort-sdk/internal/validators"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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"`
|
||||
IOPS uint64 `url:"iops,omitempty"`
|
||||
SepID uint64 `url:"sepId,omitempty"`
|
||||
Pool string `url:"pool,omitempty"`
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
}
|
||||
44
pkg/cloudbroker/disks/delete.go
Normal file
44
pkg/cloudbroker/disks/delete.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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 (drq DeleteRequest) Validate() error {
|
||||
if drq.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 := "/cloudbroker/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
|
||||
}
|
||||
46
pkg/cloudbroker/disks/delete_disks.go
Normal file
46
pkg/cloudbroker/disks/delete_disks.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DeleteDisksRequest struct {
|
||||
DiskIDS []uint64 `url:"diskIds"`
|
||||
Reason string `url:"reason"`
|
||||
Permanently bool `url:"permanently,omitempty"`
|
||||
}
|
||||
|
||||
func (drq DeleteDisksRequest) Validate() error {
|
||||
if len(drq.DiskIDS) == 0 {
|
||||
return errors.New("validation-error: field DiskIDs must be set")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) DeleteDisks(ctx context.Context, req DeleteDisksRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
}
|
||||
13
pkg/cloudbroker/disks/disks.go
Normal file
13
pkg/cloudbroker/disks/disks.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package disks
|
||||
|
||||
import "github.com/rudecs/decort-sdk/interfaces"
|
||||
|
||||
type Disks struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
func New(client interfaces.Caller) *Disks {
|
||||
return &Disks{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
43
pkg/cloudbroker/disks/get.go
Normal file
43
pkg/cloudbroker/disks/get.go
Normal file
@@ -0,0 +1,43 @@
|
||||
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 must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Get(ctx context.Context, req GetRequest) (*Disk, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/get"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disk := Disk{}
|
||||
|
||||
err = json.Unmarshal(res, &disk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &disk, nil
|
||||
}
|
||||
55
pkg/cloudbroker/disks/limit_io.go
Normal file
55
pkg/cloudbroker/disks/limit_io.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
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"`
|
||||
TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty"`
|
||||
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func (drq LimitIORequest) Validate() error {
|
||||
if drq.DiskID == 0 {
|
||||
return errors.New("validation-error: field DiskID must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) LimitIO(ctx context.Context, req LimitIORequest) (bool, error) {
|
||||
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
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
32
pkg/cloudbroker/disks/list.go
Normal file
32
pkg/cloudbroker/disks/list.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/list"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listDisks := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &listDisks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return listDisks, nil
|
||||
}
|
||||
41
pkg/cloudbroker/disks/list_deleted.go
Normal file
41
pkg/cloudbroker/disks/list_deleted.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeletedDisks, error) {
|
||||
url := "/cloudbroker/disks/listDeleted"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deletedDisks := ListDeletedDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &deletedDisks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deletedDisks, nil
|
||||
}
|
||||
30
pkg/cloudbroker/disks/list_types.go
Normal file
30
pkg/cloudbroker/disks/list_types.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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 := "/cloudbroker/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
|
||||
|
||||
}
|
||||
39
pkg/cloudbroker/disks/list_unattached.go
Normal file
39
pkg/cloudbroker/disks/list_unattached.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ListUnattachedRequest struct {
|
||||
AccountID uint64 `url:"accountId"`
|
||||
}
|
||||
|
||||
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) {
|
||||
url := "/cloudbroker/disks/listUnattached"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListUnattached{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
}
|
||||
101
pkg/cloudbroker/disks/models.go
Normal file
101
pkg/cloudbroker/disks/models.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package disks
|
||||
|
||||
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 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"`
|
||||
}
|
||||
|
||||
type Disk struct {
|
||||
DeviceName string `json:"devicename"`
|
||||
SepType string `json:"sepType"`
|
||||
Info
|
||||
}
|
||||
|
||||
type ListDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
}
|
||||
|
||||
type ListDeletedDisks []struct {
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
ComputeName string `json:"computeName"`
|
||||
MachineID uint64 `json:"machineId"`
|
||||
MachineName string `json:"machineName"`
|
||||
Disk
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
type ListUnattached []struct {
|
||||
CKey string `json:"_ckey"`
|
||||
Meta []interface{} `json:"_meta"`
|
||||
Info
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
UpdatedTime uint64 `json:"updatedTime"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
47
pkg/cloudbroker/disks/rename.go
Normal file
47
pkg/cloudbroker/disks/rename.go
Normal file
@@ -0,0 +1,47 @@
|
||||
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 must be set")
|
||||
}
|
||||
|
||||
if drq.Name == "" {
|
||||
return errors.New("validation-error: field Name must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
|
||||
}
|
||||
67
pkg/cloudbroker/disks/resize.go
Normal file
67
pkg/cloudbroker/disks/resize.go
Normal file
@@ -0,0 +1,67 @@
|
||||
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 must be set")
|
||||
}
|
||||
if drq.Size == 0 {
|
||||
return errors.New("validation-error: field Size must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Resize(ctx context.Context, req ResizeRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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 := "/cloudbroker/disks/resize2"
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
46
pkg/cloudbroker/disks/restore.go
Normal file
46
pkg/cloudbroker/disks/restore.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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 must be set")
|
||||
}
|
||||
if drq.Reason == "" {
|
||||
return errors.New("validation-error: field Reason must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
|
||||
}
|
||||
34
pkg/cloudbroker/disks/search.go
Normal file
34
pkg/cloudbroker/disks/search.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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"`
|
||||
Page uint64 `url:"page,omitempty"`
|
||||
Size uint64 `url:"size,omitempty"`
|
||||
}
|
||||
|
||||
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListDisks, error) {
|
||||
url := "/cloudbroker/disks/search"
|
||||
|
||||
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
diskList := ListDisks{}
|
||||
|
||||
err = json.Unmarshal(res, &diskList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return diskList, nil
|
||||
|
||||
}
|
||||
46
pkg/cloudbroker/disks/snapshot_delete.go
Normal file
46
pkg/cloudbroker/disks/snapshot_delete.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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 must be set")
|
||||
}
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
|
||||
}
|
||||
50
pkg/cloudbroker/disks/snapshot_rollback.go
Normal file
50
pkg/cloudbroker/disks/snapshot_rollback.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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 must be set")
|
||||
}
|
||||
if drq.Label == "" {
|
||||
return errors.New("validation-error: field Label must be set")
|
||||
}
|
||||
if drq.TimeStamp == 0 {
|
||||
return errors.New("validation-error: field TimeStamp must be set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
url := "/cloudbroker/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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user