This commit is contained in:
asteam
2025-09-23 14:34:24 +03:00
parent b924e85e49
commit f1ffb4c0fd
1108 changed files with 72020 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// CreateRequest struct to create disk
type CreateRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID of the grid (platform)
// Required: true
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Name of disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Description of disk
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// Size in GB, default is 0
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Type of disk
// - B=Boot
// - D=Data
// - T=Temp
// Required: true
Type string `url:"type" json:"type" validate:"diskType"`
// Size in GB default is 0
// Required: false
SSDSize uint64 `url:"ssdSize,omitempty" json:"ssdSize,omitempty"`
// Max IOPS disk can perform defaults to 2000
// Required: false
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`
// Storage endpoint provider ID to create disk
// Required: false
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
// Pool name to create disk
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
}
// Create creates a disk
func (d Disks) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,46 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DeleteRequest to delete disk
type DeleteRequest struct {
// ID of disk to delete
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Detach disk from machine first
// Required: false
Detach bool `url:"detach,omitempty" json:"detach,omitempty"`
// Whether to completely delete the disk, works only with non attached disks
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
// Delete deletes disk by ID
func (d Disks) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,42 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// DisksDeleteRequest struct for multiple disks
type DisksDeleteRequest struct {
// List of disk ids to delete
// Required: true
DisksIDs []uint64 `url:"diskIds" json:"diskIds" validate:"required"`
// Whether to completely delete the disks, works only with non attached disks
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
// DeleteDisks deletes multiple disks permanently
func (d Disks) DeleteDisks(ctx context.Context, req DisksDeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,18 @@
// API Actor api, this actor is the final api a enduser uses to manage his resources
package disks
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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,
}
}

View File

@@ -0,0 +1,321 @@
package disks
import (
"context"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudapi/k8s"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/pkg/cloudapi/lb"
)
// FilterByID returns ListDisks with specified ID.
func (ld ListDisks) FilterByID(id uint64) ListDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.ID == id
}
return ld.FilterFunc(predicate)
}
// FilterByName returns ListDisks with specified Name.
func (ld ListDisks) FilterByName(name string) ListDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.Name == name
}
return ld.FilterFunc(predicate)
}
// FilterByStatus returns ListDisks with specified Status.
func (ld ListDisks) FilterByStatus(status string) ListDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.Status == status
}
return ld.FilterFunc(predicate)
}
// FilterByTechStatus returns ListDisks with specified TechStatus.
func (ld ListDisks) FilterByTechStatus(techStatus string) ListDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.TechStatus == techStatus
}
return ld.FilterFunc(predicate)
}
// FilterByComputeID is used to filter ListDisks attached to specified compute.
func (ld ListDisks) FilterByComputeID(computeID uint64) ListDisks {
predicate := func(idisk ItemDisk) bool {
for k := range idisk.Computes {
if k == strconv.FormatUint(computeID, 10) {
return true
}
}
return false
}
return ld.FilterFunc(predicate)
}
// FilterByK8SID is used to filter ListDisks by specified K8S cluster.
func (ld ListDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListDisks, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
K8SID: k8sID,
}
cluster, err := caller.Get(ctx, req)
if err != nil {
return nil, err
}
var result ListDisks
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
result.Data = append(result.Data, ld.FilterByComputeID(masterCompute.ID).Data...)
}
for _, workerGroup := range cluster.K8SGroups.Workers {
for _, workerCompute := range workerGroup.DetailedInfo {
result.Data = append(result.Data, ld.FilterByComputeID(workerCompute.ID).Data...)
}
}
result.EntryCount = uint64(len(result.Data))
return &result, nil
}
// FilterByLBID is used to filter ListDisks used by computes inside specified Load Balancer.
func (ld ListDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListDisks, error) {
caller := lb.New(decortClient)
req := lb.GetRequest{
LBID: lbID,
}
foundLB, err := caller.Get(ctx, req)
if err != nil {
return nil, err
}
var result ListDisks
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID).Data...)
result.Data = append(result.Data, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID).Data...)
result.EntryCount = uint64(len(result.Data))
return &result, nil
}
// FilterFunc allows filtering ListDisks based on a user-specified predicate.
func (ld ListDisks) FilterFunc(predicate func(ItemDisk) bool) ListDisks {
var result ListDisks
for _, item := range ld.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemDisk
// If none was found, returns an empty struct.
func (ld ListDisks) FindOne() ItemDisk {
if len(ld.Data) == 0 {
return ItemDisk{}
}
return ld.Data[0]
}
// FilterByID returns ListSearchDisks with specified ID.
func (ld ListSearchDisks) FilterByID(id uint64) ListSearchDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.ID == id
}
return ld.FilterFunc(predicate)
}
// FilterByName returns ListSearchDisks with specified Name.
func (ld ListSearchDisks) FilterByName(name string) ListSearchDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.Name == name
}
return ld.FilterFunc(predicate)
}
// FilterByStatus returns ListSearchDisks with specified Status.
func (ld ListSearchDisks) FilterByStatus(status string) ListSearchDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.Status == status
}
return ld.FilterFunc(predicate)
}
// FilterByTechStatus returns ListSearchDisks with specified TechStatus.
func (ld ListSearchDisks) FilterByTechStatus(techStatus string) ListSearchDisks {
predicate := func(idisk ItemDisk) bool {
return idisk.TechStatus == techStatus
}
return ld.FilterFunc(predicate)
}
// FilterByComputeID is used to filter ListSearchDisks attached to specified compute.
func (ld ListSearchDisks) FilterByComputeID(computeID uint64) ListSearchDisks {
predicate := func(idisk ItemDisk) bool {
for k := range idisk.Computes {
if k == strconv.FormatUint(computeID, 10) {
return true
}
}
return false
}
return ld.FilterFunc(predicate)
}
// FilterByK8SID is used to filter ListSearchDisks by specified K8S cluster.
func (ld ListSearchDisks) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (ListSearchDisks, error) {
caller := k8s.New(decortClient)
req := k8s.GetRequest{
K8SID: k8sID,
}
cluster, err := caller.Get(ctx, req)
if err != nil {
return nil, err
}
var result ListSearchDisks
for _, masterCompute := range cluster.K8SGroups.Masters.DetailedInfo {
result = append(result, ld.FilterByComputeID(masterCompute.ID)...)
}
for _, workerGroup := range cluster.K8SGroups.Workers {
for _, workerCompute := range workerGroup.DetailedInfo {
result = append(result, ld.FilterByComputeID(workerCompute.ID)...)
}
}
return result, nil
}
// FilterByLBID is used to filter ListSearchDisks used by computes inside specified Load Balancer.
func (ld ListSearchDisks) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (ListSearchDisks, error) {
caller := lb.New(decortClient)
req := lb.GetRequest{
LBID: lbID,
}
foundLB, err := caller.Get(ctx, req)
if err != nil {
return nil, err
}
var result ListSearchDisks
result = append(result, ld.FilterByComputeID(foundLB.PrimaryNode.ComputeID)...)
result = append(result, ld.FilterByComputeID(foundLB.SecondaryNode.ComputeID)...)
return result, nil
}
// FilterFunc allows filtering ListSearchDisks based on a user-specified predicate.
func (ld ListSearchDisks) FilterFunc(predicate func(ItemDisk) bool) ListSearchDisks {
var result ListSearchDisks
for _, item := range ld {
if predicate(item) {
result = append(result, item)
}
}
return result
}
// FindOne returns first found ItemDisk
// If none was found, returns an empty struct.
func (ld ListSearchDisks) FindOne() ItemDisk {
if len(ld) == 0 {
return ItemDisk{}
}
return ld[0]
}
// FilterByID returns ListDisksUnattached with specified ID.
func (lu ListDisksUnattached) FilterByID(id uint64) ListDisksUnattached {
predicate := func(idisk ItemDiskUnattached) bool {
return idisk.ID == id
}
return lu.FilterFunc(predicate)
}
// FilterByName returns ListDisksUnattached with specified Name.
func (lu ListDisksUnattached) FilterByName(name string) ListDisksUnattached {
predicate := func(idisk ItemDiskUnattached) bool {
return idisk.Name == name
}
return lu.FilterFunc(predicate)
}
// FilterByStatus returns ListDisksUnattached with specified Status.
func (lu ListDisksUnattached) FilterByStatus(status string) ListDisksUnattached {
predicate := func(idisk ItemDiskUnattached) bool {
return idisk.Status == status
}
return lu.FilterFunc(predicate)
}
// FilterByTechStatus returns ListDisksUnattached with specified TechStatus.
func (lu ListDisksUnattached) FilterByTechStatus(techStatus string) ListDisksUnattached {
predicate := func(idisk ItemDiskUnattached) bool {
return idisk.TechStatus == techStatus
}
return lu.FilterFunc(predicate)
}
// FilterFunc allows filtering ListDisksUnattached based on a user-specified predicate.
func (lu ListDisksUnattached) FilterFunc(predicate func(ItemDiskUnattached) bool) ListDisksUnattached {
var result ListDisksUnattached
for _, item := range lu.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemDiskUnattached
// If none was found, returns an empty struct.
func (lu ListDisksUnattached) FindOne() ItemDiskUnattached {
if len(lu.Data) == 0 {
return ItemDiskUnattached{}
}
return lu.Data[0]
}

View File

@@ -0,0 +1,556 @@
package disks
import (
"testing"
)
var techStatusAllocated = "ALLOCATED"
var disks = ListDisks{
Data: []ItemDisk{
{
MachineID: 0,
MachineName: "",
DeviceName: "vda",
AccountID: 132847,
AccountName: "std_2",
ACL: map[string]interface{}{},
Computes: map[string]string{
"48500": "test",
},
CreatedTime: 1676975177,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
GID: 212,
ID: 65191,
ImageID: 9884,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
Role: "",
Shareable: false,
SizeMax: 2,
SizeUsed: 2,
Snapshots: []ItemSnapshot{},
Status: "ASSIGNED",
TechStatus: techStatusAllocated,
Type: "B",
VMID: 48500,
},
{
MachineID: 0,
MachineName: "",
DeviceName: "vda",
AccountID: 132852,
AccountName: "std",
ACL: map[string]interface{}{},
Computes: map[string]string{
"48502": "stdvm2",
},
CreatedTime: 1676982606,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
GID: 212,
ID: 65193,
ImageID: 9885,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
27,
},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
Role: "",
Shareable: false,
SizeMax: 4,
SizeUsed: 4,
Snapshots: []ItemSnapshot{},
Status: "ASSIGNED",
TechStatus: techStatusAllocated,
Type: "B",
VMID: 48502,
},
},
EntryCount: 2,
}
func TestListDisks_FilterByID(t *testing.T) {
actual := disks.FilterByID(65193)
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
actualItem := actual.FindOne()
if actualItem.ID != 65193 {
t.Fatal("expected ID 65193, found: ", actualItem.ID)
}
}
func TestListDisks_FilterByName(t *testing.T) {
actual := disks.FilterByName("bootdisk")
if len(actual.Data) != 2 {
t.Fatal("expected 2 elements, found: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Name != "bootdisk" {
t.Fatal("expected 'bootdisk' name, found: ", item.Name)
}
}
}
func TestListDisks_FilterByStatus(t *testing.T) {
actual := disks.FilterByStatus("ASSIGNED")
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual.Data {
if item.Status != "ASSIGNED" {
t.Fatal("expected 'ASSIGNED' status, found: ", item.Status)
}
}
}
func TestListDisks_FilterByTechStatus(t *testing.T) {
actual := disks.FilterByTechStatus(techStatusAllocated)
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual.Data {
if item.TechStatus != techStatusAllocated {
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
}
}
}
func TestListDisks_FilterFunc(t *testing.T) {
actual := disks.FilterFunc(func(id ItemDisk) bool {
return len(id.PresentTo) == 2
})
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
if len(actual.Data[0].PresentTo) != 2 {
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual.Data[0].PresentTo))
}
}
func TestListDisks_SortByCreatedTime(t *testing.T) {
actual := disks.SortByCreatedTime(false)
if actual.Data[0].ID != 65191 {
t.Fatal("expected ID 65191, found: ", actual.Data[0].ID)
}
actual = disks.SortByCreatedTime(true)
if actual.Data[0].ID != 65193 {
t.Fatal("expected ID 65193, found: ", actual.Data[0].ID)
}
}
var searchDisks = ListSearchDisks{
ItemDisk{
MachineID: 0,
MachineName: "",
DeviceName: "vda",
AccountID: 132847,
AccountName: "std_2",
ACL: map[string]interface{}{},
Computes: map[string]string{
"48500": "test",
},
CreatedTime: 1676975177,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
GID: 212,
ID: 65191,
ImageID: 9884,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
Role: "",
Shareable: false,
SizeMax: 2,
SizeUsed: 2,
Snapshots: []ItemSnapshot{},
Status: "ASSIGNED",
TechStatus: techStatusAllocated,
Type: "B",
VMID: 48500,
},
ItemDisk{
MachineID: 0,
MachineName: "",
DeviceName: "vda",
AccountID: 132852,
AccountName: "std",
ACL: map[string]interface{}{},
Computes: map[string]string{
"48502": "stdvm2",
},
CreatedTime: 1676982606,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
GID: 212,
ID: 65193,
ImageID: 9885,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
Name: "bootdisk",
Order: 0,
Params: "",
ParentID: 0,
PCISlot: 6,
Pool: "vmstor",
PresentTo: []uint64{
27,
27,
},
PurgeTime: 0,
ResID: "sample",
ResName: "sample",
Role: "",
Shareable: false,
SizeMax: 4,
SizeUsed: 4,
Snapshots: []ItemSnapshot{},
Status: "ASSIGNED",
TechStatus: techStatusAllocated,
Type: "B",
VMID: 48502,
},
}
func TestListSearchDisks_FilterByID(t *testing.T) {
actual := searchDisks.FilterByID(65193)
if len(actual) == 0 {
t.Fatal("No elements were found")
}
actualItem := actual.FindOne()
if actualItem.ID != 65193 {
t.Fatal("expected ID 65193, found: ", actualItem.ID)
}
}
func TestListSearchDisks_FilterByName(t *testing.T) {
actual := searchDisks.FilterByName("bootdisk")
if len(actual) != 2 {
t.Fatal("expected 2 elements, found: ", len(actual))
}
for _, item := range actual {
if item.Name != "bootdisk" {
t.Fatal("expected 'bootdisk' name, found: ", item.Name)
}
}
}
func TestListSearchDisks_FilterByStatus(t *testing.T) {
actual := searchDisks.FilterByStatus("ASSIGNED")
if len(actual) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual {
if item.Status != "ASSIGNED" {
t.Fatal("expected 'ASSIGNED' status, found: ", item.Status)
}
}
}
func TestListSearchDisks_FilterByTechStatus(t *testing.T) {
actual := searchDisks.FilterByTechStatus(techStatusAllocated)
if len(actual) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual {
if item.TechStatus != techStatusAllocated {
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
}
}
}
func TestListSearchDisks_FilterFunc(t *testing.T) {
actual := searchDisks.FilterFunc(func(id ItemDisk) bool {
return len(id.PresentTo) == 2
})
if len(actual) == 0 {
t.Fatal("No elements were found")
}
if len(actual[0].PresentTo) != 2 {
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual[0].PresentTo))
}
}
func TestListSearchDisks_SortByCreatedTime(t *testing.T) {
actual := searchDisks.SortByCreatedTime(false)
if actual[0].ID != 65191 {
t.Fatal("expected ID 65191, found: ", actual[0].ID)
}
actual = searchDisks.SortByCreatedTime(true)
if actual[0].ID != 65193 {
t.Fatal("expected ID 65193, found: ", actual[0].ID)
}
}
var unattachedDisks = ListDisksUnattached{
Data: []ItemDiskUnattached{
{
CKey: "",
Meta: []interface{}{
"cloudbroker",
"disk",
1,
},
AccountID: 149,
AccountName: "test_account1",
ACL: map[string]interface{}{},
BootPartition: 0,
CreatedTime: 1681477547,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
DiskPath: "",
GID: 2002,
GUID: 22636,
ID: 22636,
ImageID: 0,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
IQN: "",
Login: "",
Milestones: 43834,
Name: "test_disk",
Order: 0,
Params: "",
ParentID: 0,
Password: "",
PCISlot: -1,
Pool: "data05",
PresentTo: []uint64{},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,
ReferenceID: "",
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
ResName: "volumes/volume_22636",
Role: "",
SEPID: 1,
Shareable: false,
SizeMax: 0,
SizeUsed: 0,
Snapshots: nil,
Status: "CREATED",
TechStatus: techStatusAllocated,
Type: "D",
VMID: 0,
},
{
CKey: "",
Meta: []interface{}{
"cloudbroker",
"disk",
1,
},
AccountID: 150,
AccountName: "test_account",
ACL: map[string]interface{}{},
BootPartition: 0,
CreatedTime: 1681477558,
DeletedTime: 0,
Description: "",
DestructionTime: 0,
DiskPath: "",
GID: 2002,
GUID: 22637,
ID: 22637,
ImageID: 0,
Images: []uint64{},
IOTune: IOTune{
TotalIOPSSec: 2000,
},
IQN: "",
Login: "",
Milestones: 43834,
Name: "test_disk",
Order: 0,
Params: "",
ParentID: 0,
Password: "",
PCISlot: -1,
Pool: "data05",
PresentTo: []uint64{
27,
27,
},
PurgeAttempts: 0,
PurgeTime: 0,
RealityDeviceNumber: 0,
ReferenceID: "",
ResID: "79bd3bd8-3424-48d3-963f-1870d506f169",
ResName: "volumes/volume_22637",
Role: "",
SEPID: 1,
Shareable: false,
SizeMax: 0,
SizeUsed: 0,
Snapshots: nil,
Status: "CREATED",
TechStatus: techStatusAllocated,
Type: "B",
VMID: 0,
},
},
EntryCount: 2,
}
func TestListDisksUnattached_FilterByID(t *testing.T) {
actual := unattachedDisks.FilterByID(22636)
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
actualItem := actual.FindOne()
if actualItem.ID != 22636 {
t.Fatal("expected ID 22636, found: ", actualItem.ID)
}
}
func TestListDisksUnattached_FilterByName(t *testing.T) {
actual := unattachedDisks.FilterByName("test_disk")
if len(actual.Data) != 2 {
t.Fatal("expected 2 elements, found: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.Name != "test_disk" {
t.Fatal("expected 'test_disk' name, found: ", item.Name)
}
}
}
func TestListDisksUnattached_FilterByStatus(t *testing.T) {
actual := unattachedDisks.FilterByStatus("CREATED")
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual.Data {
if item.Status != "CREATED" {
t.Fatal("expected 'CREATED' status, found: ", item.Status)
}
}
}
func TestListDisksUnattached_FilterByTechStatus(t *testing.T) {
actual := unattachedDisks.FilterByTechStatus(techStatusAllocated)
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
for _, item := range actual.Data {
if item.TechStatus != techStatusAllocated {
t.Fatal("expected 'ALLOCATED' techStatus, found: ", item.TechStatus)
}
}
}
func TestListDisksUnattached_FilterFunc(t *testing.T) {
actual := unattachedDisks.FilterFunc(func(id ItemDiskUnattached) bool {
return len(id.PresentTo) == 2
})
if len(actual.Data) == 0 {
t.Fatal("No elements were found")
}
if len(actual.Data[0].PresentTo) != 2 {
t.Fatal("expected 2 elements in PresentTo, found: ", len(actual.Data[0].PresentTo))
}
}
func TestListDisksUnattached_SortByCreatedTime(t *testing.T) {
actual := unattachedDisks.SortByCreatedTime(false)
if actual.Data[0].ID != 22636 {
t.Fatal("expected ID 22636, found: ", actual.Data[0].ID)
}
actual = unattachedDisks.SortByCreatedTime(true)
if actual.Data[0].ID != 22637 {
t.Fatal("expected ID 22637, found: ", actual.Data[0].ID)
}
}

View File

@@ -0,0 +1,126 @@
package disks
import (
"context"
"net/http"
"strconv"
"strings"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// FromPlatformDiskRequest struct to create template from platform disk
type FromPlatformDiskRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Name of the rescue disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Boot type of image BIOS or UEFI
// Required: true
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
// Image type linux, windows or other
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
// Binary architecture of this image
// Should be:
// - X86_64
// Required: true
Architecture string `url:"architecture" json:"architecture" validate:"imageArchitecture"`
// Username for the image
// Required: false
Username string `url:"username,omitempty" json:"username,omitempty"`
// Password for the image
// Required: false
Password string `url:"password,omitempty" json:"password,omitempty"`
// Account ID to make the image exclusive
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// SEP ID
// Required: false
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Pool for image create
// Required: false
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
Drivers []string `url:"drivers" json:"drivers" validate:"required"`
// Does this machine supports hot resize
// Required: false
HotResize bool `url:"hotresize" json:"hotresize"`
// Bootable image
// Required: true
Bootable bool `url:"bootable" json:"bootable"`
}
type wrapperFromPlatformDiskRequest struct {
FromPlatformDiskRequest
AsyncMode bool `url:"asyncMode"`
}
// FromPlatformDisk creates template from platform disk in sync mode.
// It returns id of created disk and error.
func (d Disks) FromPlatformDisk(ctx context.Context, req FromPlatformDiskRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/fromPlatformDisk"
reqWrapped := wrapperFromPlatformDiskRequest{
FromPlatformDiskRequest: req,
AsyncMode: false,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}
// FromPlatformDiskAsync creates template from platform disk in async mode.
// It returns guid of task and error.
func (d Disks) FromPlatformDiskAsync(ctx context.Context, req FromPlatformDiskRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/fromPlatformDisk"
reqWrapped := wrapperFromPlatformDiskRequest{
FromPlatformDiskRequest: req,
AsyncMode: true,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
if err != nil {
return "", err
}
result := strings.ReplaceAll(string(res), "\"", "")
return result, nil
}

48
pkg/cloudapi/disks/get.go Normal file
View File

@@ -0,0 +1,48 @@
package disks
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// GetRequest struct to get information about disk
type GetRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// Get gets disk details as a RecordDisk struct
// 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) {
res, err := d.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordDisk{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets disk details as an array of bytes
// 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) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/get"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

28
pkg/cloudapi/disks/ids.go Normal file
View File

@@ -0,0 +1,28 @@
package disks
// IDs gets array of DiskIDs from ListDisks struct
func (ld ListDisks) IDs() []uint64 {
res := make([]uint64, 0, len(ld.Data))
for _, d := range ld.Data {
res = append(res, d.ID)
}
return res
}
// IDs gets array of DiskIDs from ListDisksUnattached struct
func (ldu ListDisksUnattached) IDs() []uint64 {
res := make([]uint64, 0, len(ldu.Data))
for _, d := range ldu.Data {
res = append(res, d.ID)
}
return res
}
// IDs gets array of DiskIDs from ListSearchDisks struct
func (lsd ListSearchDisks) IDs() []uint64 {
res := make([]uint64, 0, len(lsd))
for _, d := range lsd {
res = append(res, d.ID)
}
return res
}

View File

@@ -0,0 +1,96 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// LimitIORequest struct for limit IO
type LimitIORequest struct {
// ID of the disk to limit
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Alias for total_iops_sec for backwards compatibility
// Required: false
IOPS uint64 `url:"iops,omitempty" json:"iops,omitempty"`
// TotalBytesSec
// Required: false
TotalBytesSec uint64 `url:"total_bytes_sec,omitempty" json:"total_bytes_sec,omitempty"`
// ReadBytesSec
// Required: false
ReadBytesSec uint64 `url:"read_bytes_sec,omitempty" json:"read_bytes_sec,omitempty"`
// WriteBytesSec
// Required: false
WriteBytesSec uint64 `url:"write_bytes_sec,omitempty" json:"write_bytes_sec,omitempty"`
// TotalIOPSSec
// Required: false
TotalIOPSSec uint64 `url:"total_iops_sec,omitempty" json:"total_iops_sec,omitempty"`
// ReadIOPSSec
// Required: false
ReadIOPSSec uint64 `url:"read_iops_sec,omitempty" json:"read_iops_sec,omitempty"`
// WriteIOPSSec
// Required: false
WriteIOPSSec uint64 `url:"write_iops_sec,omitempty" json:"write_iops_sec,omitempty"`
// TotalBytesSecMax
// Required: false
TotalBytesSecMax uint64 `url:"total_bytes_sec_max,omitempty" json:"total_bytes_sec_max,omitempty"`
// ReadBytesSecMax
// Required: false
ReadBytesSecMax uint64 `url:"read_bytes_sec_max,omitempty" json:"read_bytes_sec_max,omitempty"`
// WriteBytesSecMax
// Required: false
WriteBytesSecMax uint64 `url:"write_bytes_sec_max,omitempty" json:"write_bytes_sec_max,omitempty"`
// TotalIOPSSecMax
// Required: false
TotalIOPSSecMax uint64 `url:"total_iops_sec_max,omitempty" json:"total_iops_sec_max,omitempty"`
// ReadIOPSSecMax
// Required: false
ReadIOPSSecMax uint64 `url:"read_iops_sec_max,omitempty" json:"read_iops_sec_max,omitempty"`
// WriteIOPSSecMax
// Required: false
WriteIOPSSecMax uint64 `url:"write_iops_sec_max,omitempty" json:"write_iops_sec_max,omitempty"`
// SizeIOPSSec
// Required: false
SizeIOPSSec uint64 `url:"size_iops_sec,omitempty" json:"size_iops_sec,omitempty"`
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,95 @@
package disks
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListRequest struct to get list of disks
type ListRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account name
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by max size disk
// Required: false
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Type of the disks
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of the created disks belonging to an account as a ListDisks struct
func (d Disks) List(ctx context.Context, req ListRequest) (*ListDisks, error) {
res, err := d.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of the created disks belonging to an account as an array of bytes
func (d Disks) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/list"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,76 @@
package disks
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListDeletedRequest struct to get list of deleted disks
type ListDeletedRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by account name
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by max size disk
// Required: false
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
// Find by shared, true or false
// Required: false
Shared interface{} `url:"shared,omitempty" json:"shared,omitempty" validate:"omitempty,isBool"`
// ID of the account the disks belong to
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Type of the disks
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListDeleted gets list the deleted disks belonging to an account
func (d Disks) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDisks, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/listDeleted"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,52 @@
package disks
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListTypesRequest struct to get list types of disks
type ListTypesRequest struct {
// Show detailed disk types by seps
// Required: true
Detailed bool `url:"detailed" json:"detailed"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListTypes gets list defined disk types
func (d Disks) ListTypes(ctx context.Context, req ListTypesRequest) (*ListTypes, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/listTypes"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListTypes{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,80 @@
package disks
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ListUnattachedRequest struct to get list of unattached disk
type ListUnattachedRequest struct {
// Find by id
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by account name
// Required: false
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
// Find by max size disk
// Required: false
DiskMaxSize int64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Type of the disks
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// ID of the account
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListUnattached gets list of unattached disks
func (d Disks) ListUnattached(ctx context.Context, req ListUnattachedRequest) (*ListDisksUnattached, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/listUnattached"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListDisksUnattached{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}

View File

@@ -0,0 +1,480 @@
package disks
// Main information about disk
type ItemDisk struct {
// Access Control List
ACL map[string]interface{} `json:"acl"`
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Computes
Computes map[string]string `json:"computes"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Device name
DeviceName string `json:"devicename"`
// Description
Description string `json:"desc"`
// Destruction time
DestructionTime uint64 `json:"destructionTime"`
// Grid ID
GID uint64 `json:"gid"`
// ID
ID uint64 `json:"id"`
// Image ID
ImageID uint64 `json:"imageId"`
// List of image IDs
Images []uint64 `json:"images"`
// IOTune
IOTune IOTune `json:"iotune"`
// Machine ID
MachineID uint64 `json:"machineId"`
// Machine name
MachineName string `json:"machineName"`
// Name
Name string `json:"name"`
// Order
Order uint64 `json:"order"`
// Params
Params string `json:"params"`
// Parent ID
ParentID uint64 `json:"parentId"`
// PCI slot
PCISlot int64 `json:"pciSlot"`
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
// Replication
Replication ItemReplication `json:"replication"`
// Resource ID
ResID string `json:"resId"`
// Resource name
ResName string `json:"resName"`
// Role
Role string `json:"role"`
// SepType
SepType string `json:"sepType"`
// Shareable
Shareable bool `json:"shareable"`
// SepID
SepID uint64 `json:"sepId"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Size used
SizeUsed float64 `json:"sizeUsed"`
// List of 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 ItemDiskUnattached struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Access Control List
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"`
// Images
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"`
//PCISlot
PCISlot int64 `json:"pciSlot"`
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// 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"`
// ID SEP
SEPID uint64 `json:"sepId"`
// Shareable
Shareable bool `json:"shareable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Size used
SizeUsed float64 `json:"sizeUsed"`
// List of 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"`
}
// List of disks searched
type ListSearchDisks []ItemDisk
// List of disks
type ListDisks struct {
// Data
Data []ItemDisk `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// List of unattached disks
type ListDisksUnattached struct {
// Data
Data []ItemDiskUnattached `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about snapshot
type ItemSnapshot struct {
// GUID
GUID string `json:"guid"`
// Label
Label string `json:"label"`
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`
// SnapSetGUID
SnapSetGUID string `json:"snapSetGuid"`
// SnapSetTime
SnapSetTime uint64 `json:"snapSetTime"`
// TimeStamp
TimeStamp uint64 `json:"timestamp"`
}
// List of snapshots
type ListSnapshots []ItemSnapshot
// Main information about IO tune
type IOTune struct {
// 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
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
WriteIOPSSec uint64 `json:"write_iops_sec"`
// WriteIOPSSecMax
WriteIOPSSecMax uint64 `json:"write_iops_sec_max"`
}
// Detailed information about disk
type RecordDisk struct {
// Access Control List
ACL map[string]interface{} `json:"acl"`
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Computes
Computes map[string]string `json:"computes"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Device name
DeviceName string `json:"devicename"`
// Description
Description string `json:"desc"`
// Destruction time
DestructionTime uint64 `json:"destructionTime"`
// Grid ID
GID uint64 `json:"gid"`
// ID
ID uint64 `json:"id"`
// Image ID
ImageID uint64 `json:"imageId"`
// List of image IDs
Images []uint64 `json:"images"`
// IOTune
IOTune IOTune `json:"iotune"`
// Name
Name string `json:"name"`
// Order
Order uint64 `json:"order"`
// Params
Params string `json:"params"`
// Parent ID
ParentID uint64 `json:"parentId"`
// PCI slot
PCISlot int64 `json:"pciSlot"`
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Purge time
PurgeTime uint64 `json:"purgeTime"`
// Replication
Replication ItemReplication `json:"replication"`
// Resource ID
ResID string `json:"resId"`
// Resource name
ResName string `json:"resName"`
// Role
Role string `json:"role"`
// SepType
SepType string `json:"sepType"`
// SepID
SepID uint64 `json:"sepId"`
// Shareable
Shareable bool `json:"shareable"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Size used
SizeUsed float64 `json:"sizeUsed"`
// List of 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 ItemReplication struct {
// DiskID
DiskID uint64 `json:"diskId"`
// PoolID
PoolID string `json:"poolId"`
// Role
Role string `json:"role"`
// SelfVolumeID
SelfVolumeID string `json:"selfVolumeId"`
// StorageID
StorageID string `json:"storageId"`
// VolumeID
VolumeID string `json:"volumeId"`
}
type ListTypes struct {
// Data
Data []interface{} `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}

View File

@@ -0,0 +1,42 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RenameRequest struct to rename disk
type RenameRequest struct {
// ID of the disk to rename
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// New name of disk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
}
// Rename renames disk
func (d Disks) Rename(ctx context.Context, req RenameRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,52 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicateRequest struct to create an empty disk in chosen SEP and pool combination.
type ReplicateRequest struct {
// Id of the disk to replicate. This disk will become master in replication
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Name of replica disk to create
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// ID of SEP to create slave disk
// Required: true
SepID uint64 `url:"sepId" json:"sepId" validate:"required"`
// Pool name to create slave disk in
// Required: true
PoolName string `url:"poolName" json:"poolName" validate:"required"`
}
// Create an empty disk in chosen SEP and pool combination.
// Starts replication between chosen disk and newly created disk
// Note: only TATLIN type SEP are supported for replications between
func (d Disks) Replicate(ctx context.Context, req ReplicateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicate"
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

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationResume struct to resume suspended replication
type ReplicationResumeRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationResume resume suspended replication
func (d Disks) ReplicationResume(ctx context.Context, req ReplicationResumeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationResume"
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

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationReverseRequest struct to change role between disks replications
type ReplicationReverseRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationReverse change role between disks replications
func (d Disks) ReplicationReverse(ctx context.Context, req ReplicationReverseRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationReverse"
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

@@ -0,0 +1,43 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationStartRequest struct to starts replication between two chosen disks
type ReplicationStartRequest struct {
// Id of the disk to replicate. Primary disk in replication
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// ID of target disk. Secondary disk in replication
// Required: true
TargetDiskID uint64 `url:"targetDiskId" json:"targetDiskId" validate:"required"`
}
// ReplicationStart starts replication between two chosen disks. It's required for both disks to have same size to avoid replication conflicts
// Note: Source disk's SEP and target SEP supported only of TATLIN type.
func (d Disks) ReplicationStart(ctx context.Context, req ReplicationStartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStart"
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

@@ -0,0 +1,32 @@
package disks
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationStatusRequest struct to get replication status
type ReplicationStatusRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationStatus get replication status
func (d Disks) ReplicationStatus(ctx context.Context, req ReplicationStatusRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStatus"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationStopRequest struct to remove replication between disks completely
type ReplicationStopRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationStop remove replication between disks completely
func (d Disks) ReplicationStop(ctx context.Context, req ReplicationStopRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationStop"
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

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ReplicationSuspendRequest struct to pause replication with possibility to resume from pause moment
type ReplicationSuspendRequest struct {
// Id of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// ReplicationSuspend pause replication with possibility to resume from pause moment
func (d Disks) ReplicationSuspend(ctx context.Context, req ReplicationSuspendRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/replicationSuspend"
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

@@ -0,0 +1,70 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ResizeRequest struct to resize disk
type ResizeRequest struct {
// ID of the disk to resize
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// New size of the disk in GB
// Required: true
Size uint64 `url:"size" json:"size" validate:"required"`
}
// Resize resizes 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 := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}
// 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 := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/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
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// RestoreRequest struct to restore a deleted unattached disk
type RestoreRequest struct {
// ID of the disk to restore
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// Restore restores a deleted unattached disk from recycle bin
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,48 @@
package disks
import (
"context"
"encoding/json"
"net/http"
)
// SearchRequest struct for search
type SearchRequest struct {
// ID of the account to search for the Disk
// Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Name of the Disk to search for
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// If false, then disks having one of the statuses are not listed
// Required: false
ShowAll bool `url:"show_all,omitempty" json:"show_all,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// Search searches disks
func (d Disks) Search(ctx context.Context, req SearchRequest) (ListSearchDisks, error) {
url := "/cloudapi/disks/search"
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
list := ListSearchDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}

View File

@@ -0,0 +1,99 @@
package disks
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ld ListDisks) Serialize(params ...string) (serialization.Serialized, error) {
if ld.EntryCount == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ld, prefix, indent)
}
return json.Marshal(ld)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ld ListSearchDisks) Serialize(params ...string) (serialization.Serialized, error) {
if len(ld) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ld, prefix, indent)
}
return json.Marshal(ld)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (idisk ItemDisk) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(idisk, prefix, indent)
}
return json.Marshal(idisk)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (lu ListDisksUnattached) Serialize(params ...string) (serialization.Serialized, error) {
if lu.EntryCount == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(lu, prefix, indent)
}
return json.Marshal(lu)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (idisk ItemDiskUnattached) Serialize(params ...string) (serialization.Serialized, error) {
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(idisk, prefix, indent)
}
return json.Marshal(idisk)
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// ShareRequest struct to share disk data
type ShareRequest struct {
// ID of the disk to share
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// Share shares data disk
func (d Disks) Share(ctx context.Context, req ShareRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/share"
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

@@ -0,0 +1,42 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SnapshotDeleteRequest struct to delete snapshot
type SnapshotDeleteRequest struct {
// ID of disk to delete
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Label of the snapshot to delete
// Required: true
Label string `url:"label" json:"label" validate:"required"`
}
// SnapshotDelete deletes a snapshot
func (d Disks) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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

@@ -0,0 +1,47 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// SnapshotRollbackRequest struct to rollback snapshot
type SnapshotRollbackRequest struct {
// ID of the disk
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
// Label of the snapshot to rollback
// Required: false
Label string `url:"label,omitempty" json:"label,omitempty"`
// Timestamp of the snapshot to rollback
// Required: false
TimeStamp uint64 `url:"timestamp,omitempty" json:"timestamp,omitempty"`
}
// SnapshotRollback rollbacks an individual disk snapshot
func (d Disks) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(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
}

View File

@@ -0,0 +1,174 @@
package disks
import "sort"
// SortByCreatedTime sorts ListDisks by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDisks) SortByCreatedTime(inverse bool) ListDisks {
if len(ld.Data) < 2 {
return ld
}
sort.Slice(ld.Data, func(i, j int) bool {
if inverse {
return ld.Data[i].CreatedTime > ld.Data[j].CreatedTime
}
return ld.Data[i].CreatedTime < ld.Data[j].CreatedTime
})
return ld
}
// SortByDestructionTime sorts ListDisks by the DestructionTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDisks) SortByDestructionTime(inverse bool) ListDisks {
if len(ld.Data) < 2 {
return ld
}
sort.Slice(ld.Data, func(i, j int) bool {
if inverse {
return ld.Data[i].DestructionTime > ld.Data[j].DestructionTime
}
return ld.Data[i].DestructionTime < ld.Data[j].DestructionTime
})
return ld
}
// SortByDeletedTime sorts ListDisks by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDisks) SortByDeletedTime(inverse bool) ListDisks {
if len(ld.Data) < 2 {
return ld
}
sort.Slice(ld.Data, func(i, j int) bool {
if inverse {
return ld.Data[i].DeletedTime > ld.Data[j].DeletedTime
}
return ld.Data[i].DeletedTime < ld.Data[j].DeletedTime
})
return ld
}
// SortByCreatedTime sorts ListSearchDisks by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListSearchDisks) SortByCreatedTime(inverse bool) ListSearchDisks {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].CreatedTime > ld[j].CreatedTime
}
return ld[i].CreatedTime < ld[j].CreatedTime
})
return ld
}
// SortByDestructionTime sorts ListSearchDisks by the DestructionTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListSearchDisks) SortByDestructionTime(inverse bool) ListSearchDisks {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].DestructionTime > ld[j].DestructionTime
}
return ld[i].DestructionTime < ld[j].DestructionTime
})
return ld
}
// SortByDeletedTime sorts ListSearchDisks by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListSearchDisks) SortByDeletedTime(inverse bool) ListSearchDisks {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].DeletedTime > ld[j].DeletedTime
}
return ld[i].DeletedTime < ld[j].DeletedTime
})
return ld
}
// SortByCreatedTime sorts ListDisksUnattached by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lu ListDisksUnattached) SortByCreatedTime(inverse bool) ListDisksUnattached {
if len(lu.Data) < 2 {
return lu
}
sort.Slice(lu.Data, func(i, j int) bool {
if inverse {
return lu.Data[i].CreatedTime > lu.Data[j].CreatedTime
}
return lu.Data[i].CreatedTime < lu.Data[j].CreatedTime
})
return lu
}
// SortByDestructionTime sorts ListDisksUnattached by the DestructionTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lu ListDisksUnattached) SortByDestructionTime(inverse bool) ListDisksUnattached {
if len(lu.Data) < 2 {
return lu
}
sort.Slice(lu.Data, func(i, j int) bool {
if inverse {
return lu.Data[i].DestructionTime > lu.Data[j].DestructionTime
}
return lu.Data[i].DestructionTime < lu.Data[j].DestructionTime
})
return lu
}
// SortByDeletedTime sorts ListDisksUnattached by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (lu ListDisksUnattached) SortByDeletedTime(inverse bool) ListDisksUnattached {
if len(lu.Data) < 2 {
return lu
}
sort.Slice(lu.Data, func(i, j int) bool {
if inverse {
return lu.Data[i].DeletedTime > lu.Data[j].DeletedTime
}
return lu.Data[i].DeletedTime < lu.Data[j].DeletedTime
})
return lu
}

View File

@@ -0,0 +1,38 @@
package disks
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
)
// UnshareRequest struct to unshare data disk
type UnshareRequest struct {
// ID of the disk to unshare
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
// Unshare unshares data disk
func (d Disks) Unshare(ctx context.Context, req UnshareRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/unshare"
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
}