From 7ddd8c5fbe801a2ad06e573b80750e467a0b9e2d Mon Sep 17 00:00:00 2001 From: stSolo Date: Mon, 23 Jan 2023 15:39:41 +0300 Subject: [PATCH] 1.1.0 --- CHANGELOG.md | 48 ++++- README.md | 6 +- pkg/cloudapi/account/create.go | 21 -- pkg/cloudapi/account/models.go | 191 +++++++++++------- pkg/cloudapi/account/update.go | 21 -- pkg/cloudapi/bservice/group_add.go | 8 + pkg/cloudapi/bservice/models.go | 3 + pkg/cloudapi/compute/models.go | 41 ++-- pkg/cloudapi/computeci/models.go | 2 +- pkg/cloudapi/disks/models.go | 30 ++- pkg/cloudapi/disks/share.go | 45 +++++ pkg/cloudapi/disks/unshare.go | 45 +++++ pkg/cloudapi/flipgroup/models.go | 3 + pkg/cloudapi/image/models.go | 3 + pkg/cloudapi/k8s/create.go | 16 ++ pkg/cloudapi/k8s/get_node_labels.go | 46 +++++ pkg/cloudapi/k8s/workers_group_add.go | 8 + pkg/cloudapi/lb/start.go | 45 +++++ pkg/cloudapi/lb/stop.go | 45 +++++ pkg/cloudapi/rg/create.go | 21 -- pkg/cloudapi/rg/models.go | 139 ++++++++++++- pkg/cloudapi/rg/update.go | 21 -- pkg/cloudbroker/account/create.go | 21 -- pkg/cloudbroker/account/models.go | 36 ++++ pkg/cloudbroker/account/update.go | 21 -- .../account/update_resource_types.go | 65 ++++++ pkg/cloudbroker/compute/list_gpu.go | 2 +- pkg/cloudbroker/compute/models.go | 23 ++- pkg/cloudbroker/disks/models.go | 26 +-- pkg/cloudbroker/extnet/device_migrate.go | 6 + pkg/cloudbroker/extnet/models.go | 3 + pkg/cloudbroker/grid/models.go | 15 ++ pkg/cloudbroker/image/models.go | 3 + pkg/cloudbroker/kvmppc/mass_create.go | 4 +- pkg/cloudbroker/kvmx86/mass_create.go | 2 +- pkg/cloudbroker/rg/create.go | 21 -- pkg/cloudbroker/rg/models.go | 27 ++- pkg/cloudbroker/rg/update.go | 22 +- pkg/cloudbroker/rg/update_resource_types.go | 65 ++++++ 39 files changed, 869 insertions(+), 301 deletions(-) create mode 100644 pkg/cloudapi/disks/share.go create mode 100644 pkg/cloudapi/disks/unshare.go create mode 100644 pkg/cloudapi/k8s/get_node_labels.go create mode 100644 pkg/cloudapi/lb/start.go create mode 100644 pkg/cloudapi/lb/stop.go create mode 100644 pkg/cloudbroker/account/update_resource_types.go create mode 100644 pkg/cloudbroker/rg/update_resource_types.go diff --git a/CHANGELOG.md b/CHANGELOG.md index e04139e..4dbad53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,46 @@ -## Version 1.0.2 +## Version 1.1.0 -### Bug fixes +### Features -- Update tags for Kubernetes create -- Add License file +#### CloudAPI + +- Account + - Delete "ResTypes" field in Create/Update request structs + - Add fields "DiskSizeMax", "Shareable", "SEPs" in Get/List response structs +- BService + - Add fields "SEPID", "SEPPool" in GroupAdd request structs + - Add field "PoolName" in List/ListDeleted response structs +- Compute + - Add fields "PresentTo", "Shareable" in Get/List/ListDeleted response structs +- Disks + - Add fields "PresentTo", "Shareable", "Computes" in Get/List/ListDeleted/ListUnattached/Search response structs + - Delete fields "ComputeID", "ComputeName" in List/ListDeleted/ListUnattached/Search response structs +- FLIPgroup + - Add field "ClientNames" in Get response struct +- Image + - Add field "PresentTo" in Get response struct +- RG + - Delete "ResTypes" field in Create/Update request structs + - Add fields "DiskSizeMax", "Shareable", "SEPs" in Get/List response structs + +#### Cloudbroker + +- Account + - Add fields "SEPs", "ResourceTypes", "PresentTo", "DiskSizeMax", "UniqPools", "Shareable" in Get/List/ListDeleted/ListDisks/ListRG response structs +- Compute + - Add fields "VINSConnected", "TotalDiskSize", "Shareable", "PresentTo" in Get/List/ListDeleted response structs +- Disks + - Add fields "ReferenceID", "Shareable", "PresentTo", "Computes" in List/ListDeleted/ListUnattached/Search response structs + - Delete fields "ComputeID", "ComputeName" in List/ListDeleted/ListUnattached/Search response structs +- Grid + - Add fields "SEPs", "DiskSizeMax" in Get/List response structs +- Image + - Add field "PresentTo" in Get response struct +- KVMX86 + - Add field "Userdata" in MassCreate request struct + - Delete field "IPAddr" in MassCreate request struct +- KVMPPC + - Add field "Userdata" in MassCreate request struct + - Delete field "IPAddr" in MassCreate request struct +- RG + - Add fields "DiskSizeMax", "Shareable", "SEPs" in Get/List response structs diff --git a/README.md b/README.md index d0b74f2..b262a54 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Decort SDK - это библиотека, написанная на языке GO, позволяющая взаимодействовать с API облачной платформы **DECORT**. Библиотека содеражит в себе структуры и методы, необходимые для отправки запросов. Decort SDK имеет встроенный http-клиент и поддерживает разные способы авторизации на платформе. Библиотека так же содержит в себе модели ответов от платформы. +## Версии + - Версия 1.0.0 Decort-SDK соответствует 3.8.4 версии платформы + - Версия 1.1.0 Decort-SDK соответствует 3.8.5 версии платформы + ## Оглавление - [Установка](#установка) @@ -417,7 +421,7 @@ func main() { } //Выполнение запроса с помощью конвейера - res, err := client.СloudAPI().KVMX86().Create(context.Background(), req) + res, err := client.CloudAPI().KVMX86().Create(context.Background(), req) if err != nil { log.Fatal(err) } diff --git a/pkg/cloudapi/account/create.go b/pkg/cloudapi/account/create.go index ba0f5f3..10961d5 100644 --- a/pkg/cloudapi/account/create.go +++ b/pkg/cloudapi/account/create.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for creating account @@ -50,17 +48,6 @@ type CreateRequest struct { // Limit (positive) or disable (0) GPU resources // Required: false GPUUnits uint64 `url:"gpu_units,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (arq CreateRequest) validate() error { @@ -70,14 +57,6 @@ func (arq CreateRequest) validate() error { if arq.Username == "" { return errors.New("validation-error: field Username can not be empty") } - if len(arq.ResTypes) > 0 { - for _, value := range arq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudapi/account/models.go b/pkg/cloudapi/account/models.go index cc86520..46b0e65 100644 --- a/pkg/cloudapi/account/models.go +++ b/pkg/cloudapi/account/models.go @@ -45,75 +45,6 @@ type ResourceLimits struct { GPUUnits float64 `json:"gpu_units"` } -// Main information of account -type InfoAccount struct { - // Segment - DCLocation string `json:"DCLocation"` - - // Key - CKey string `jspn:"_ckey"` - - // Meta - Meta []interface{} `json:"_meta"` - - // Access Control List - ACL []RecordACL `json:"acl"` - - // Company - Company string `json:"company"` - - // Company URL - CompanyURL string `json:"companyurl"` - - // Created by - CreatedBy string `jspn:"createdBy"` - - // Created time - CreatedTime uint64 `json:"createdTime"` - - // Deactiovation time - DeactiovationTime float64 `json:"deactivationTime"` - - // Deleted by - DeletedBy string `json:"deletedBy"` - - // Deleted time - DeletedTime uint64 `json:"deletedTime"` - - // Display name - DisplayName string `json:"displayname"` - - // GUID - GUID uint64 `json:"guid"` - - // ID - ID uint64 `json:"id"` - - // Name - Name string `json:"name"` - - // Resource Limits - ResourceLimits ResourceLimits `json:"resourceLimits"` - - // If true send emails when a user is granted access to resources - SendAccessEmails bool `json:"sendAccessEmails"` - - // Service Account - ServiceAccount bool `json:"serviceAccount"` - - // Status - Status string `json:"status"` - - // Updated time - UpdatedTime uint64 `json:"updatedTime"` - - // Version - Version uint64 `json:"version"` - - // List VINS in account - VINS []uint64 `json:"vins"` -} - // Main information in one of if the list of accounts type ItemAccount struct { // Access Control List @@ -149,6 +80,9 @@ type Resource struct { // Disk size DiskSize int64 `json:"disksize"` + // Max disk size + DiskSizeMax int64 `json:"disksizemax"` + // Number of External IPs ExtIPs int64 `json:"extips"` @@ -160,6 +94,18 @@ type Resource struct { // Number of RAM RAM int64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` +} + +// Disk usage +type DiskUsage struct { + // Disk size + DiskSize float64 `json:"disksize"` + + // Disk size max + DiskSizeMax float64 `json:"disksizemax"` } // Information about resources @@ -189,21 +135,84 @@ type Machines struct { Halted uint64 `json:"halted"` } -// Сomplete information about account +// Main information about account type RecordAccount struct { - // Main information about account - InfoAccount + // DCLocation + DCLocation string `json:"DCLocation"` // Resources Resources Resources `json:"Resources"` + // CKey + CKey string `json:"_ckey"` + + // Access control list + ACL []RecordACL `json:"acl"` + + // Company + Company string `json:"company"` + + // Company URL + CompanyURL string `json:"companyurl"` + // Computes Computes Computes `json:"computes"` + // Created by + CreatedBy string `json:"createdBy"` + + // Created time + CreatedTime uint64 `json:"createdTime"` + + // Deactivation time + DeactivationTime uint64 `json:"deactivationTime"` + + // Deleted by + DeletedBy string `json:"deletedBy"` + + // Deleted time + DeletedTime uint64 `json:"deletedTime"` + + // Display name + DisplayName string `json:"displayname"` + + // GUID + GUID uint64 `json:"guid"` + + // ID + ID uint64 `json:"id"` + // Machines Machines Machines `json:"machines"` - // Number of VINSes + // Name + Name string `json:"name"` + + // Resource limits + ResourceLimits ResourceLimits `json:"resourceLimits"` + + // Resource types + ResourceTypes []string `json:"resourceTypes"` + + // Send access emails + SendAccessEmails bool `json:"sendAccessEmails"` + + // Status + Status string `json:"status"` + + // UniqPools + UniqPools []interface{} `json:"uniqPools"` + + // Updated time + UpdatedTime uint64 `json:"updatedTime"` + + // Version + Version uint64 `json:"version"` + + // VINS + VINS []uint64 `json:"vins"` + + // VINSes VINSes uint64 `json:"vinses"` } @@ -287,6 +296,9 @@ type ItemDisk struct { // ID SEP SEPID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Max size SizeMax uint64 `json:"sizeMax"` @@ -378,10 +390,10 @@ type ListAudits []ItemAudit // Information compute in resource group type RGComputes struct { // Number of started computes - Started uint64 `json:"started"` + Started uint64 `json:"Started"` // Number of stopped computes - Stopped uint64 `json:"stopped"` + Stopped uint64 `json:"Stopped"` } // Resources of Resource group @@ -390,12 +402,39 @@ type RGResources struct { Consumed Resource `json:"Consumed"` // Limits - Limits Resource `json:"Limits"` + Limits LimitsRG `json:"Limits"` // Reserved Reserved Resource `json:"Reserved"` } +// Resources used +type LimitsRG struct { + // Number of cores + CPU int64 `json:"cpu"` + + // Disk size + DiskSize int64 `json:"disksize"` + + // Max disk size + DiskSizeMax int64 `json:"disksizemax"` + + // Number of External IPs + ExtIPs int64 `json:"extips"` + + // External traffic + ExtTraffic int64 `json:"exttraffic"` + + // Number of grafic cores + GPU int64 `json:"gpu"` + + // Number of RAM + RAM int64 `json:"ram"` + + // SEPs + SEPs uint64 `json:"seps"` +} + // Main information about resource group type ItemRG struct { // Computes diff --git a/pkg/cloudapi/account/update.go b/pkg/cloudapi/account/update.go index 0298850..ea45d02 100644 --- a/pkg/cloudapi/account/update.go +++ b/pkg/cloudapi/account/update.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for updaate account @@ -46,31 +44,12 @@ type UpdateRequest struct { // Limit (positive) or disable (0) GPU resources // Required: false GPUUnits uint64 `url:"gpu_units,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (arq UpdateRequest) validate() error { if arq.AccountID == 0 { return errors.New("validation-error: field AccountID can not be empty or equal to 0") } - if len(arq.ResTypes) > 0 { - for _, value := range arq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudapi/bservice/group_add.go b/pkg/cloudapi/bservice/group_add.go index 069df64..cd03f2f 100644 --- a/pkg/cloudapi/bservice/group_add.go +++ b/pkg/cloudapi/bservice/group_add.go @@ -44,6 +44,14 @@ type GroupAddRequest struct { // Required: true Driver string `url:"driver"` + // Storage endpoint provider ID + // Required: false + SEPID uint64 `url:"sepId,omitempty"` + + // Pool to use if sepId is set, can be also empty if needed to be chosen by system + // Required: false + SEPPool string `url:"sepPool,omitempty"` + // Group role tag. Can be empty string, does not have to be unique // Required: false Role string `url:"role,omitempty"` diff --git a/pkg/cloudapi/bservice/models.go b/pkg/cloudapi/bservice/models.go index 1c1d2a5..9741020 100644 --- a/pkg/cloudapi/bservice/models.go +++ b/pkg/cloudapi/bservice/models.go @@ -191,6 +191,9 @@ type RecordGroup struct { // List of Parent IDs Parents []uint64 `json:"parents"` + // Pool name + PoolName string `json:"poolName"` + // Number of RAM, MB RAM uint64 `json:"ram"` diff --git a/pkg/cloudapi/compute/models.go b/pkg/cloudapi/compute/models.go index fc62765..e1f5407 100644 --- a/pkg/cloudapi/compute/models.go +++ b/pkg/cloudapi/compute/models.go @@ -3,13 +3,13 @@ package compute // Access Control List type RecordACL struct { // Account ACL list - AccountACL ListACL `json:"accountACL"` + AccountACL ListACL `json:"accountAcl"` // Compute ACL list - ComputeACL ListACL `json:"computeACL"` + ComputeACL ListACL `json:"computeAcl"` // Resource group ACL list - RGACL ListACL `json:"rgACL"` + RGACL ListACL `json:"rgAcl"` } // ACL information @@ -281,7 +281,7 @@ type RecordCompute struct { // Created time CreatedTime uint64 `json:"createdTime"` - // Custom fields + // Custom fields items CustomFields map[string]interface{} `json:"customFields"` // Deleted by @@ -597,6 +597,9 @@ type ItemComputeDisk struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Purge time PurgeTime uint64 `json:"purgeTime"` @@ -612,6 +615,9 @@ type ItemComputeDisk struct { // SepID SepID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Size max SizeMax uint64 `json:"sizeMax"` @@ -703,7 +709,7 @@ type IOTune struct { // Main information about compute type ItemCompute struct { // Access Control List - ACL []interface{} `json:"ACL"` + ACL []interface{} `json:"acl"` // Account ID AccountID uint64 `json:"accountId"` @@ -750,7 +756,7 @@ type ItemCompute struct { // Created time CreatedTime uint64 `json:"createdTime"` - // Custom fields + // Custom fields list CustomFields map[string]interface{} `json:"customFields"` // Deleted by @@ -765,8 +771,8 @@ type ItemCompute struct { // Devices Devices interface{} `json:"devices"` - // List disk IDs - Disks []uint64 `json:"disks"` + // List disk items + Disks []InfoDisk `json:"disks"` // Driver Driver string `json:"driver"` @@ -783,9 +789,6 @@ type ItemCompute struct { // Image ID ImageID uint64 `json:"imageId"` - // Image name - ImageName string `json:"imageName"` - // List interfaces Interfaces ListInterfaces `json:"interfaces"` @@ -858,17 +861,23 @@ type ItemCompute struct { // User Managed or not UserManaged bool `json:"userManaged"` - // Userdata - Userdata interface{} `json:"userdata"` - // List vGPU IDs VGPUs []uint64 `json:"vgpus"` + // VINS connected + VINSConnected uint64 `json:"vinsConnected"` + // Virtual image ID VirtualImageID uint64 `json:"virtualImageId"` +} - // Virtual image name - VirtualImageName string `json:"virtualImageName"` +// Information Disk +type InfoDisk struct { + // ID + ID uint64 `json:"id"` + + // PCISlot + PCISlot uint64 `json:"pciSlot"` } // List information about computes diff --git a/pkg/cloudapi/computeci/models.go b/pkg/cloudapi/computeci/models.go index c96f917..802e803 100644 --- a/pkg/cloudapi/computeci/models.go +++ b/pkg/cloudapi/computeci/models.go @@ -24,7 +24,7 @@ type ItemComputeCI struct { Status string `json:"status"` // Template - Template string `jsnn:"template"` + Template string `json:"template"` } // List of computeci instances diff --git a/pkg/cloudapi/disks/models.go b/pkg/cloudapi/disks/models.go index 318d054..06dab86 100644 --- a/pkg/cloudapi/disks/models.go +++ b/pkg/cloudapi/disks/models.go @@ -11,18 +11,12 @@ type ItemDisk struct { // Account name AccountName string `json:"accountName"` - // Boot partition - BootPartition uint64 `json:"bootPartition"` + // Computes + Computes map[string]string `json:"computes"` // Created time CreatedTime uint64 `json:"createdTime"` - // Compute ID - ComputeID uint64 `json:"computeId"` - - // Compute name - ComputeName string `json:"computeName"` - // Deleted time DeletedTime uint64 `json:"deletedTime"` @@ -69,11 +63,14 @@ type ItemDisk struct { ParentID uint64 `json:"parentId"` // PCI slot - PCISlot uint64 `json:"pciSlot"` + PCISlot int64 `json:"pciSlot"` // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Purge time PurgeTime uint64 `json:"purgeTime"` @@ -89,12 +86,18 @@ type ItemDisk struct { // SepType SepType string `json:"sepType"` + // Shareable + Shareable bool `json:"shareable"` + // SepID SepID uint64 `json:"sepId"` // Size max SizeMax uint64 `json:"sizeMax"` + // Size used + SizeUsed uint64 `json:"sizeUsed"` + // List of snapshots Snapshots ListSnapshots `json:"snapshots"` @@ -191,6 +194,9 @@ type RecordDisk struct { // Account name AccountName string `json:"accountName"` + // Computes + Computes map[string]string `json:"computes"` + // Created time CreatedTime uint64 `json:"createdTime"` @@ -239,6 +245,9 @@ type RecordDisk struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Purge time PurgeTime uint64 `json:"purgeTime"` @@ -257,6 +266,9 @@ type RecordDisk struct { // SepID SepID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Size max SizeMax uint64 `json:"sizeMax"` diff --git a/pkg/cloudapi/disks/share.go b/pkg/cloudapi/disks/share.go new file mode 100644 index 0000000..35fa0ee --- /dev/null +++ b/pkg/cloudapi/disks/share.go @@ -0,0 +1,45 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +// Request struct for share data disk +type ShareRequest struct { + // ID of the disk to share + // Required: true + DiskID uint64 `url:"diskId"` +} + +func (drq ShareRequest) validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +// Share shares data disk +func (d Disks) Share(ctx context.Context, req ShareRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, 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 +} diff --git a/pkg/cloudapi/disks/unshare.go b/pkg/cloudapi/disks/unshare.go new file mode 100644 index 0000000..5eb4a36 --- /dev/null +++ b/pkg/cloudapi/disks/unshare.go @@ -0,0 +1,45 @@ +package disks + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +// Request struct for unshare data disk +type UnshareRequest struct { + // ID of the disk to unshare + // Required: true + DiskID uint64 `url:"diskId"` +} + +func (drq UnshareRequest) validate() error { + if drq.DiskID == 0 { + return errors.New("validation-error: field DiskID can not be empty or equal to 0") + } + + return nil +} + +// Unshare unshares data disk +func (d Disks) Unshare(ctx context.Context, req UnshareRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, 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 +} diff --git a/pkg/cloudapi/flipgroup/models.go b/pkg/cloudapi/flipgroup/models.go index f2c76bf..5c8f090 100644 --- a/pkg/cloudapi/flipgroup/models.go +++ b/pkg/cloudapi/flipgroup/models.go @@ -29,6 +29,9 @@ type ItemFLIPGroup struct { // List of client IDs ClientIDs []uint64 `json:"clientIds"` + // Client names list + ClientNames []string `json:"clientNames"` + // Client type ClientType string `json:"clientType"` diff --git a/pkg/cloudapi/image/models.go b/pkg/cloudapi/image/models.go index 6f9d780..eac72f4 100644 --- a/pkg/cloudapi/image/models.go +++ b/pkg/cloudapi/image/models.go @@ -143,6 +143,9 @@ type RecordImage struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // ProviderName ProviderName string `json:"provider_name"` diff --git a/pkg/cloudapi/k8s/create.go b/pkg/cloudapi/k8s/create.go index 2b26e00..0843b3d 100644 --- a/pkg/cloudapi/k8s/create.go +++ b/pkg/cloudapi/k8s/create.go @@ -25,6 +25,22 @@ type CreateRequest struct { // Required: true WorkerGroupName string `url:"workerGroupName"` + // ID of SEP to create boot disks for master nodes. Uses images SEP ID if not set + // Required: false + MasterSEPID uint64 `url:"masterSepId,omitempty"` + + // Pool to use if master SEP ID is set, can be also empty if needed to be chosen by system + // Required: false + MasterSEPPool string `url:"masterSepPool,omitempty"` + + // ID of SEP to create boot disks for default worker nodes group. Uses images SEP ID if not set + // Required: false + WorkerSEPID uint64 `url:"workerSepId,omitempty"` + + // Pool to use if worker SEP ID is set, can be also empty if needed to be chosen by system + // Required: false + WorkerSEPPool string `url:"workerSepPool,omitempty"` + // List of strings with labels for default worker group // i.e: ["label1=value1", "label2=value2"] // Required: false diff --git a/pkg/cloudapi/k8s/get_node_labels.go b/pkg/cloudapi/k8s/get_node_labels.go new file mode 100644 index 0000000..4862ab2 --- /dev/null +++ b/pkg/cloudapi/k8s/get_node_labels.go @@ -0,0 +1,46 @@ +package k8s + +import ( + "context" + "errors" + "net/http" +) + +// Request struct for get node labels +type GetNodeLabelsRequest struct { + // Kubernetes cluster ID + // Required: true + K8SID uint64 `url:"k8sId"` + + // Node ID + // Required: false + NodeID uint64 `url:"nodeId"` +} + +func (krq GetNodeLabelsRequest) validate() error { + if krq.K8SID == 0 { + return errors.New("validation-error: field K8SID can not be empty or equal to 0") + } + if krq.NodeID == 0 { + return errors.New("validation-error: field NodeID can not be empty or equal to 0") + } + + return nil +} + +// GetNodeLabels gets kubernetes cluster worker node labels +func (k8s K8S) GetNodeLabels(ctx context.Context, req GetNodeLabelsRequest) (string, error) { + err := req.validate() + if err != nil { + return "", err + } + + url := "/cloudapi/k8s/getNodeLabels" + + res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req) + if err != nil { + return "", err + } + + return string(res), nil +} diff --git a/pkg/cloudapi/k8s/workers_group_add.go b/pkg/cloudapi/k8s/workers_group_add.go index e0189bc..60d1328 100644 --- a/pkg/cloudapi/k8s/workers_group_add.go +++ b/pkg/cloudapi/k8s/workers_group_add.go @@ -17,6 +17,14 @@ type WorkersGroupAddRequest struct { // Required: true Name string `url:"name"` + // ID of SEP to create boot disks for default worker nodes group. Uses images SEP ID if not set + // Required: false + WorkerSEPID uint64 `url:"workerSepId,omitempty"` + + // Pool to use if worker SEP ID is set, can be also empty if needed to be chosen by system + // Required: false + WorkerSEPPool string `url:"workerSepPool,omitempty"` + // List of strings with labels for worker group // i.e: ["label1=value1", "label2=value2"] // Required: false diff --git a/pkg/cloudapi/lb/start.go b/pkg/cloudapi/lb/start.go new file mode 100644 index 0000000..149a1a6 --- /dev/null +++ b/pkg/cloudapi/lb/start.go @@ -0,0 +1,45 @@ +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +// Request struct for start load balancer +type StartRequest struct { + // ID of the load balancer instance to start + // Required: true + LBID uint64 `url:"lbId"` +} + +func (lbrq StartRequest) validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +// Start starts specified load balancer instance +func (l LB) Start(ctx context.Context, req StartRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/start" + + res, err := l.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 +} diff --git a/pkg/cloudapi/lb/stop.go b/pkg/cloudapi/lb/stop.go new file mode 100644 index 0000000..138c304 --- /dev/null +++ b/pkg/cloudapi/lb/stop.go @@ -0,0 +1,45 @@ +package lb + +import ( + "context" + "errors" + "net/http" + "strconv" +) + +// Request struct for stop load balancer +type StopRequest struct { + // ID of the load balancer instance to stop + // Required: true + LBID uint64 `url:"lbId"` +} + +func (lbrq StopRequest) validate() error { + if lbrq.LBID == 0 { + return errors.New("validation-error: field LBID can not be empty or equal to 0") + } + + return nil +} + +// Stop stops specified load balancer instance +func (l LB) Stop(ctx context.Context, req StopRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, err + } + + url := "/cloudapi/lb/start" + + res, err := l.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 +} diff --git a/pkg/cloudapi/rg/create.go b/pkg/cloudapi/rg/create.go index f2ae3ba..ee4f39d 100644 --- a/pkg/cloudapi/rg/create.go +++ b/pkg/cloudapi/rg/create.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for create resource group @@ -80,17 +78,6 @@ type CreateRequest struct { // Register computes in registration system // Required: false RegisterComputes bool `url:"registerComputes,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (rgrq CreateRequest) validate() error { @@ -103,14 +90,6 @@ func (rgrq CreateRequest) validate() error { if len(rgrq.Name) < 2 { return errors.New("field Name can not be shorter than two bytes") } - if len(rgrq.ResTypes) > 0 { - for _, value := range rgrq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudapi/rg/models.go b/pkg/cloudapi/rg/models.go index d275b46..7f42d35 100644 --- a/pkg/cloudapi/rg/models.go +++ b/pkg/cloudapi/rg/models.go @@ -1,7 +1,142 @@ package rg +// Resources used +type Resource struct { + // Number of cores + CPU int64 `json:"cpu"` + + // Disk size + DiskSize int64 `json:"disksize"` + + // Max disk size + DiskSizeMax int64 `json:"disksizemax"` + + // Number of External IPs + ExtIPs int64 `json:"extips"` + + // External traffic + ExtTraffic int64 `json:"exttraffic"` + + // Number of grafic cores + GPU int64 `json:"gpu"` + + // Number of RAM + RAM int64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` +} + +// Disk usage +type DiskUsage struct { + // Disk size + DiskSize float64 `json:"disksize"` + + // Disk size max + DiskSizeMax float64 `json:"disksizemax"` +} + +// Information about resources +type Resources struct { + // Current information about resources + Current Resource `json:"Current"` + + // Reserved information about resources + Reserved Resource `json:"Reserved"` +} + // Detailed information about resource group type RecordResourceGroup struct { + // Resources + Resources Resources `json:"Resources"` + + // Account ID + AccountID uint64 `json:"accountId"` + + // Account name + AccountName string `json:"accountName"` + + // Access Control List + ACL ListACL `json:"acl"` + + // Created by + CreatedBy string `json:"createdBy"` + + // Created time + CreatedTime uint64 `json:"createdTime"` + + // DefNetID + DefNetID int64 `json:"def_net_id"` + + // DefNetType + DefNetType string `json:"def_net_type"` + + // Deleted by + DeletedBy string `json:"deletedBy"` + + // Deleted time + DeletedTime uint64 `json:"deletedTime"` + + // Description + Description string `json:"desc"` + + // Dirty + Dirty bool `json:"dirty"` + + // Grid ID + GID uint64 `json:"gid"` + + // GUID + GUID uint64 `json:"guid"` + + // ID + ID uint64 `json:"id"` + + // Lock status + LockStatus string `json:"lockStatus"` + + // Milestones + Milestones uint64 `json:"milestones"` + + // Name + Name string `json:"name"` + + // RegisterComputes + RegisterComputes bool `json:"registerComputes"` + + // Resource limits + ResourceLimits ResourceLimits `json:"resourceLimits"` + + // Secret + Secret string `json:"secret"` + + // Status + Status string `json:"status"` + + // Updated by + UpdatedBy string `json:"updatedBy"` + + // Updated time + UpdatedTime uint64 `json:"updatedTime"` + + // List of VINS IDs + VINS []uint64 `json:"vins"` + + // List of compute IDs + Computes []uint64 `json:"vms"` + + // List of resource types + ResTypes []string `json:"resourceTypes"` + + // UniqPools + UniqPools []string `json:"uniqPools"` +} + +// Main information about resource group +type ItemResourceGroup struct { + // + AccountACL ItemACL `json:"accountAcl"` + // Account ID AccountID uint64 `json:"accountId"` @@ -78,14 +213,14 @@ type RecordResourceGroup struct { Computes []uint64 `json:"vms"` // List of resource types - ResTypes []string `json:"resTypes"` + ResTypes []string `json:"resourceTypes"` // UniqPools UniqPools []string `json:"uniqPools"` } // List of resource groups -type ListResourceGroups []RecordResourceGroup +type ListResourceGroups []ItemResourceGroup // Main information about Access Control List type ItemACL struct { diff --git a/pkg/cloudapi/rg/update.go b/pkg/cloudapi/rg/update.go index 30abe7a..905bd5b 100644 --- a/pkg/cloudapi/rg/update.go +++ b/pkg/cloudapi/rg/update.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for update resource group @@ -50,31 +48,12 @@ type UpdateRequest struct { // Reason for action // Required: false Reason string `url:"reason,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (rgrq UpdateRequest) validate() error { if rgrq.RGID == 0 { return errors.New("field RGID can not be empty or equal to 0") } - if len(rgrq.ResTypes) > 0 { - for _, value := range rgrq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudbroker/account/create.go b/pkg/cloudbroker/account/create.go index a9d1f0e..4ffeec7 100644 --- a/pkg/cloudbroker/account/create.go +++ b/pkg/cloudbroker/account/create.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for creating account @@ -55,17 +53,6 @@ type CreateRequest struct { // i.e.: ["sep1_poolName1", "sep2_poolName2", etc] // Required: false UniqPools []string `url:"uniqPools,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (arq CreateRequest) validate() error { @@ -75,14 +62,6 @@ func (arq CreateRequest) validate() error { if arq.Username == "" { return errors.New("validation-error: field Username can not be empty") } - if len(arq.ResTypes) > 0 { - for _, value := range arq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudbroker/account/models.go b/pkg/cloudbroker/account/models.go index 1809796..61981e6 100644 --- a/pkg/cloudbroker/account/models.go +++ b/pkg/cloudbroker/account/models.go @@ -36,6 +36,9 @@ type Resource struct { // Disk size DiskSize int64 `json:"disksize"` + // Disk size max + DiskSizeMax int64 `json:"disksizemax"` + // Number of External IPs ExtIPs int64 `json:"extips"` @@ -47,6 +50,18 @@ type Resource struct { // Number of RAM RAM int64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` +} + +// Disk usage +type DiskUsage struct { + // Disk size + DiskSize float64 `json:"disksize"` + + // Disk size max + DiskSizeMax float64 `json:"disksizemax"` } // Access Control List @@ -138,12 +153,18 @@ type InfoAccount struct { // Resource limits ResourceLimits ResourceLimits `json:"resourceLimits"` + // Resource types + ResourceTypes []string `json:"resourceTypes"` + // Send access emails SendAccessEmails bool `json:"sendAccessEmails"` // Status Status string `json:"status"` + // UniqPools + UniqPools []string `json:"uniqPools"` + // UpdatedTime UpdatedTime uint64 `json:"updatedTime"` @@ -258,6 +279,9 @@ type ItemDisk struct { // SepID SepID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Size max SizeMax uint64 `json:"sizeMax"` @@ -351,6 +375,9 @@ type Consumed struct { // Disk size DiskSize uint64 `json:"disksize"` + // Disk size max + DiskSizeMax int64 `json:"disksizemax"` + // External IPs ExtIPs uint64 `json:"extips"` @@ -362,6 +389,9 @@ type Consumed struct { // Number of RAM RAM uint64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` } // Limits @@ -372,6 +402,9 @@ type Limits struct { // Disk size DiskSize int64 `json:"disksize"` + // Disk size max + DiskSizeMax int64 `json:"disksizemax"` + // External IPs ExtIPs int64 `json:"extips"` @@ -383,6 +416,9 @@ type Limits struct { // Number of RAM RAM int64 `json:"ram"` + + // SEPs number + SEPs uint64 `json:"seps"` } // Resources of resource group diff --git a/pkg/cloudbroker/account/update.go b/pkg/cloudbroker/account/update.go index 7b3af9d..cab4cd0 100644 --- a/pkg/cloudbroker/account/update.go +++ b/pkg/cloudbroker/account/update.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for update account @@ -59,17 +57,6 @@ type UpdateRequest struct { // i.e.: ["sep1_poolName1", "sep2_poolName2", etc] // Required: false UniqPools []string `url:"uniqPools,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice must be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (arq UpdateRequest) validate() error { @@ -79,14 +66,6 @@ func (arq UpdateRequest) validate() error { if arq.Name == "" { return errors.New("validation-error: field Name must be set") } - if len(arq.ResTypes) > 0 { - for _, value := range arq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudbroker/account/update_resource_types.go b/pkg/cloudbroker/account/update_resource_types.go new file mode 100644 index 0000000..45bd9e1 --- /dev/null +++ b/pkg/cloudbroker/account/update_resource_types.go @@ -0,0 +1,65 @@ +package account + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +// Request struct for update resource types in account +type UpdateResourceTypesRequest struct { + // ID of account + // Required: true + AccountID uint64 `url:"accountId"` + + // Resource types available to create in this account + // Each element in a resource type slice must be one of: + // - compute + // - vins + // - k8s + // - openshift + // - lb + // - flipgroup + // Required: true + ResTypes []string `url:"resourceTypes"` +} + +func (arq UpdateResourceTypesRequest) validate() error { + if arq.AccountID == 0 { + return errors.New("validation-error: field AccountID must be set") + } + if len(arq.ResTypes) > 0 { + for _, value := range arq.ResTypes { + validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) + if !validate { + return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") + } + } + } + + return nil +} + +func (a Account) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/account/updateResourceTypes" + + res, err := a.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 +} diff --git a/pkg/cloudbroker/compute/list_gpu.go b/pkg/cloudbroker/compute/list_gpu.go index 38be234..8122eba 100644 --- a/pkg/cloudbroker/compute/list_gpu.go +++ b/pkg/cloudbroker/compute/list_gpu.go @@ -27,7 +27,7 @@ func (crq ListGPURequest) validate() error { } // ListVGPU gets list GPU for compute -func (c Compute) ListVGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) { +func (c Compute) ListGPU(ctx context.Context, req ListGPURequest) ([]interface{}, error) { err := req.validate() if err != nil { return nil, err diff --git a/pkg/cloudbroker/compute/models.go b/pkg/cloudbroker/compute/models.go index f83ff63..62248ec 100644 --- a/pkg/cloudbroker/compute/models.go +++ b/pkg/cloudbroker/compute/models.go @@ -401,6 +401,9 @@ type ItemDisk struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Purge attempts PurgeAttempts uint64 `json:"purgeAttempts"` @@ -425,6 +428,9 @@ type ItemDisk struct { // SEP ID SEPID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Size max SizeMax uint64 `json:"sizeMax"` @@ -677,6 +683,9 @@ type InfoCompute struct { // Tech status TechStatus string `json:"techStatus"` + // Total disk size + TotalDiskSize uint64 `json:"totalDisksSize"` + // Updated by UpdatedBy string `json:"updatedBy"` @@ -692,6 +701,9 @@ type InfoCompute struct { // List VGPU IDs VGPUs []uint64 `json:"vgpus"` + // VINS connected + VINSConnected uint64 `json:"vinsConnected"` + // Virtual image ID VirtualImageID uint64 `json:"virtualImageId"` } @@ -708,7 +720,7 @@ type RecordCompute struct { // Main information about compute for list type ItemCompute struct { // List of disk IDs - Disks []uint64 `json:"disks"` + Disks []InfoDisk `json:"disks"` // Main information about compute InfoCompute @@ -720,6 +732,15 @@ type ItemCompute struct { VINSConnected uint64 `json:"vinsConnected"` } +// Information Disk +type InfoDisk struct { + // ID + ID uint64 `json:"id"` + + // PCISlot + PCISlot uint64 `json:"pciSlot"` +} + // List computes type ListComputes []ItemCompute diff --git a/pkg/cloudbroker/disks/models.go b/pkg/cloudbroker/disks/models.go index dd0082f..a7e5618 100644 --- a/pkg/cloudbroker/disks/models.go +++ b/pkg/cloudbroker/disks/models.go @@ -56,6 +56,9 @@ type InfoDisk struct { // Boot partition BootPartition uint64 `json:"bootPartition"` + // Computes + Computes map[string]string `json:"computes"` + // Created time CreatedTime uint64 `json:"createdTime"` @@ -119,6 +122,9 @@ type InfoDisk struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Purge attempts PurgeAttempts uint64 `json:"purgeAttempts"` @@ -143,11 +149,14 @@ type InfoDisk struct { // SEP ID SEPID uint64 `json:"sepId"` + // Shareable + Shareable bool `json:"shareable"` + // Size max SizeMax uint64 `json:"sizeMax"` // Size used - SizeUsed uint64 `json:"sizeUsed"` + SizeUsed float64 `json:"sizeUsed"` // List snapshots Snapshots ListSnapshots `json:"snapshots"` @@ -179,12 +188,6 @@ type RecordDisk struct { // Main information for list disks type ItemDisk struct { - // Compute ID - ComputeID uint64 `json:"computeId"` - - // Compute name - ComputeName string `json:"computeName"` - // Machine ID MachineID uint64 `json:"machineId"` @@ -200,12 +203,6 @@ type ListDisks []ItemDisk // Main information about deleted disk type ItemDeletedDisk struct { - // Compute ID - ComputeID uint64 `json:"computeId"` - - // Compute name - ComputeName string `json:"computeName"` - // Machine ID MachineID uint64 `json:"machineId"` @@ -254,6 +251,9 @@ type ItemSnapshot struct { // Label Label string `json:"label"` + // Reference ID + ReferenceID string `json:"referenceId"` + // Resource ID ResID string `json:"resId"` diff --git a/pkg/cloudbroker/extnet/device_migrate.go b/pkg/cloudbroker/extnet/device_migrate.go index 8d99ed0..78b5093 100644 --- a/pkg/cloudbroker/extnet/device_migrate.go +++ b/pkg/cloudbroker/extnet/device_migrate.go @@ -12,12 +12,18 @@ type DeviceMigrateRequest struct { // ID of external network // Required: true NetID uint64 `url:"net_id"` + + // Target stack ID to migrate to + StackID uint64 `url:"stackId"` } func (erq DeviceMigrateRequest) validate() error { if erq.NetID == 0 { return errors.New("validation-error: field NetID must be set") } + if erq.StackID == 0 { + return errors.New("validation-error: field StackID must be set") + } return nil } diff --git a/pkg/cloudbroker/extnet/models.go b/pkg/cloudbroker/extnet/models.go index 8d9445b..0ad4aae 100644 --- a/pkg/cloudbroker/extnet/models.go +++ b/pkg/cloudbroker/extnet/models.go @@ -127,6 +127,9 @@ type RecordExtNet struct { // CheckIPs CheckIPs []string `json:"checkIPs"` + // CheckIps + CheckIps []string `json:"checkIps"` + // List DNS DNS []string `json:"dns"` diff --git a/pkg/cloudbroker/grid/models.go b/pkg/cloudbroker/grid/models.go index f8c1641..5826f3f 100644 --- a/pkg/cloudbroker/grid/models.go +++ b/pkg/cloudbroker/grid/models.go @@ -17,6 +17,9 @@ type RecordResource struct { // Disk size DiskSize uint64 `json:"disksize"` + // Disk size max + DiskSizeMax int64 `json:"disksizemax"` + // External IPs ExtIPs uint64 `json:"extips"` @@ -28,6 +31,18 @@ type RecordResource struct { // Number of RAM RAM uint64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` +} + +// Disk usage +type DiskUsage struct { + // Disk size + DiskSize float64 `json:"disksize"` + + // Disk size max + DiskSizeMax float64 `json:"disksizemax"` } // Detailed information about grid diff --git a/pkg/cloudbroker/image/models.go b/pkg/cloudbroker/image/models.go index d85c742..11df2cd 100644 --- a/pkg/cloudbroker/image/models.go +++ b/pkg/cloudbroker/image/models.go @@ -74,6 +74,9 @@ type RecordImage struct { // Pool Pool string `json:"pool"` + // Present to + PresentTo []uint64 `json:"presentTo"` + // Provider name ProviderName string `json:"provider_name"` diff --git a/pkg/cloudbroker/kvmppc/mass_create.go b/pkg/cloudbroker/kvmppc/mass_create.go index de8db28..4120247 100644 --- a/pkg/cloudbroker/kvmppc/mass_create.go +++ b/pkg/cloudbroker/kvmppc/mass_create.go @@ -62,9 +62,9 @@ type MassCreateRequest struct { // Required: false NetID uint64 `url:"netId,omitempty"` - // IP address to assign to this VM when connecting to the specified network + // Input data for cloud-init facility // Required: false - IPAddr string `url:"ipAddr,omitempty"` + UserData string `url:"userdata,omitempty"` // Text description of this VM // Required: false diff --git a/pkg/cloudbroker/kvmx86/mass_create.go b/pkg/cloudbroker/kvmx86/mass_create.go index 5743c08..51a560c 100644 --- a/pkg/cloudbroker/kvmx86/mass_create.go +++ b/pkg/cloudbroker/kvmx86/mass_create.go @@ -66,7 +66,7 @@ type MassCreateRequest struct { // Required: false IPAddr string `url:"ipAddr,omitempty"` - // User data + // Input data for cloud-init facility // Required: false UserData string `url:"userdata,omitempty"` diff --git a/pkg/cloudbroker/rg/create.go b/pkg/cloudbroker/rg/create.go index c80fb64..ddb900d 100644 --- a/pkg/cloudbroker/rg/create.go +++ b/pkg/cloudbroker/rg/create.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for create resource group @@ -84,17 +82,6 @@ type CreateRequest struct { // List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2"] // Required: false UniqPools []string `url:"unuqPools,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice should be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (rgrq CreateRequest) validate() error { @@ -107,14 +94,6 @@ func (rgrq CreateRequest) validate() error { if len(rgrq.Name) < 2 { return errors.New("field Name can not be shorter than two bytes") } - if len(rgrq.ResTypes) > 0 { - for _, value := range rgrq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } return nil } diff --git a/pkg/cloudbroker/rg/models.go b/pkg/cloudbroker/rg/models.go index 35be0b3..d07ebd7 100644 --- a/pkg/cloudbroker/rg/models.go +++ b/pkg/cloudbroker/rg/models.go @@ -29,6 +29,9 @@ type Reservation struct { // Disk size DiskSize uint64 `json:"disksize"` + // Max disk size + DiskSizeMax int64 `json:"disksizemax"` + // External IPs ExtIPs uint64 `json:"extips"` @@ -40,6 +43,18 @@ type Reservation struct { // Number of RAM RAM uint64 `json:"ram"` + + // SEPs + SEPs map[string]map[string]DiskUsage `json:"seps"` +} + +// Disk usage +type DiskUsage struct { + // Disk size + DiskSize float64 `json:"disksize"` + + // Disk size max + DiskSizeMax float64 `json:"disksizemax"` } // Resources usage information @@ -180,7 +195,7 @@ type ItemRG struct { VMs []uint64 `json:"vms"` // Resource types list - ResTypes []string `json:"resTypes"` + ResTypes []string `json:"resourceTypes"` // Uniq pools UniqPools []string `json:"uniqPools"` @@ -217,7 +232,7 @@ type ItemAffinityGroupCompute struct { type ListAffinityGroupCompute []ItemAffinityGroupCompute // Main information about affinity rule -type ItemAffinityRule struct { +type ItemRule struct { // GUID GUID string `json:"guid"` @@ -237,8 +252,8 @@ type ItemAffinityRule struct { Value string `json:"value"` } -// List affinity rules -type ListAffinityRules []ItemAffinityRule +// List rules +type ListRules []ItemRule // Main information about compute type ItemCompute struct { @@ -252,13 +267,13 @@ type ItemCompute struct { AffinityLabel string `json:"affinityLabel"` // List affinity rules - AffinityRules ListAffinityRules `json:"affinityRules"` + AffinityRules ListRules `json:"affinityRules"` // Affinity weight AffinityWeight uint64 `json:"affinityWeight"` // Anti affinity rules - AntiAffinityRules []interface{} `json:"antiAffinityRules"` + AntiAffinityRules ListRules `json:"antiAffinityRules"` // Number of CPU CPUs uint64 `json:"cpus"` diff --git a/pkg/cloudbroker/rg/update.go b/pkg/cloudbroker/rg/update.go index 959aa93..99fbb34 100644 --- a/pkg/cloudbroker/rg/update.go +++ b/pkg/cloudbroker/rg/update.go @@ -5,8 +5,6 @@ import ( "errors" "net/http" "strconv" - - "github.com/rudecs/decort-sdk/internal/validators" ) // Request struct for update resource group @@ -54,31 +52,13 @@ type UpdateRequest struct { // List of strings with pools i.e.: ["sep1_poolName1", "sep2_poolName2", etc] // Required: false UniqPools []string `url:"uniqPools,omitempty"` - - // Resource types available to create in this account - // Each element in a resource type slice should be one of: - // - compute - // - vins - // - k8s - // - openshift - // - lb - // - flipgroup - // Required: false - ResTypes []string `url:"resourceTypes,omitempty"` } func (rgrq UpdateRequest) validate() error { if rgrq.RGID == 0 { return errors.New("validation-error: field RGID must be set") } - if len(rgrq.ResTypes) > 0 { - for _, value := range rgrq.ResTypes { - validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) - if !validate { - return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") - } - } - } + return nil } diff --git a/pkg/cloudbroker/rg/update_resource_types.go b/pkg/cloudbroker/rg/update_resource_types.go new file mode 100644 index 0000000..da05658 --- /dev/null +++ b/pkg/cloudbroker/rg/update_resource_types.go @@ -0,0 +1,65 @@ +package rg + +import ( + "context" + "errors" + "net/http" + "strconv" + + "github.com/rudecs/decort-sdk/internal/validators" +) + +// Request struct for update resource types in account +type UpdateResourceTypesRequest struct { + // ID of resource group + // Required: true + RGID uint64 `url:"rgId"` + + // Resource types available to create in this resource group + // Each element in a resource type slice must be one of: + // - compute + // - vins + // - k8s + // - openshift + // - lb + // - flipgroup + // Required: true + ResTypes []string `url:"resourceTypes"` +} + +func (rgrq UpdateResourceTypesRequest) validate() error { + if rgrq.RGID == 0 { + return errors.New("validation-error: field RGID must be set") + } + if len(rgrq.ResTypes) > 0 { + for _, value := range rgrq.ResTypes { + validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}) + if !validate { + return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]") + } + } + } + + return nil +} + +func (r RG) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (bool, error) { + err := req.validate() + if err != nil { + return false, err + } + + url := "/cloudbroker/rg/updateResourceTypes" + + res, err := r.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 +}