v9.0.0
This commit is contained in:
42
pkg/cloudbroker/image/computeci_set.go
Normal file
42
pkg/cloudbroker/image/computeci_set.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ComputeCISetRequest struct to set compute CI
|
||||
type ComputeCISetRequest struct {
|
||||
// ID of the image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// ID of the compute CI
|
||||
// Required: true
|
||||
ComputeCIID uint64 `url:"computeciId" json:"computeciId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeCISet sets compute CI ID for image
|
||||
func (i Image) ComputeCISet(ctx context.Context, req ComputeCISetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/computeciSet"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudbroker/image/computeci_unset.go
Normal file
38
pkg/cloudbroker/image/computeci_unset.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ComputeCIUnsetRequest struct to unset compute CI
|
||||
type ComputeCIUnsetRequest struct {
|
||||
// ID of the image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// ComputeCIUnset unsets compute CI ID from image
|
||||
func (i Image) ComputeCIUnset(ctx context.Context, req ComputeCIUnsetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/computeciUnset"
|
||||
|
||||
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
|
||||
}
|
||||
77
pkg/cloudbroker/image/create_cdrom_image.go
Normal file
77
pkg/cloudbroker/image/create_cdrom_image.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateCDROMImageRequest struct to create CD-ROM image
|
||||
type CreateCDROMImageRequest struct {
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// URL where to download ISO from
|
||||
// Required: true
|
||||
URL string `url:"url" json:"url" validate:"required,url"`
|
||||
|
||||
// Grid (platform) ID where this CD-ROM image should be create in
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Storage endpoint provider ID for place rescue CD
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
||||
|
||||
// Pool for place rescue CD
|
||||
// Required: false
|
||||
PoolName string `url:"pool_name,omitempty" json:"pool_name,omitempty"`
|
||||
|
||||
// Username for remote media download
|
||||
// Required: false
|
||||
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
|
||||
|
||||
// Password for remote media download
|
||||
// Required: false
|
||||
PasswordDl string `url:"passwordDL,omitempty" json:"passwordDL,omitempty"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be one of:
|
||||
// - X86_64
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// List of types of compute suitable for image.
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: false
|
||||
Drivers []string `url:"drivers,omitempty" json:"drivers,omitempty" validate:"max=2,imageDrivers"`
|
||||
}
|
||||
|
||||
// CreateCDROMImage creates CD-ROM image from an ISO identified by URL
|
||||
func (i Image) CreateCDROMImage(ctx context.Context, req CreateCDROMImageRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createCDROMImage"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
115
pkg/cloudbroker/image/create_image.go
Normal file
115
pkg/cloudbroker/image/create_image.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create image
|
||||
type CreateRequest struct {
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// URL where to download media from
|
||||
// Required: true
|
||||
URL string `url:"url" json:"url" validate:"required,url"`
|
||||
|
||||
// Grid (platform) ID where this template should be create in
|
||||
// Required: true
|
||||
GID uint64 `url:"gid" json:"gid" validate:"required"`
|
||||
|
||||
// Boot type of image
|
||||
// Should be one of:
|
||||
// - bios
|
||||
// - UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
|
||||
|
||||
// Image type
|
||||
// Should be one of:
|
||||
// - linux
|
||||
// - windows
|
||||
// - or other
|
||||
// Required: true
|
||||
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
|
||||
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
|
||||
|
||||
// Optional username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Optional password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Username for upload binary media
|
||||
// Required: false
|
||||
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
|
||||
|
||||
// Password for upload binary media
|
||||
// Required: false
|
||||
PasswordDL string `url:"passwordDL,omitempty" json:"passwordDL,omitempty"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool for image create
|
||||
// Required: false
|
||||
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be one of:
|
||||
// - X86_64
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// List of types of compute suitable for image
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: required
|
||||
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
|
||||
|
||||
// Bootable image or not
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
// CreateImage creates image from a media identified by URL
|
||||
func (i Image) CreateImage(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createImage"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/image/create_virtual.go
Normal file
42
pkg/cloudbroker/image/create_virtual.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// CreateVirtualRequest struct to create virtual image
|
||||
type CreateVirtualRequest struct {
|
||||
// Name of the virtual image to create
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// ID of real image to link this virtual image to upon creation
|
||||
// Required: true
|
||||
TargetID uint64 `url:"targetId" json:"targetId" validate:"required"`
|
||||
}
|
||||
|
||||
// CreateVirtual creates virtual image
|
||||
func (i Image) CreateVirtual(ctx context.Context, req CreateVirtualRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/createVirtual"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
38
pkg/cloudbroker/image/delete.go
Normal file
38
pkg/cloudbroker/image/delete.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete image
|
||||
type DeleteRequest struct {
|
||||
// ID of the image to delete
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// Delete deletes image by ID
|
||||
func (i Image) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/delete"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudbroker/image/delete_cdrom_image.go
Normal file
38
pkg/cloudbroker/image/delete_cdrom_image.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteCDROMImageRequest struct to delete CD-ROM image
|
||||
type DeleteCDROMImageRequest struct {
|
||||
// ID of the CD-ROM image to delete
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// DeleteCDROMImage deletes a CD-ROM image
|
||||
func (i Image) DeleteCDROMImage(ctx context.Context, req DeleteCDROMImageRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/deleteCDROMImage"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudbroker/image/delete_images.go
Normal file
38
pkg/cloudbroker/image/delete_images.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteImagesRequest struct to delete images
|
||||
type DeleteImagesRequest struct {
|
||||
// List of images to be deleted
|
||||
// Required: true
|
||||
ImageIDs []uint64 `url:"imageIds" json:"imageIds" validate:"min=1"`
|
||||
}
|
||||
|
||||
// DeleteImages deletes images
|
||||
func (i Image) DeleteImages(ctx context.Context, req DeleteImagesRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/deleteImages"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudbroker/image/disable.go
Normal file
38
pkg/cloudbroker/image/disable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// DisableRequest struct to disable image
|
||||
type DisableRequest struct {
|
||||
// ID of image to be disabled
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables image
|
||||
func (i Image) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/disable"
|
||||
|
||||
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
|
||||
}
|
||||
69
pkg/cloudbroker/image/edit.go
Normal file
69
pkg/cloudbroker/image/edit.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EditRequest struct to edit image
|
||||
type EditRequest struct {
|
||||
// ID of the image to edit
|
||||
// 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"`
|
||||
|
||||
// Username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Does this machine supports hot resize
|
||||
// Required: false
|
||||
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
|
||||
|
||||
// Does this image boot OS
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
// Edit edits an existing image
|
||||
func (i Image) Edit(ctx context.Context, req EditRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/edit"
|
||||
|
||||
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
|
||||
}
|
||||
38
pkg/cloudbroker/image/enable.go
Normal file
38
pkg/cloudbroker/image/enable.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// EnableRequest struct to enable image
|
||||
type EnableRequest struct {
|
||||
// ID of image to be enabled
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// Enable enables image
|
||||
func (i Image) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/enable"
|
||||
|
||||
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
|
||||
}
|
||||
69
pkg/cloudbroker/image/filter.go
Normal file
69
pkg/cloudbroker/image/filter.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package image
|
||||
|
||||
// FilterById returns ListImages with specified ID.
|
||||
func (li ListImages) FilterByID(id uint64) ListImages {
|
||||
predicate := func(ri ItemImage) bool {
|
||||
return ri.ID == id
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns ListImages with specified Name.
|
||||
func (li ListImages) FilterByName(name string) ListImages {
|
||||
predicate := func(ri ItemImage) bool {
|
||||
return ri.Name == name
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByStatus returns ListImages with specified Status.
|
||||
func (li ListImages) FilterByStatus(status string) ListImages {
|
||||
predicate := func(ri ItemImage) bool {
|
||||
return ri.Status == status
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByTechStatus returns ListImages with specified TechStatus.
|
||||
func (li ListImages) FilterByTechStatus(techStatus string) ListImages {
|
||||
predicate := func(ri ItemImage) bool {
|
||||
return ri.TechStatus == techStatus
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByBootType returns ListImages with specified BootType.
|
||||
func (li ListImages) FilterByBootType(bootType string) ListImages {
|
||||
predicate := func(ri ItemImage) bool {
|
||||
return ri.BootType == bootType
|
||||
}
|
||||
|
||||
return li.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListImages based on a user-specified predicate.
|
||||
func (li ListImages) FilterFunc(predicate func(ItemImage) bool) ListImages {
|
||||
var result ListImages
|
||||
|
||||
for _, item := range li.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found RecordImage
|
||||
// If none was found, returns an empty struct.
|
||||
func (li ListImages) FindOne() ItemImage {
|
||||
if len(li.Data) == 0 {
|
||||
return ItemImage{}
|
||||
}
|
||||
|
||||
return li.Data[0]
|
||||
}
|
||||
195
pkg/cloudbroker/image/filter_test.go
Normal file
195
pkg/cloudbroker/image/filter_test.go
Normal file
@@ -0,0 +1,195 @@
|
||||
package image
|
||||
|
||||
import "testing"
|
||||
|
||||
var images = ListImages{
|
||||
Data: []ItemImage{
|
||||
{
|
||||
UNCPath: "",
|
||||
AccountID: 0,
|
||||
ACL: []ACL{},
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
ComputeCIID: 0,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
Enabled: true,
|
||||
GID: 212,
|
||||
GUID: 9882,
|
||||
History: []History{},
|
||||
HotResize: true,
|
||||
ID: 9882,
|
||||
LastModified: 0,
|
||||
LinkTo: 0,
|
||||
Milestones: 363491,
|
||||
Name: "u16",
|
||||
Password: "",
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{},
|
||||
ProviderName: "",
|
||||
PurgeAttempts: 0,
|
||||
ReferenceID: "sample_reference_id_u16",
|
||||
ResID: "b321318-3214as-324-213-fdas",
|
||||
ResName: "templates/image_9882",
|
||||
RescueCD: false,
|
||||
SEPID: 2504,
|
||||
SharedWith: []uint64{},
|
||||
Size: 5,
|
||||
Status: "CREATED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "linux",
|
||||
URL: "http://sample_url:8000/u16",
|
||||
Username: "",
|
||||
Version: "",
|
||||
Virtual: false,
|
||||
},
|
||||
{
|
||||
UNCPath: "",
|
||||
AccountID: 0,
|
||||
ACL: []ACL{},
|
||||
Architecture: "X86_64",
|
||||
BootType: "bois",
|
||||
Bootable: true,
|
||||
ComputeCIID: 0,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
Enabled: false,
|
||||
GID: 212,
|
||||
GUID: 9884,
|
||||
History: []History{},
|
||||
HotResize: false,
|
||||
ID: 9884,
|
||||
LastModified: 0,
|
||||
LinkTo: 0,
|
||||
Milestones: 363499,
|
||||
Name: "alpine-virt-3.17",
|
||||
Password: "",
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{},
|
||||
ProviderName: "",
|
||||
PurgeAttempts: 0,
|
||||
ReferenceID: "sample_reference_id_alpine",
|
||||
ResID: "31d1d410-74f1-4e09-866b-046a5a8433c3",
|
||||
ResName: "templates/image_9884",
|
||||
RescueCD: false,
|
||||
SEPID: 2504,
|
||||
SharedWith: []uint64{},
|
||||
Size: 1,
|
||||
Status: "CREATED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "linux",
|
||||
URL: "http://sample_url:8000/alpine-virt-3",
|
||||
Username: "",
|
||||
Version: "",
|
||||
Virtual: true,
|
||||
},
|
||||
{
|
||||
UNCPath: "",
|
||||
AccountID: 1,
|
||||
ACL: []ACL{},
|
||||
Architecture: "X86_64",
|
||||
BootType: "bios",
|
||||
Bootable: true,
|
||||
ComputeCIID: 0,
|
||||
DeletedTime: 0,
|
||||
Description: "",
|
||||
Drivers: []string{
|
||||
"KVM_X86",
|
||||
},
|
||||
Enabled: true,
|
||||
GID: 212,
|
||||
GUID: 9885,
|
||||
History: []History{},
|
||||
HotResize: true,
|
||||
ID: 9885,
|
||||
LastModified: 0,
|
||||
LinkTo: 0,
|
||||
Milestones: 363513,
|
||||
Name: "test",
|
||||
Password: "",
|
||||
Pool: "vmstor",
|
||||
PresentTo: []uint64{},
|
||||
ProviderName: "",
|
||||
PurgeAttempts: 0,
|
||||
ReferenceID: "sample_reference_id_test",
|
||||
ResID: "1f53b815-1ac9-4a4b-af98-a0a3b69a34bb",
|
||||
ResName: "templates/image_9885",
|
||||
RescueCD: false,
|
||||
SEPID: 2505,
|
||||
SharedWith: []uint64{},
|
||||
Size: 4,
|
||||
Status: "DESTROYED",
|
||||
TechStatus: "ALLOCATED",
|
||||
Type: "linux",
|
||||
URL: "http://sample_url:8000/test",
|
||||
Username: "",
|
||||
Version: "",
|
||||
Virtual: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := images.FilterByID(9885).FindOne()
|
||||
|
||||
if actual.ID != 9885 {
|
||||
t.Fatal("expected ID 9885, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := images.FilterByName("u16").FindOne()
|
||||
|
||||
if actual.Name != "u16" {
|
||||
t.Fatal("expected Name 'u16', found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByStatus(t *testing.T) {
|
||||
actual := images.FilterByStatus("CREATED")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Status != "CREATED" {
|
||||
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByBootType(t *testing.T) {
|
||||
actual := images.FilterByBootType("bios")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.BootType != "bios" {
|
||||
t.Fatal("expected BootType 'bios', found: ", item.BootType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := images.FilterFunc(func(ri ItemImage) bool {
|
||||
return ri.Virtual == true
|
||||
})
|
||||
|
||||
if len(actual.Data) != 1 {
|
||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
if actual.Data[0].Virtual != true {
|
||||
t.Fatal("expected Virtual true, found false")
|
||||
}
|
||||
}
|
||||
46
pkg/cloudbroker/image/get.go
Normal file
46
pkg/cloudbroker/image/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get image details
|
||||
type GetRequest struct {
|
||||
// ID of image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets image details by ID as a RecordImage struct
|
||||
func (i Image) Get(ctx context.Context, req GetRequest) (*RecordImage, error) {
|
||||
res, err := i.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordImage{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets image details by ID as an array of bytes
|
||||
func (i Image) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/get"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
42
pkg/cloudbroker/image/grant_access.go
Normal file
42
pkg/cloudbroker/image/grant_access.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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
|
||||
}
|
||||
28
pkg/cloudbroker/image/ids.go
Normal file
28
pkg/cloudbroker/image/ids.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package image
|
||||
|
||||
// IDs gets array of ImageIDs from ListImages struct
|
||||
func (li ListImages) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(li.Data))
|
||||
for _, i := range li.Data {
|
||||
res = append(res, i.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of StackIDs from ListStacks struct
|
||||
func (ls ListStacks) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(ls.Data))
|
||||
for _, h := range ls.Data {
|
||||
res = append(res, h.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of HistoryIDs from ListHistory struct
|
||||
func (lh ListHistory) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lh))
|
||||
for _, h := range lh {
|
||||
res = append(res, h.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
16
pkg/cloudbroker/image/image.go
Normal file
16
pkg/cloudbroker/image/image.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Lists all the images. A image is a template which can be used to deploy machines
|
||||
package image
|
||||
|
||||
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
|
||||
// Structure for creating request to image
|
||||
type Image struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for image endpoint
|
||||
func New(client interfaces.Caller) *Image {
|
||||
return &Image{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
42
pkg/cloudbroker/image/link.go
Normal file
42
pkg/cloudbroker/image/link.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// LinkRequest struct to link virtual image to another image
|
||||
type LinkRequest struct {
|
||||
// ID of the virtual image
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// ID of real image to link this virtual image to
|
||||
// Required: true
|
||||
TargetID uint64 `url:"targetId" json:"targetId" validate:"required"`
|
||||
}
|
||||
|
||||
// Link links virtual image to another image in the platform
|
||||
func (i Image) Link(ctx context.Context, req LinkRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/link"
|
||||
|
||||
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
|
||||
}
|
||||
107
pkg/cloudbroker/image/list.go
Normal file
107
pkg/cloudbroker/image/list.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListRequest struct to get list of available images
|
||||
type ListRequest struct {
|
||||
// Filter images by storage endpoint provider ID
|
||||
// Required: false
|
||||
SepID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Find by ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Find by architecture
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// Find by type
|
||||
// Required: false
|
||||
TypeImage string `url:"typeImage,omitempty" json:"typeImage,omitempty"`
|
||||
|
||||
// Find by image size
|
||||
// Required: false
|
||||
ImageSize uint64 `url:"imageSize,omitempty" json:"imageSize,omitempty"`
|
||||
|
||||
// Find by SEP name
|
||||
// Required: false
|
||||
SEPName string `url:"sepName,omitempty" json:"sepName,omitempty"`
|
||||
|
||||
// Find by pool
|
||||
// Required: false
|
||||
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
|
||||
|
||||
// Find by public True or False
|
||||
// Required: false
|
||||
Public interface{} `url:"public,omitempty" json:"public,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Find by hot resize True or False
|
||||
// Required: false
|
||||
HotResize interface{} `url:"hotResize,omitempty" json:"hotResize,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Find by bootable True or False
|
||||
// Required: false
|
||||
Bootable interface{} `url:"bootable,omitempty" json:"bootable,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Sort by one of supported fields, format +|-(field)
|
||||
// Required: false
|
||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Find by enabled True or False
|
||||
// Required: false
|
||||
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
list := ListImages{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
return res, err
|
||||
}
|
||||
65
pkg/cloudbroker/image/list_stacks.go
Normal file
65
pkg/cloudbroker/image/list_stacks.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ListStacksRequest struct to get list of stack
|
||||
type ListStacksRequest struct {
|
||||
// Image ID
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// Page number
|
||||
// Required: false
|
||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Page size
|
||||
// Required: false
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
|
||||
// Find by name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/listStacks"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListStacks{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
479
pkg/cloudbroker/image/models.go
Normal file
479
pkg/cloudbroker/image/models.go
Normal file
@@ -0,0 +1,479 @@
|
||||
package image
|
||||
|
||||
// Detailed information about image
|
||||
type RecordImage 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"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// 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"`
|
||||
|
||||
// Virtual
|
||||
Virtual bool `json:"virtual"`
|
||||
}
|
||||
|
||||
// List images
|
||||
type ListImages struct {
|
||||
// Data
|
||||
Data []ItemImage `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Access Control List
|
||||
type ACL struct {
|
||||
// Explicit
|
||||
Explicit bool `json:"explicit"`
|
||||
|
||||
// GUID
|
||||
GUID string `json:"guid"`
|
||||
|
||||
// Right
|
||||
Right string `json:"right"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
|
||||
// User group ID
|
||||
UserGroupID string `json:"userGroupId"`
|
||||
}
|
||||
|
||||
// List ACL
|
||||
type ListACL []ACL
|
||||
|
||||
// History information
|
||||
type History struct {
|
||||
// GUID
|
||||
GUID GUID `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// Timestamp
|
||||
Timestamp uint64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
type GUID string
|
||||
|
||||
func (r *GUID) UnmarshalJSON(b []byte) error {
|
||||
|
||||
if b[0] == '"' {
|
||||
*r = GUID(string(b[1 : len(b)-1]))
|
||||
return nil
|
||||
}
|
||||
|
||||
*r = GUID(string(b))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// List history
|
||||
type ListHistory []History
|
||||
|
||||
// List stacks
|
||||
type ListStacks struct {
|
||||
// Data
|
||||
Data []ItemListStacks `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Detailed information about image
|
||||
type ItemListStacks struct {
|
||||
// CKey
|
||||
CKey string `json:"_ckey"`
|
||||
|
||||
// Meta
|
||||
Meta []interface{} `json:"_meta"`
|
||||
|
||||
// API URL
|
||||
APIURL string `json:"apiUrl"`
|
||||
|
||||
// API key
|
||||
APIKey string `json:"apikey"`
|
||||
|
||||
// App ID
|
||||
AppID string `json:"appId"`
|
||||
|
||||
// CPU allocation ratio
|
||||
CPUAllocationRatio float64 `json:"cpu_allocation_ratio"`
|
||||
|
||||
// Description
|
||||
Description string `json:"desc"`
|
||||
|
||||
// Descr
|
||||
Descr string `json:"descr"`
|
||||
|
||||
// Drivers
|
||||
Drivers []string `json:"drivers"`
|
||||
|
||||
// Eco
|
||||
Eco interface{} `json:"eco"`
|
||||
|
||||
// Error
|
||||
Error uint64 `json:"error"`
|
||||
|
||||
// Grid ID
|
||||
GID uint64 `json:"gid"`
|
||||
|
||||
// GID
|
||||
GUID uint64 `json:"guid"`
|
||||
|
||||
// ID
|
||||
ID uint64 `json:"id"`
|
||||
|
||||
// List image IDs
|
||||
Images []uint64 `json:"images"`
|
||||
|
||||
// Login
|
||||
Login string `json:"login"`
|
||||
|
||||
// Mem allocation ratio
|
||||
MemAllocationRatio float64 `json:"mem_allocation_ratio"`
|
||||
|
||||
// Name
|
||||
Name string `json:"name"`
|
||||
|
||||
// Packegas
|
||||
Packages Packages `json:"packages"`
|
||||
|
||||
// Password
|
||||
Password string `json:"passwd"`
|
||||
|
||||
// Reference ID
|
||||
ReferenceID string `json:"referenceId"`
|
||||
|
||||
// Status
|
||||
Status string `json:"status"`
|
||||
|
||||
// Type
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// Package
|
||||
type Packages struct {
|
||||
// LibvirtBin
|
||||
LibvirtBin LibvirtBin `json:"libvirt-bin"`
|
||||
|
||||
// LibvirtDaemon
|
||||
LibvirtDaemon LibvirtDaemon `json:"libvirt-daemon"`
|
||||
|
||||
// Lvm2Lockd
|
||||
Lvm2Lockd Lvm2Lockd `json:"lvm2-lockd"`
|
||||
|
||||
// OpenvswitchCommon
|
||||
OpenvswitchCommon OpenvswitchCommon `json:"openvswitch-common"`
|
||||
|
||||
// OpenvswitchSwitch
|
||||
OpenvswitchSwitch OpenvswitchSwitch `json:"openvswitch-switch"`
|
||||
|
||||
// QemuSystemX86
|
||||
QemuSystemX86 QemuSystemX86 `json:"qemu-system-x86"`
|
||||
|
||||
// Sanlock
|
||||
Sanlock Sanlock `json:"sanlock"`
|
||||
}
|
||||
|
||||
// LibvirtBin
|
||||
type LibvirtBin struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
type LibvirtDaemon struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
// Lvm2Lockd
|
||||
type Lvm2Lockd struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
// OpenvswitchCommon
|
||||
type OpenvswitchCommon struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
// OpenvswitchSwitch
|
||||
type OpenvswitchSwitch struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
// QemuSystemX86
|
||||
type QemuSystemX86 struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
|
||||
// Sanlock
|
||||
type Sanlock struct {
|
||||
// InstalledSize
|
||||
InstalledSize string `json:"installed_size"`
|
||||
|
||||
// Version
|
||||
Ver string `json:"ver"`
|
||||
}
|
||||
42
pkg/cloudbroker/image/rename.go
Normal file
42
pkg/cloudbroker/image/rename.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// RenameRequest struct to rename image
|
||||
type RenameRequest struct {
|
||||
// ID of the virtual image to rename
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// New name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
}
|
||||
|
||||
// Rename renames image by ID
|
||||
func (i Image) Rename(ctx context.Context, req RenameRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/rename"
|
||||
|
||||
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
|
||||
}
|
||||
42
pkg/cloudbroker/image/revoke_access.go
Normal file
42
pkg/cloudbroker/image/revoke_access.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/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
|
||||
}
|
||||
43
pkg/cloudbroker/image/serialize.go
Normal file
43
pkg/cloudbroker/image/serialize.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/serialization"
|
||||
)
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (li ListImages) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(li.Data) == 0 {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(li, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(li)
|
||||
}
|
||||
|
||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
||||
//
|
||||
// In order to serialize with indent make sure to follow these guidelines:
|
||||
// - First argument -> prefix
|
||||
// - Second argument -> indent
|
||||
func (ri RecordImage) Serialize(params ...string) (serialization.Serialized, error) {
|
||||
if len(params) > 1 {
|
||||
prefix := params[0]
|
||||
indent := params[1]
|
||||
|
||||
return json.MarshalIndent(ri, prefix, indent)
|
||||
}
|
||||
|
||||
return json.Marshal(ri)
|
||||
}
|
||||
42
pkg/cloudbroker/image/share.go
Normal file
42
pkg/cloudbroker/image/share.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// ShareRequest struct to share image
|
||||
type ShareRequest struct {
|
||||
// ID of the image to share
|
||||
// Required: true
|
||||
ImageId uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// List of account IDs
|
||||
// Required: true
|
||||
AccountIDs []uint64 `url:"accounts" json:"accounts" validate:"min=1"`
|
||||
}
|
||||
|
||||
// Share shares image with accounts
|
||||
func (i Image) Share(ctx context.Context, req ShareRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/share"
|
||||
|
||||
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
|
||||
}
|
||||
111
pkg/cloudbroker/image/sync_create_image.go
Normal file
111
pkg/cloudbroker/image/sync_create_image.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// SyncCreateRequest struct to sync create image
|
||||
type SyncCreateRequest struct {
|
||||
// Name of the rescue disk
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// URL where to download media from
|
||||
// Required: true
|
||||
URL string `url:"url" json:"url" validate:"required"`
|
||||
|
||||
// Boot type of image
|
||||
// Should be one of:
|
||||
// - bios
|
||||
// - UEFI
|
||||
// Required: true
|
||||
BootType string `url:"boottype" json:"boottype" validate:"required,imageBootType"`
|
||||
|
||||
// Image type
|
||||
// Should be one of:
|
||||
// - linux
|
||||
// - windows
|
||||
// - or other
|
||||
// Required: true
|
||||
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
|
||||
HotResize bool `url:"hotresize,omitempty" json:"hotresize,omitempty"`
|
||||
|
||||
// Optional username for the image
|
||||
// Required: false
|
||||
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||
|
||||
// Optional password for the image
|
||||
// Required: false
|
||||
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||
|
||||
// Account ID to make the image exclusive
|
||||
// Required: false
|
||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
||||
|
||||
// Username for upload binary media
|
||||
// Required: false
|
||||
UsernameDL string `url:"usernameDL,omitempty" json:"usernameDL,omitempty"`
|
||||
|
||||
// Password for upload binary media
|
||||
// Required: false
|
||||
PasswordDL string `url:"passwordDL,omitempty" json:"passwordDL,omitempty"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
||||
|
||||
// Pool for image create
|
||||
// Required: false
|
||||
PoolName string `url:"poolName,omitempty" json:"poolName,omitempty"`
|
||||
|
||||
// Binary architecture of this image
|
||||
// Should be one of:
|
||||
// - X86_64
|
||||
// Required: false
|
||||
Architecture string `url:"architecture,omitempty" json:"architecture,omitempty"`
|
||||
|
||||
// List of types of compute suitable for image
|
||||
// Example: [ "KVM_X86" ]
|
||||
// Required: true
|
||||
Drivers []string `url:"drivers" json:"drivers" validate:"min=1,max=2,imageDrivers"`
|
||||
|
||||
// Bootable image or not
|
||||
// Required: false
|
||||
Bootable bool `url:"bootable,omitempty" json:"bootable,omitempty"`
|
||||
}
|
||||
|
||||
// SyncCreate creates image from a media identified by URL (in synchronous mode)
|
||||
func (i Image) SyncCreate(ctx context.Context, req SyncCreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/syncCreateImage"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/cloudbroker/image/update_nodes.go
Normal file
42
pkg/cloudbroker/image/update_nodes.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// UpdateNodesRequest struct to update nodes
|
||||
type UpdateNodesRequest struct {
|
||||
// Image ID
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// List of stacks
|
||||
// Required: false
|
||||
EnabledStacks []uint64 `url:"enabledStacks,omitempty" json:"enabledStacks,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateNodes updates image availability on nodes
|
||||
func (i Image) UpdateNodes(ctx context.Context, req UpdateNodesRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/updateNodes"
|
||||
|
||||
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
|
||||
}
|
||||
39
pkg/cloudbroker/image/upload_image_file.go
Normal file
39
pkg/cloudbroker/image/upload_image_file.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// UploadImageFileResponse struct to enable image
|
||||
type UploadImageFileResponse struct {
|
||||
// ImageFileUri
|
||||
ImageFileUri string `json:"image_file_uri"`
|
||||
}
|
||||
|
||||
// UploadImageFile uploads file image to platform
|
||||
func (i Image) UploadImageFile(ctx context.Context, filePath string) (string, error) {
|
||||
file, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("can not read file %v", err)
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/uploadImageFile"
|
||||
|
||||
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := UploadImageFileResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return result.ImageFileUri, nil
|
||||
}
|
||||
Reference in New Issue
Block a user