This commit is contained in:
2024-04-16 14:26:06 +03:00
parent bc264c4d90
commit e7c968797b
298 changed files with 11066 additions and 398 deletions

View File

@@ -22,7 +22,7 @@ func (i Image) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (b
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/image/сomputeciUnset"
url := "/cloudbroker/image/computeciUnset"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {

View File

@@ -27,7 +27,7 @@ type CreateRequest struct {
// - bios
// - UEFI
// Required: true
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
// Image type
// Should be one of:
@@ -35,7 +35,14 @@ type CreateRequest struct {
// - windows
// - or other
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
// Should be:
// - eth
// - ens (default value)
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize
// Required: false
@@ -78,7 +85,7 @@ type CreateRequest struct {
// List of types of compute suitable for image
// Example: [ "KVM_X86" ]
// Required: true
// Required: required
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
// Bootable image or not

View File

@@ -14,6 +14,13 @@ type EditRequest struct {
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
// Should be:
// - eth
// - ens (default value)
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Name for the image
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`

View File

@@ -2,7 +2,7 @@ package image
// FilterById returns ListImages with specified ID.
func (li ListImages) FilterByID(id uint64) ListImages {
predicate := func(ri RecordImage) bool {
predicate := func(ri ItemImage) bool {
return ri.ID == id
}
@@ -11,7 +11,7 @@ func (li ListImages) FilterByID(id uint64) ListImages {
// FilterByName returns ListImages with specified Name.
func (li ListImages) FilterByName(name string) ListImages {
predicate := func(ri RecordImage) bool {
predicate := func(ri ItemImage) bool {
return ri.Name == name
}
@@ -20,7 +20,7 @@ func (li ListImages) FilterByName(name string) ListImages {
// FilterByStatus returns ListImages with specified Status.
func (li ListImages) FilterByStatus(status string) ListImages {
predicate := func(ri RecordImage) bool {
predicate := func(ri ItemImage) bool {
return ri.Status == status
}
@@ -29,7 +29,7 @@ func (li ListImages) FilterByStatus(status string) ListImages {
// FilterByTechStatus returns ListImages with specified TechStatus.
func (li ListImages) FilterByTechStatus(techStatus string) ListImages {
predicate := func(ri RecordImage) bool {
predicate := func(ri ItemImage) bool {
return ri.TechStatus == techStatus
}
@@ -38,7 +38,7 @@ func (li ListImages) FilterByTechStatus(techStatus string) ListImages {
// FilterByBootType returns ListImages with specified BootType.
func (li ListImages) FilterByBootType(bootType string) ListImages {
predicate := func(ri RecordImage) bool {
predicate := func(ri ItemImage) bool {
return ri.BootType == bootType
}
@@ -46,7 +46,7 @@ func (li ListImages) FilterByBootType(bootType string) ListImages {
}
// FilterFunc allows filtering ListImages based on a user-specified predicate.
func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages {
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
var result ListImages
for _, item := range li.Data {
@@ -60,9 +60,9 @@ func (li ListImages) FilterFunc(predicate func(RecordImage) bool) ListImages {
// FindOne returns first found RecordImage
// If none was found, returns an empty struct.
func (li ListImages) FindOne() RecordImage {
func (li ListImages) FindOne() ItemImage {
if len(li.Data) == 0 {
return RecordImage{}
return ItemImage{}
}
return li.Data[0]

View File

@@ -3,16 +3,9 @@ package image
import "testing"
var images = ListImages{
Data: []RecordImage{
Data: []ItemImage{
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
UNCPath: "",
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
@@ -55,14 +48,7 @@ var images = ListImages{
Virtual: false,
},
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
UNCPath: "",
AccountID: 0,
ACL: []ACL{},
Architecture: "X86_64",
@@ -105,14 +91,7 @@ var images = ListImages{
Virtual: true,
},
{
UNCPath: "",
CKey: "",
Meta: []interface{}{
"osismodel",
"cloudbroker",
"image",
1,
},
UNCPath: "",
AccountID: 1,
ACL: []ACL{},
Architecture: "X86_64",
@@ -202,7 +181,7 @@ func TestFilterByBootType(t *testing.T) {
}
func TestFilterFunc(t *testing.T) {
actual := images.FilterFunc(func(ri RecordImage) bool {
actual := images.FilterFunc(func(ri ItemImage) bool {
return ri.Virtual == true
})

View File

@@ -0,0 +1,42 @@
package image
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GrantAccessRequest struct to share image with accounts
type GrantAccessRequest struct {
// ID of the image to share
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// ID of the accounts for share image
// Required: true
AccountIDs []uint64 `url:"accounts" json:"accounts" validate:"required"`
}
// GrantAccess shares specified image with specified accounts
func (i Image) GrantAccess(ctx context.Context, req GrantAccessRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/image/grantAccess"
res, err := i.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

@@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of available images
@@ -56,6 +58,10 @@ type ListRequest struct {
// Required: false
Bootable bool `url:"bootable,omitempty" json:"bootable,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"`
@@ -67,6 +73,7 @@ type ListRequest struct {
// List gets list of information about images as a ListImages struct
func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
res, err := i.ListRaw(ctx, req)
if err != nil {
return nil, err
@@ -84,6 +91,11 @@ func (i Image) List(ctx context.Context, req ListRequest) (*ListImages, error) {
// ListRaw gets list of information about images as an array of bytes
func (i Image) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/image/list"
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)

View File

@@ -33,10 +33,15 @@ type ListStacksRequest struct {
// Find by type
// 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"`
}
// ListStacks gets list stack by image ID
func (i Image) ListStacks(ctx context.Context, req ListStacksRequest) (*ListStacks, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))

View File

@@ -5,12 +5,6 @@ type RecordImage struct {
// UNC path
UNCPath string `json:"UNCPath"`
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Account ID
AccountID uint64 `json:"accountId"`
@@ -26,6 +20,9 @@ type RecordImage struct {
// Bootable
Bootable bool `json:"bootable"`
// CdPresentedTo
CdPresentedTo interface{} `json:"cdPresentedTo"`
// Compute CI ID
ComputeCIID uint64 `json:"computeciId"`
@@ -68,6 +65,132 @@ type RecordImage struct {
// Name
Name string `json:"name"`
// NetworkInterfaceNaming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Password
Password string `json:"password"`
// Pool
Pool string `json:"pool"`
// Present to
PresentTo []uint64 `json:"presentTo"`
// Provider name
ProviderName string `json:"provider_name"`
// Purge attempts
PurgeAttempts uint64 `json:"purgeAttempts"`
// Reference ID
ReferenceID string `json:"referenceId"`
// Resource ID
ResID string `json:"resId"`
// Resource name
ResName string `json:"resName"`
// Rescue CD
RescueCD bool `json:"rescuecd"`
// SEP ID
SEPID uint64 `json:"sepId"`
// List shared with
SharedWith []uint64 `json:"sharedWith"`
// Size
Size uint64 `json:"size"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Type
Type string `json:"type"`
// URL
URL string `json:"url"`
// Username
Username string `json:"username"`
// Version
Version string `json:"version"`
}
// Detailed information about item of images list
type ItemImage struct {
// UNC path
UNCPath string `json:"UNCPath"`
// Account ID
AccountID uint64 `json:"accountId"`
// Access Control List
ACL ListACL `json:"acl"`
// Architecture
Architecture string `json:"architecture"`
// Boot type
BootType string `json:"bootType"`
// Bootable
Bootable bool `json:"bootable"`
// CdPresentedTo
CdPresentedTo interface{} `json:"cdPresentedTo"`
// Compute CI ID
ComputeCIID uint64 `json:"computeciId"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Drivers
Drivers []string `json:"drivers"`
// Enabled
Enabled bool `json:"enabled"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// List history
History ListHistory `json:"history"`
// Hot resize
HotResize bool `json:"hotResize"`
// ID
ID uint64 `json:"id"`
// Last modified
LastModified uint64 `json:"lastModified"`
// Link to
LinkTo uint64 `json:"linkTo"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// NetworkInterfaceNaming
NetworkInterfaceNaming string `json:"networkInterfaceNaming"`
// Password
Password string `json:"password"`
@@ -129,7 +252,7 @@ type RecordImage struct {
// List images
type ListImages struct {
// Data
Data []RecordImage `json:"data"`
Data []ItemImage `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`

View File

@@ -0,0 +1,42 @@
package image
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RevokeAccessRequest struct to unshare image with accounts
type RevokeAccessRequest struct {
// ID of the image to unshare
// Required: true
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
// ID of the accounts for unshare image
// Required: true
AccountIDs []uint64 `url:"accounts" json:"accounts" validate:"required"`
}
// RevokeAccess unshares specified image with specified accounts
func (i Image) RevokeAccess(ctx context.Context, req RevokeAccessRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/image/revokeAccess"
res, err := i.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

@@ -27,7 +27,7 @@ type SyncCreateRequest struct {
// - bios
// - UEFI
// Required: true
BootType string `url:"boottype" json:"boottype" validate:"imageBootType"`
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
// Image type
// Should be one of:
@@ -35,7 +35,14 @@ type SyncCreateRequest struct {
// - windows
// - or other
// Required: true
ImageType string `url:"imagetype" json:"imagetype" validate:"imageType"`
ImageType string `url:"imagetype" json:"imagetype" validate:"required,imageType"`
// Select a network interface naming pattern for your Linux machine. eth - onboard, ens - pci slot naming
// Should be:
// - eth
// - ens (default value)
// Required: false
NetworkInterfaceNaming string `url:"networkInterfaceNaming,omitempty" json:"networkInterfaceNaming,omitempty" validate:"omitempty,networkInterfaceNaming"`
// Does this machine supports hot resize
// Required: false