v1.0.0
This commit is contained in:
42
pkg/template/get.go
Normal file
42
pkg/template/get.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/template/models"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/template/requests"
|
||||
)
|
||||
|
||||
// Get return information about specified template
|
||||
func (t Template) Get(ctx context.Context, req requests.GetTemplateRequest) (*models.RecordTemplateResponse, error) {
|
||||
res, err := t.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := models.RecordTemplateResponse{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// GetRaw return information about specified template an array of bytes
|
||||
func (t Template) GetRaw(ctx context.Context, req requests.GetTemplateRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := constants.APIv0 + "/template/" + fmt.Sprint(req.TemplateID)
|
||||
|
||||
res, err := t.client.ApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
41
pkg/template/list.go
Normal file
41
pkg/template/list.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/internal/validators"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/template/models"
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/template/requests"
|
||||
)
|
||||
|
||||
// List gets a list of all templates the user has access to a ListAccounts struct
|
||||
func (t Template) List(ctx context.Context, req requests.ListTemplateRequest) (*models.ListTemplate, error) {
|
||||
res, err := t.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := models.ListTemplate{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all templates the user has access to as an array of bytes
|
||||
func (t Template) ListRaw(ctx context.Context, req requests.ListTemplateRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := constants.APIv1 + "/template"
|
||||
|
||||
res, err := t.client.ApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
110
pkg/template/models/model_get.go
Normal file
110
pkg/template/models/model_get.go
Normal file
@@ -0,0 +1,110 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type RecordTemplateResponse struct {
|
||||
TemplateInfo RecordTemplate `json:"template_info"`
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
type RecordTemplate struct {
|
||||
CPULimit int `json:"cpu_limit"`
|
||||
Status string `json:"status"`
|
||||
IoPriority int `json:"io_priority"`
|
||||
HaStatus string `json:"ha_status"`
|
||||
Description string `json:"description"`
|
||||
NodeMask string `json:"node_mask"`
|
||||
Rates any `json:"rates"`
|
||||
IsInfrastructure bool `json:"is_infrastructure"`
|
||||
HaEnabled bool `json:"ha_enabled"`
|
||||
FolderID int `json:"folder_id"`
|
||||
SystemFlags string `json:"system_flags"`
|
||||
UsedByDesktop bool `json:"used_by_desktop"`
|
||||
Location string `json:"location"`
|
||||
GuestOsVersion string `json:"guest_os_version"`
|
||||
MaxRAMSize int `json:"max_ram_size"`
|
||||
ExternalUUID string `json:"external_uuid"`
|
||||
Domain string `json:"domain"`
|
||||
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
|
||||
VirtType string `json:"virt_type"`
|
||||
Created time.Time `json:"created"`
|
||||
CPUUnits int `json:"cpu_units"`
|
||||
Ratebound bool `json:"ratebound"`
|
||||
InstallOs bool `json:"install_os"`
|
||||
MonitoringEnabled bool `json:"monitoring_enabled"`
|
||||
RAMSize int `json:"ram_size"`
|
||||
Maxmemory int `json:"maxmemory"`
|
||||
Name string `json:"name"`
|
||||
GuestOs string `json:"guest_os"`
|
||||
CPUSockets int `json:"cpu_sockets"`
|
||||
AutoStartDelay int `json:"auto_start_delay"`
|
||||
CoresCount int `json:"cores_count"`
|
||||
GuestToolsState string `json:"guest_tools_state"`
|
||||
Deleted time.Time `json:"deleted"`
|
||||
ResourcePoolID int `json:"resource_pool_id"`
|
||||
SmbiosUUID string `json:"smbios_uuid"`
|
||||
CPUMask string `json:"cpu_mask"`
|
||||
CPUCount int `json:"cpu_count"`
|
||||
MacAddresses any `json:"mac_addresses"`
|
||||
IsLinkedClone bool `json:"is_linked_clone"`
|
||||
BootDeviceList []BootDevice `json:"boot_device_list"`
|
||||
IopsLimit int `json:"iops_limit"`
|
||||
VncHostname string `json:"vnc_hostname"`
|
||||
Imported bool `json:"imported"`
|
||||
ExternalStorageName string `json:"external_storage_name"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
CPUHotplug bool `json:"cpu_hotplug"`
|
||||
MemGuaranteeSize int `json:"mem_guarantee_size"`
|
||||
LinkedVMID int `json:"linked_vm_id"`
|
||||
ParentUUID string `json:"parent_uuid"`
|
||||
IsVzTemplate bool `json:"is_vz_template"`
|
||||
IoLimit int `json:"io_limit"`
|
||||
Chipset string `json:"chipset"`
|
||||
VncMode string `json:"vnc_mode"`
|
||||
DisableAutobalance bool `json:"disable_autobalance"`
|
||||
ExternalStorageID int `json:"external_storage_id"`
|
||||
ClusterID int `json:"cluster_id"`
|
||||
HaPriority int `json:"ha_priority"`
|
||||
VMID int `json:"vm_id"`
|
||||
ClockOffset string `json:"clock_offset"`
|
||||
Lock bool `json:"lock"`
|
||||
RAMBalloonActualHotplug bool `json:"ram_balloon_actual_hotplug"`
|
||||
VncPassword string `json:"vnc_password"`
|
||||
ExternalResourceName string `json:"external_resource_name"`
|
||||
RAMTotalHotplug int `json:"ram_total_hotplug"`
|
||||
SecureBoot bool `json:"secure_boot"`
|
||||
ExternalResourceID int `json:"external_resource_id"`
|
||||
Affinity string `json:"affinity"`
|
||||
IsTemplate bool `json:"is_template"`
|
||||
NodeID int `json:"node_id"`
|
||||
VncPort int `json:"vnc_port"`
|
||||
LinkedVMUUID string `json:"linked_vm_uuid"`
|
||||
VideoRAMSize int `json:"video_ram_size"`
|
||||
AutoStop string `json:"auto_stop"`
|
||||
TpmEnabled bool `json:"tpm_enabled"`
|
||||
UUID string `json:"uuid"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
Hostname string `json:"hostname"`
|
||||
EfiEnabled bool `json:"efi_enabled"`
|
||||
AutoStart string `json:"auto_start"`
|
||||
LinkedCloneCount int `json:"linked_clone_count"`
|
||||
SnapshotCount int `json:"snapshot_count"`
|
||||
HostDeviceCount int `json:"host_device_count"`
|
||||
Node Node `json:"node"`
|
||||
AllMd5 bool `json:"all_md5"`
|
||||
DisksSize int `json:"disks_size"`
|
||||
TemplateSize float64 `json:"template_size"`
|
||||
FullHardDriveSize int `json:"full_hard_drive_size"`
|
||||
UsedHardDriveSize float64 `json:"used_hard_drive_size"`
|
||||
ParentTree []ParentTree `json:"parent_tree"`
|
||||
}
|
||||
|
||||
// ParentTree represents the parent tree information.
|
||||
type ParentTree struct {
|
||||
VMID int `json:"vm_id"`
|
||||
Name string `json:"name"`
|
||||
UUID string `json:"uuid"`
|
||||
ParentID int `json:"parent_id"`
|
||||
IsTemplate bool `json:"is_template"`
|
||||
Depth int `json:"depth"`
|
||||
}
|
||||
117
pkg/template/models/model_list.go
Normal file
117
pkg/template/models/model_list.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type ListTemplate struct {
|
||||
Total int `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PerPage int `json:"per_page"`
|
||||
IsApproximateTotal bool `json:"is_approximate_total"`
|
||||
Items []ItemTemplate `json:"items"`
|
||||
HasMore bool `json:"has_more"`
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
type ItemTemplate struct {
|
||||
CPULimit int `json:"cpu_limit"`
|
||||
Status string `json:"status"`
|
||||
IoPriority int `json:"io_priority"`
|
||||
HaStatus string `json:"ha_status"`
|
||||
Description string `json:"description"`
|
||||
NodeMask string `json:"node_mask"`
|
||||
Rates any `json:"rates"`
|
||||
IsInfrastructure bool `json:"is_infrastructure"`
|
||||
HaEnabled bool `json:"ha_enabled"`
|
||||
FolderID int `json:"folder_id"`
|
||||
SystemFlags string `json:"system_flags"`
|
||||
UsedByDesktop bool `json:"used_by_desktop"`
|
||||
Location string `json:"location"`
|
||||
GuestOsVersion string `json:"guest_os_version"`
|
||||
MaxRAMSize int `json:"max_ram_size"`
|
||||
ExternalUUID string `json:"external_uuid"`
|
||||
Domain string `json:"domain"`
|
||||
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
|
||||
VirtType string `json:"virt_type"`
|
||||
Created time.Time `json:"created"`
|
||||
CPUUnits int `json:"cpu_units"`
|
||||
Ratebound bool `json:"ratebound"`
|
||||
InstallOs bool `json:"install_os"`
|
||||
MonitoringEnabled bool `json:"monitoring_enabled"`
|
||||
RAMSize int `json:"ram_size"`
|
||||
Maxmemory int `json:"maxmemory"`
|
||||
Name string `json:"name"`
|
||||
GuestOs string `json:"guest_os"`
|
||||
CPUSockets int `json:"cpu_sockets"`
|
||||
AutoStartDelay int `json:"auto_start_delay"`
|
||||
CoresCount int `json:"cores_count"`
|
||||
GuestToolsState string `json:"guest_tools_state"`
|
||||
Deleted time.Time `json:"deleted"`
|
||||
ResourcePoolID int `json:"resource_pool_id"`
|
||||
SmbiosUUID string `json:"smbios_uuid"`
|
||||
CPUMask string `json:"cpu_mask"`
|
||||
CPUCount int `json:"cpu_count"`
|
||||
MacAddresses any `json:"mac_addresses"`
|
||||
IsLinkedClone bool `json:"is_linked_clone"`
|
||||
BootDeviceList []BootDevice `json:"boot_device_list"`
|
||||
IopsLimit int `json:"iops_limit"`
|
||||
VncHostname string `json:"vnc_hostname"`
|
||||
Imported bool `json:"imported"`
|
||||
ExternalStorageName string `json:"external_storage_name"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
CPUHotplug bool `json:"cpu_hotplug"`
|
||||
MemGuaranteeSize int `json:"mem_guarantee_size"`
|
||||
LinkedVMID int `json:"linked_vm_id"`
|
||||
ParentUUID string `json:"parent_uuid"`
|
||||
IsVzTemplate bool `json:"is_vz_template"`
|
||||
IoLimit int `json:"io_limit"`
|
||||
Chipset string `json:"chipset"`
|
||||
VncMode string `json:"vnc_mode"`
|
||||
DisableAutobalance bool `json:"disable_autobalance"`
|
||||
ExternalStorageID int `json:"external_storage_id"`
|
||||
ClusterID int `json:"cluster_id"`
|
||||
HaPriority int `json:"ha_priority"`
|
||||
VMID int `json:"vm_id"`
|
||||
ClockOffset string `json:"clock_offset"`
|
||||
Lock bool `json:"lock"`
|
||||
RAMBalloonActualHotplug bool `json:"ram_balloon_actual_hotplug"`
|
||||
VncPassword string `json:"vnc_password"`
|
||||
ExternalResourceName string `json:"external_resource_name"`
|
||||
RAMTotalHotplug string `json:"ram_total_hotplug"`
|
||||
SecureBoot bool `json:"secure_boot"`
|
||||
ExternalResourceID int `json:"external_resource_id"`
|
||||
Affinity string `json:"affinity"`
|
||||
IsTemplate bool `json:"is_template"`
|
||||
NodeID int `json:"node_id"`
|
||||
VncPort int `json:"vnc_port"`
|
||||
LinkedVMUUID string `json:"linked_vm_uuid"`
|
||||
VideoRAMSize int `json:"video_ram_size"`
|
||||
AutoStop string `json:"auto_stop"`
|
||||
TpmEnabled bool `json:"tpm_enabled"`
|
||||
UUID string `json:"uuid"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
Hostname string `json:"hostname"`
|
||||
EfiEnabled bool `json:"efi_enabled"`
|
||||
AutoStart string `json:"auto_start"`
|
||||
LinkedCloneCount int `json:"linked_clone_count"`
|
||||
SnapshotCount int `json:"snapshot_count"`
|
||||
HostDeviceCount int `json:"host_device_count"`
|
||||
Node Node `json:"node"`
|
||||
AllMd5 bool `json:"all_md5"`
|
||||
DisksSize int `json:"disks_size"`
|
||||
TemplateSize float64 `json:"template_size"`
|
||||
FullHardDriveSize int `json:"full_hard_drive_size"`
|
||||
UsedHardDriveSize float64 `json:"used_hard_drive_size"`
|
||||
}
|
||||
|
||||
// BootDevice represents the boot device information.
|
||||
type BootDevice struct {
|
||||
Type string `json:"type"`
|
||||
InUse bool `json:"in_use"`
|
||||
Index int `json:"index"`
|
||||
}
|
||||
|
||||
// Node represents the node information.
|
||||
type Node struct {
|
||||
Name string `json:"name"`
|
||||
NodeID int `json:"node_id"`
|
||||
}
|
||||
12
pkg/template/requests/request_get.go
Normal file
12
pkg/template/requests/request_get.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package requests
|
||||
|
||||
// GetTemplateRequest struct to get details of a template.
|
||||
type GetTemplateRequest struct {
|
||||
// Id of source template
|
||||
// Required: true
|
||||
TemplateID int `url:"template" json:"template" validate:"required"`
|
||||
|
||||
// If true, include VM's hierarchy information.
|
||||
// Required: false
|
||||
WithParentTree bool `url:"with_parent_tree,omitempty" json:"with_parent_tree,omitempty"`
|
||||
}
|
||||
134
pkg/template/requests/request_list.go
Normal file
134
pkg/template/requests/request_list.go
Normal file
@@ -0,0 +1,134 @@
|
||||
package requests
|
||||
|
||||
import "time"
|
||||
|
||||
// ListTemplateRequest struct to get list of templates
|
||||
type ListTemplateRequest struct {
|
||||
// Find by partial name match. Ignored if NameExact is provided.
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Find by virtualization type. Possible values: "VM", "CT".
|
||||
// Required: false
|
||||
VirtType string `url:"virt_type,omitempty" json:"virt_type,omitempty" validate:"omitempty,virt_type"`
|
||||
|
||||
// Find by node identifier,.
|
||||
// Required: false
|
||||
Node int `url:"node,omitempty" json:"node,omitempty"`
|
||||
|
||||
// Filter templates by description.
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Filter by OS installation.
|
||||
// Required: false
|
||||
InstallOS interface{} `url:"install_os,omitempty" json:"install_os,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Filter templates by CPU count.
|
||||
// Required: false
|
||||
CPUCount int `url:"cpu_count,omitempty" json:"cpu_count,omitempty"`
|
||||
|
||||
// Filter templates by external resource ID.
|
||||
// Required: false
|
||||
ExternalResourceID int `url:"external_resource_id,omitempty" json:"external_resource_id,omitempty"`
|
||||
|
||||
// Include external resource pools for filtering.
|
||||
// Required: false
|
||||
IncludeExternal bool `url:"include_external,omitempty" json:"include_external,omitempty"`
|
||||
|
||||
// Filter templates by CPU units (2-262144).
|
||||
// Required: false
|
||||
CPUUnits int `url:"cpu_units,omitempty" json:"cpu_units,omitempty" validate:"omitempty,cpu_units"`
|
||||
|
||||
// Filter templates by CPU limit (0-100) * number of cores on server.
|
||||
// Required: false
|
||||
CPULimit int `url:"cpu_limit,omitempty" json:"cpu_limit,omitempty" validate:"omitempty,cpu_limit"`
|
||||
|
||||
// Filter templates by RAM size in Megabytes.
|
||||
// Required: false
|
||||
RAMSize int `url:"ram_size,omitempty" json:"ram_size,omitempty"`
|
||||
|
||||
// Filter templates by video RAM size in Megabytes.
|
||||
// Required: false
|
||||
VideoRAMSize int `url:"video_ram_size,omitempty" json:"video_ram_size,omitempty"`
|
||||
|
||||
// Filter templates by Guest OS.
|
||||
// Required: false
|
||||
GuestOS string `url:"guest_os,omitempty" json:"guest_os,omitempty" validate:"omitempty,guest_os"`
|
||||
|
||||
// Filter templates by Guest OS version.
|
||||
// Required: false
|
||||
GuestOSVersion string `url:"guest_os_version,omitempty" json:"guest_os_version,omitempty" validate:"omitempty,guest_os_version"`
|
||||
|
||||
// Filter templates by location.
|
||||
// Required: false
|
||||
Location string `url:"location,omitempty" json:"location,omitempty"`
|
||||
|
||||
// Filter templates by lock status.
|
||||
// Required: false
|
||||
Lock interface{} `url:"lock,omitempty" json:"lock,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Filter templates by status.
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty" validate:"omitempty,template_status"`
|
||||
|
||||
// Filter templates by EFI usage.
|
||||
// Required: false
|
||||
EFIEnabled interface{} `url:"efi_enabled,omitempty" json:"efi_enabled,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Filter templates by RAM hotplug enabled.
|
||||
// Required: false
|
||||
RamHotplugEnabled interface{} `url:"ram_hotplug_enabled,omitempty" json:"ram_hotplug_enabled,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Set memory guarantee size as a percentage of VM RAM.
|
||||
// Required: false
|
||||
MemGuaranteeSize int `url:"mem_guarantee_size,omitempty" json:"mem_guarantee_size,omitempty" validate:"omitempty,mem_guarantee_size"`
|
||||
|
||||
// Filter templates by parent UUID.
|
||||
// Required: false
|
||||
ParentUUID string `url:"parent_uuid,omitempty" json:"parent_uuid,omitempty"`
|
||||
|
||||
// Filter to search in all text fields.
|
||||
// Required: false
|
||||
FilterText string `url:"filter_text,omitempty" json:"filter_text,omitempty"`
|
||||
|
||||
// List columns which will be used by FilterText.
|
||||
// Required: false
|
||||
FilterColumns string `url:"filter_columns,omitempty" json:"filter_columns,omitempty"`
|
||||
|
||||
// Filter templates deleted before this date.
|
||||
// Required: false
|
||||
DeletedBefore time.Time `url:"deleted_before,omitempty" json:"deleted_before,omitempty"`
|
||||
|
||||
// Filter templates deleted after this date.
|
||||
// Required: false
|
||||
DeletedAfter time.Time `url:"deleted_after,omitempty" json:"deleted_after,omitempty"`
|
||||
|
||||
// Filter templates created before this date.
|
||||
// Required: false
|
||||
CreatedBefore time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
|
||||
|
||||
// Filter templates created after this date.
|
||||
// Required: false
|
||||
CreatedAfter time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
|
||||
|
||||
// Filter VM templates that are unavailable now, because share is unavailable
|
||||
// Required: false
|
||||
HideUnavailable interface{} `url:"hide_unavailable,omitempty" json:"hide_unavailable,omitempty" validate:"omitempty,is_bool"`
|
||||
|
||||
// Number of returning page.
|
||||
// Required: false
|
||||
Page int `url:"page,omitempty" json:"page,omitempty"`
|
||||
|
||||
// Number of items on page.
|
||||
// Required: false
|
||||
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
|
||||
|
||||
// Column sorting, format +|-(field).
|
||||
// Required: false
|
||||
Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
|
||||
|
||||
// Filter template by visibility. Possible values: "visible", "deleted", "all".
|
||||
// Required: false
|
||||
Visibility string `url:"visibility,omitempty" json:"visibility,omitempty" validate:"omitempty,visibility"`
|
||||
}
|
||||
17
pkg/template/template.go
Normal file
17
pkg/template/template.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to template
|
||||
type Template struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for vms endpoints
|
||||
func New(client interfaces.Caller) *Template {
|
||||
return &Template{
|
||||
client,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user