v1.11.0
This commit is contained in:
@@ -12,23 +12,23 @@ import (
|
||||
type ChangeIPRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||
|
||||
// Network type
|
||||
// 'EXTNET' for connect to external network directly
|
||||
// 'VINS' for connect to ViNS
|
||||
// Required: true
|
||||
NetType string `url:"netType" json:"netType" validate:"computeNetType"`
|
||||
NetType string `url:"net_type" json:"net_type" validate:"computeNetType"`
|
||||
|
||||
// Network ID for connect to
|
||||
// For EXTNET - external network ID
|
||||
// For VINS - VINS ID
|
||||
// Required: true
|
||||
NetID uint64 `url:"netId" json:"netId" validate:"required"`
|
||||
NetID uint64 `url:"net_id" json:"net_id" validate:"required"`
|
||||
|
||||
// IP address to which we will change the existing one, it must be from the same subnet
|
||||
// Required: true
|
||||
IPAddr string `url:"ipAddr" json:"ipAddr" validate:"required"`
|
||||
IPAddr string `url:"ip_addr" json:"ip_addr" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeIP change reserved IP for compute instance
|
||||
|
||||
46
pkg/cloudbroker/compute/change_mac.go
Normal file
46
pkg/cloudbroker/compute/change_mac.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ChangeMACRequest struct to change MAC for network
|
||||
type ChangeMACRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||
|
||||
// Current mac address
|
||||
// Required: true
|
||||
СurrentMAC string `url:"current_mac_address" json:"current_mac_address" validate:"required"`
|
||||
|
||||
// the MAC address to which we will change the existing one
|
||||
// Required: true
|
||||
NewMAC string `url:"new_mac_address" json:"new_mac_address" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeMAC change MAC for compute instance
|
||||
func (c Compute) ChangeMAC(ctx context.Context, req ChangeMACRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/changeMac"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -168,3 +168,164 @@ func (lc ListComputes) FindOne() ItemCompute {
|
||||
|
||||
return lc.Data[0]
|
||||
}
|
||||
|
||||
// FilterByID returns ListDeletedComputes with specified ID.
|
||||
func (lc ListDeletedComputes) FilterByID(id uint64) ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
return ic.ID == id
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListDeletedComputes with specified Name.
|
||||
func (lc ListDeletedComputes) FilterByName(name string) ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
return ic.Name == name
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListDeletedComputes with specified Status.
|
||||
func (lc ListDeletedComputes) FilterByStatus(status string) ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
return ic.Status == status
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListDeletedComputes with specified TechStatus.
|
||||
func (lc ListDeletedComputes) FilterByTechStatus(techStatus string) ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
return ic.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDiskID return ListDeletedComputes with specified DiskID.
|
||||
func (lc ListDeletedComputes) FilterByDiskID(diskID uint64) ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
for _, disk := range ic.Disks {
|
||||
if disk.ID == diskID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByK8SID returns master and worker nodes (ListDeletedComputes) inside specified K8S cluster.
|
||||
func (lc ListDeletedComputes) FilterByK8SID(ctx context.Context, k8sID uint64, decortClient interfaces.Caller) (*ListDeletedComputes, error) {
|
||||
caller := k8s.New(decortClient)
|
||||
|
||||
req := k8s.GetRequest{
|
||||
K8SID: k8sID,
|
||||
}
|
||||
|
||||
cluster, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
for _, info := range cluster.K8SGroups.Masters.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, worker := range cluster.K8SGroups.Workers {
|
||||
for _, info := range worker.DetailedInfo {
|
||||
if info.ID == ic.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
result := lc.FilterFunc(predicate)
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter master nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListDeletedComputes) FilterByK8SMasters() ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "master" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// K8SMasters is used to filter worker nodes. Best used after FilterByK8SID function.
|
||||
func (lc ListDeletedComputes) FilterByK8SWorkers() ListDeletedComputes {
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
for _, rule := range ic.AntiAffinityRules {
|
||||
if rule.Value == "worker" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return lc.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByLBID is used to filter ListDeletedComputes used by specified Load Balancer.
|
||||
func (lc ListDeletedComputes) FilterByLBID(ctx context.Context, lbID uint64, decortClient interfaces.Caller) (*ListDeletedComputes, error) {
|
||||
caller := lb.New(decortClient)
|
||||
|
||||
req := lb.GetRequest{
|
||||
LBID: lbID,
|
||||
}
|
||||
|
||||
foundLB, err := caller.Get(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
predicate := func(ic ItemDeletedCompute) bool {
|
||||
return ic.ID == foundLB.PrimaryNode.ComputeID || ic.ID == foundLB.SecondaryNode.ComputeID
|
||||
}
|
||||
|
||||
result := lc.FilterFunc(predicate)
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListDeletedComputes based on a user-specified predicate.
|
||||
func (lc ListDeletedComputes) FilterFunc(predicate func(ItemDeletedCompute) bool) ListDeletedComputes {
|
||||
var result ListDeletedComputes
|
||||
|
||||
for _, item := range lc.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemDeletedCompute
|
||||
// If none was found, returns an empty struct.
|
||||
func (lc ListDeletedComputes) FindOne() ItemDeletedCompute {
|
||||
if len(lc.Data) == 0 {
|
||||
return ItemDeletedCompute{}
|
||||
}
|
||||
|
||||
return lc.Data[0]
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ var computes = ListComputes{
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65191,
|
||||
PCISlot: 6,
|
||||
ID: 65191,
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
@@ -67,7 +66,7 @@ var computes = ListComputes{
|
||||
MigrationJob: 0,
|
||||
Milestones: 363500,
|
||||
Name: "test",
|
||||
Pinned: false,
|
||||
PinnedToStack: 1,
|
||||
RAM: 4096,
|
||||
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
|
||||
Registered: true,
|
||||
@@ -92,8 +91,7 @@ var computes = ListComputes{
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65248,
|
||||
PCISlot: 6,
|
||||
ID: 65248,
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
@@ -132,7 +130,7 @@ var computes = ListComputes{
|
||||
MigrationJob: 0,
|
||||
Milestones: 363853,
|
||||
Name: "compute_2",
|
||||
Pinned: false,
|
||||
PinnedToStack: 1,
|
||||
RAM: 4096,
|
||||
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
|
||||
Registered: true,
|
||||
@@ -248,3 +246,244 @@ func TestSortingByCPU(t *testing.T) {
|
||||
t.Fatal("expected 6 CPU cores, found: ", actual.Data[0].CPUs)
|
||||
}
|
||||
}
|
||||
|
||||
var deleteComputes = ListDeletedComputes{
|
||||
Data: []ItemDeletedCompute{
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65191,
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132847,
|
||||
AccountName: "std_2",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "aff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "aff_val",
|
||||
},
|
||||
},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{
|
||||
{
|
||||
GUID: "",
|
||||
Key: "antiaff_key",
|
||||
Mode: "ANY",
|
||||
Policy: "RECOMMENDED",
|
||||
Topology: "compute",
|
||||
Value: "antiaff_val",
|
||||
},
|
||||
},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 4,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1676975175,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48500,
|
||||
ID: 48500,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363500,
|
||||
Name: "test",
|
||||
RAM: 4096,
|
||||
ReferenceID: "c7cb19ac-af4a-4067-852f-c5572949207e",
|
||||
Registered: true,
|
||||
ResName: "compute-48500",
|
||||
RGID: 79724,
|
||||
RGName: "std_broker2",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STOPPED",
|
||||
TotalDiskSize: 2,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677058904,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
Disks: []InfoDisk{
|
||||
{
|
||||
ID: 65248,
|
||||
},
|
||||
},
|
||||
InfoCompute: InfoCompute{
|
||||
ACL: []interface{}{},
|
||||
AccountID: 132848,
|
||||
AccountName: "std_broker",
|
||||
AffinityLabel: "",
|
||||
AffinityRules: []ItemRule{},
|
||||
AffinityWeight: 0,
|
||||
AntiAffinityRules: []ItemRule{},
|
||||
Arch: "X86_64",
|
||||
BootOrder: []string{
|
||||
"hd", "cdrom",
|
||||
},
|
||||
BootDiskSize: 0,
|
||||
CloneReference: 0,
|
||||
Clones: []uint64{},
|
||||
ComputeCIID: 0,
|
||||
CPUs: 6,
|
||||
CreatedBy: "timofey_tkachev_1@decs3o",
|
||||
CreatedTime: 1677579436,
|
||||
CustomFields: map[string]interface{}{},
|
||||
DeletedBy: "",
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Devices: nil,
|
||||
Driver: "KVM_X86",
|
||||
GID: 212,
|
||||
GUID: 48556,
|
||||
ID: 48556,
|
||||
ImageID: 9884,
|
||||
Interfaces: ListInterfaces{},
|
||||
LockStatus: "UNLOCKED",
|
||||
ManagerID: 0,
|
||||
ManagerType: "",
|
||||
MigrationJob: 0,
|
||||
Milestones: 363853,
|
||||
Name: "compute_2",
|
||||
RAM: 4096,
|
||||
ReferenceID: "a542c449-5b1c-4f90-88c5-7bb5f8ae68ff",
|
||||
Registered: true,
|
||||
ResName: "compute-48556",
|
||||
RGID: 79727,
|
||||
RGName: "sdk_negative_fields_test",
|
||||
SnapSets: ListSnapshots{},
|
||||
StatelessSEPID: 0,
|
||||
StatelessSEPType: "",
|
||||
Status: "ENABLED",
|
||||
Tags: map[string]interface{}{},
|
||||
TechStatus: "STARTED",
|
||||
TotalDiskSize: 1,
|
||||
UpdatedBy: "",
|
||||
UpdatedTime: 1677579436,
|
||||
UserManaged: true,
|
||||
VGPUs: []uint64{},
|
||||
VINSConnected: 0,
|
||||
VirtualImageID: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
EntryCount: 2,
|
||||
}
|
||||
|
||||
func TestFilterDeleteByID(t *testing.T) {
|
||||
actual := deleteComputes.FilterByID(48500).FindOne()
|
||||
|
||||
if actual.ID != 48500 {
|
||||
t.Fatal("expected ID 48500, found: ", actual.ID)
|
||||
}
|
||||
|
||||
actualEmpty := deleteComputes.FilterByID(0)
|
||||
|
||||
if len(actualEmpty.Data) != 0 {
|
||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDeleteByName(t *testing.T) {
|
||||
actual := deleteComputes.FilterByName("compute_2").FindOne()
|
||||
|
||||
if actual.Name != "compute_2" {
|
||||
t.Fatal("expected compute with name 'test', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDeleteByStatus(t *testing.T) {
|
||||
actual := deleteComputes.FilterByStatus("ENABLED")
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "ENABLED" {
|
||||
t.Fatal("expected ENABLED status, found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDeleteByTechStatus(t *testing.T) {
|
||||
actual := deleteComputes.FilterByTechStatus("STARTED").FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with STARTED techStatus, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDeleteByDiskID(t *testing.T) {
|
||||
actual := deleteComputes.FilterByDiskID(65248).FindOne()
|
||||
|
||||
if actual.ID != 48556 {
|
||||
t.Fatal("expected 48556 with DiskID 65248, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterDeleteFunc(t *testing.T) {
|
||||
actual := deleteComputes.FilterFunc(func(ic ItemDeletedCompute) bool {
|
||||
return ic.Registered == true
|
||||
})
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 elements found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Registered != true {
|
||||
t.Fatal("expected Registered to be true, actual: ", item.Registered)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteSortingByCreatedTime(t *testing.T) {
|
||||
actual := deleteComputes.SortByCreatedTime(false)
|
||||
|
||||
if actual.Data[0].Name != "test" {
|
||||
t.Fatal("expected 'test', found: ", actual.Data[0].Name)
|
||||
}
|
||||
|
||||
actual = deleteComputes.SortByCreatedTime(true)
|
||||
if actual.Data[0].Name != "compute_2" {
|
||||
t.Fatal("expected 'compute_2', found: ", actual.Data[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteSortingByCPU(t *testing.T) {
|
||||
actual := deleteComputes.SortByCPU(false)
|
||||
|
||||
if actual.Data[0].CPUs != 4 {
|
||||
t.Fatal("expected 4 CPU cores, found: ", actual.Data[0].CPUs)
|
||||
}
|
||||
|
||||
actual = deleteComputes.SortByCPU(true)
|
||||
|
||||
if actual.Data[0].CPUs != 6 {
|
||||
t.Fatal("expected 6 CPU cores, found: ", actual.Data[0].CPUs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ type ListRequest struct {
|
||||
// Required: false
|
||||
CDImageID uint64 `url:"cdImageId,omitempty" json:"cdImageId,omitempty"`
|
||||
|
||||
// Find by stack name
|
||||
// Required: false
|
||||
StackName string `url:"stackName,omitempty" json:"stackName,omitempty"`
|
||||
|
||||
// Find by external network name
|
||||
// Required: false
|
||||
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
||||
|
||||
@@ -60,7 +60,7 @@ type ListDeletedRequest struct {
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted computes
|
||||
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListComputes, error) {
|
||||
func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListDeletedComputes, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
@@ -73,7 +73,7 @@ func (c Compute) ListDeleted(ctx context.Context, req ListDeletedRequest) (*List
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListComputes{}
|
||||
list := ListDeletedComputes{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// MassRepairBootFSRequest struct to repair boot disk filesystem on several computes
|
||||
type MassRepairBootFSRequest struct {
|
||||
// IDs of compute instances which boot file systems will be repaired
|
||||
// Required: true
|
||||
ComputeIDs []uint64 `url:"computeIds" json:"computeIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// MassRepairBootFS repairs boot disk filesystem on several computes
|
||||
func (c Compute) MassRepairBootFS(ctx context.Context, req MassRepairBootFSRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/massRepairBootFs"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -425,13 +425,13 @@ type ItemDisk struct {
|
||||
Password string `json:"passwd"`
|
||||
|
||||
// PCI slot
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
PCISlot int64 `json:"pci_slot"`
|
||||
|
||||
// Pool
|
||||
Pool string `json:"pool"`
|
||||
|
||||
// Present to
|
||||
PresentTo []uint64 `json:"presentTo"`
|
||||
PresentTo map[string]uint64 `json:"presentTo"`
|
||||
|
||||
// Purge attempts
|
||||
PurgeAttempts uint64 `json:"purgeAttempts"`
|
||||
@@ -469,6 +469,9 @@ type ItemDisk struct {
|
||||
// Size used
|
||||
SizeUsed float64 `json:"sizeUsed"`
|
||||
|
||||
// Size available
|
||||
SizeAvailable uint64 `json:"sizeAvailable"`
|
||||
|
||||
// List detailed snapshots
|
||||
Snapshots ListDetailedSnapshots `json:"snapshots"`
|
||||
|
||||
@@ -482,7 +485,7 @@ type ItemDisk struct {
|
||||
Type string `json:"type"`
|
||||
|
||||
// Updated by
|
||||
UpdatedBy uint64 `json:"updatedBy,omitempty"`
|
||||
UpdatedBy uint64 `json:"updatedBy"`
|
||||
|
||||
// Virtual machine ID
|
||||
VMID uint64 `json:"vmid"`
|
||||
@@ -633,6 +636,9 @@ type InfoCompute struct {
|
||||
// Boot order
|
||||
BootOrder []string `json:"bootOrder"`
|
||||
|
||||
// Boot type
|
||||
BootType string `json:"bootType"`
|
||||
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
@@ -690,6 +696,9 @@ type InfoCompute struct {
|
||||
// HPBacked
|
||||
HPBacked bool `json:"hpBacked"`
|
||||
|
||||
// Hot resize
|
||||
HotResize bool `json:"hotResize"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
@@ -699,6 +708,9 @@ type InfoCompute struct {
|
||||
// List interfaces
|
||||
Interfaces ListInterfaces `json:"interfaces"`
|
||||
|
||||
// Loader type
|
||||
LoaderType string `json:"loaderType"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
@@ -720,6 +732,9 @@ type InfoCompute struct {
|
||||
// Need reboot
|
||||
NeedReboot bool `json:"needReboot"`
|
||||
|
||||
// network interface naming
|
||||
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
|
||||
|
||||
// Numa Affinity
|
||||
NumaAffinity string `json:"numaAffinity"`
|
||||
|
||||
@@ -729,8 +744,8 @@ type InfoCompute struct {
|
||||
// List OS users
|
||||
OSUsers ListOSUsers `json:"osUsers"`
|
||||
|
||||
// Pinned
|
||||
Pinned bool `json:"pinned"`
|
||||
// Pinned to stack
|
||||
PinnedToStack int64 `json:"pinnedToStack"`
|
||||
|
||||
// PreferredCPU
|
||||
PreferredCPU []int64 `json:"preferredCpu"`
|
||||
@@ -861,6 +876,9 @@ type RecordCompute struct {
|
||||
// Boot order
|
||||
BootOrder []string `json:"bootOrder"`
|
||||
|
||||
// Boot type
|
||||
BootType string `json:"bootType"`
|
||||
|
||||
// Boot disk size
|
||||
BootDiskSize uint64 `json:"bootdiskSize"`
|
||||
|
||||
@@ -921,6 +939,9 @@ type RecordCompute struct {
|
||||
// HPBacked
|
||||
HPBacked bool `json:"hpBacked"`
|
||||
|
||||
// Hot resize
|
||||
HotResize bool `json:"hotResize"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
@@ -933,6 +954,9 @@ type RecordCompute struct {
|
||||
// List interfaces
|
||||
Interfaces ListInterfaces `json:"interfaces"`
|
||||
|
||||
// Loader type
|
||||
LoaderType string `json:"loaderType"`
|
||||
|
||||
// Lock status
|
||||
LockStatus string `json:"lockStatus"`
|
||||
|
||||
@@ -972,6 +996,9 @@ type RecordCompute struct {
|
||||
// Need reboot
|
||||
NeedReboot bool `json:"needReboot"`
|
||||
|
||||
// network interface naming
|
||||
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
|
||||
|
||||
// NumaAffinity
|
||||
NumaAffinity string `json:"numaAffinity"`
|
||||
|
||||
@@ -981,8 +1008,8 @@ type RecordCompute struct {
|
||||
// List OS users
|
||||
OSUsers ListOSUsers `json:"osUsers"`
|
||||
|
||||
// Pinned
|
||||
Pinned bool `json:"pinned"`
|
||||
// Pinned to stack
|
||||
PinnedToStack int64 `json:"pinnedToStack"`
|
||||
|
||||
// PreferredCPU
|
||||
PreferredCPU []int64 `json:"preferredCpu"`
|
||||
@@ -1071,6 +1098,24 @@ type ItemCompute struct {
|
||||
// Main information about compute
|
||||
InfoCompute
|
||||
|
||||
// NID
|
||||
NID uint64 `json:"nid"`
|
||||
|
||||
// Total disk size
|
||||
TotalDiskSize uint64 `json:"totalDisksSize"`
|
||||
|
||||
// VINS connected
|
||||
VINSConnected uint64 `json:"vinsConnected"`
|
||||
}
|
||||
|
||||
// Main information about compute for list
|
||||
type ItemDeletedCompute struct {
|
||||
// List of disk IDs
|
||||
Disks ListInfoDisks `json:"disks"`
|
||||
|
||||
// Main information about compute
|
||||
InfoCompute
|
||||
|
||||
// Total disk size
|
||||
TotalDiskSize uint64 `json:"totalDisksSize"`
|
||||
|
||||
@@ -1080,14 +1125,8 @@ type ItemCompute struct {
|
||||
|
||||
// Information Disk
|
||||
type InfoDisk struct {
|
||||
// Bus number
|
||||
BusNumber uint64 `json:"bus_number"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// PCISlot
|
||||
PCISlot int64 `json:"pciSlot"`
|
||||
}
|
||||
|
||||
// List computes
|
||||
@@ -1099,6 +1138,15 @@ type ListComputes struct {
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// List computes
|
||||
type ListDeletedComputes struct {
|
||||
// Data
|
||||
Data []ItemDeletedCompute `json:"data"`
|
||||
|
||||
// EntryCount
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Short information about audit
|
||||
type ItemAudit struct {
|
||||
// Epoch
|
||||
|
||||
@@ -32,6 +32,10 @@ type NetAttachRequest struct {
|
||||
// Required: true
|
||||
IPAddr string `url:"ipAddr,omitempty" json:"ipAddr,omitempty"`
|
||||
|
||||
// MAC address
|
||||
// Required: false
|
||||
MACAddr string `url:"mac_addr,omitempty" json:"mac_addr,omitempty"`
|
||||
|
||||
// Used only for DPDK type, must be 1-9216
|
||||
// Required: false
|
||||
MTU uint64 `url:"mtu,omitempty" json:"mtu,omitempty" validate:"omitempty,mtu"`
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// RegistrationRequest struct to set compute registered in RT
|
||||
type RegistrationRequest struct {
|
||||
// ID of the Compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Unique compute registration key
|
||||
// Required: true
|
||||
RegistrationKey string `url:"registrationKey" json:"registrationKey" validate:"required"`
|
||||
}
|
||||
|
||||
// Registration sets compute registered in RT
|
||||
func (c Compute) Registration(ctx context.Context, req RegistrationRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/registration"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// RepairBootFSRequest struct to repair filesystem
|
||||
type RepairBootFSRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
}
|
||||
|
||||
// RepairBootFS repairs compute boot disk filesystem
|
||||
func (c Compute) RepairBootFS(ctx context.Context, req RepairBootFSRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/repairBootFs"
|
||||
|
||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -96,3 +96,98 @@ func (lc ListComputes) SortByDeletedTime(inverse bool) ListComputes {
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByCPU sorts ListDeletedComputes by the CPU core amount in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListDeletedComputes) SortByCPU(inverse bool) ListDeletedComputes {
|
||||
if len(lc.Data) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc.Data[i].CPUs > lc.Data[j].CPUs
|
||||
}
|
||||
|
||||
return lc.Data[i].CPUs < lc.Data[j].CPUs
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByRAM sorts ListDeletedComputes by the RAM amount in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListDeletedComputes) SortByRAM(inverse bool) ListDeletedComputes {
|
||||
if len(lc.Data) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc.Data[i].RAM > lc.Data[j].RAM
|
||||
}
|
||||
|
||||
return lc.Data[i].RAM < lc.Data[j].RAM
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByCreatedTime sorts ListDeletedComputes by the CreatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListDeletedComputes) SortByCreatedTime(inverse bool) ListDeletedComputes {
|
||||
if len(lc.Data) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc.Data[i].CreatedTime > lc.Data[j].CreatedTime
|
||||
}
|
||||
|
||||
return lc.Data[i].CreatedTime < lc.Data[j].CreatedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByUpdatedTime sorts ListDeletedComputes by the UpdatedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListDeletedComputes) SortByUpdatedTime(inverse bool) ListDeletedComputes {
|
||||
if len(lc.Data) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc.Data[i].UpdatedTime > lc.Data[j].UpdatedTime
|
||||
}
|
||||
|
||||
return lc.Data[i].UpdatedTime < lc.Data[j].UpdatedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
// SortByDeletedTime sorts ListDeletedComputes by the DeletedTime field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lc ListDeletedComputes) SortByDeletedTime(inverse bool) ListDeletedComputes {
|
||||
if len(lc.Data) < 2 {
|
||||
return lc
|
||||
}
|
||||
|
||||
sort.Slice(lc.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lc.Data[i].DeletedTime > lc.Data[j].DeletedTime
|
||||
}
|
||||
|
||||
return lc.Data[i].DeletedTime < lc.Data[j].DeletedTime
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
@@ -17,11 +17,6 @@ type StopRequest struct {
|
||||
// Force stop compute
|
||||
// Required: false
|
||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||
|
||||
// whether to depresent compute disks from node or not
|
||||
// Default: true
|
||||
// Required: false
|
||||
Depresent bool `url:"depresent" json:"depresent"`
|
||||
}
|
||||
|
||||
// Stop stops compute
|
||||
|
||||
@@ -52,6 +52,22 @@ type UpdateRequest struct {
|
||||
// Recommended isolated CPUs. Field is ignored if compute.cpupin=False or compute.pinned=False
|
||||
// Required: false
|
||||
PreferredCPU []int64 `url:"preferredCpu,omitempty" json:"preferredCpu,omitempty" validate:"omitempty,preferredCPU"`
|
||||
|
||||
// VM type linux, windows or unknown
|
||||
// Required: false
|
||||
LoaderType string `url:"loaderType,omitempty" json:"loaderType,omitempty" validate:"omitempty,loaderType"`
|
||||
|
||||
// Boot type of image bios or uefi
|
||||
// Required: false
|
||||
BootType string `url:"bootType,omitempty" json:"bootType,omitempty" validate:"omitempty,imageBootType"`
|
||||
|
||||
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming.
|
||||
// Required: false
|
||||
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Required: false
|
||||
HotResize bool `url:"hotResize,omitempty" json:"hotResize,omitempty"`
|
||||
}
|
||||
|
||||
// Update updates some properties of the compute
|
||||
|
||||
Reference in New Issue
Block a user