This commit is contained in:
asteam
2024-10-01 11:15:36 +03:00
commit a25a3c2e5c
81 changed files with 5143 additions and 0 deletions

25
pkg/vm/common/power.go Normal file
View File

@@ -0,0 +1,25 @@
package common
// PowerVMRequest struct to power on or off a virtual machine.
type PowerVMRequest struct {
// Id of source VM
// Required: true
VmID int `url:"vm" json:"vm" validate:"required"`
// Command to power on or off the virtual machine.
// Required: true
Command string `url:"command" json:"command" validate:"required"`
// If true, attempt a graceful operation of the virtual machine.
// Required: false
Graceful bool `url:"graceful" json:"graceful,omitempty"`
// If true, force the operation of the virtual machine.
// Required: false
Force bool `url:"force" json:"force,omitempty"`
}
const (
PowerOn = "vm_start"
PowerOff = "vm_stop"
)

84
pkg/vm/create.go Normal file
View File

@@ -0,0 +1,84 @@
package vm
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/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
type wrapperCreateVMRequest struct {
requests.CreateVMRequest
BootDevices []string `url:"boot_device,omitempty"`
Device []string `url:"device,omitempty"`
}
// Create new VM
func (vm VM) Create(ctx context.Context, req requests.CreateVMRequest) (*models.CreateVMResponse, error) {
if len(req.Names) == 0 {
req.Names = []string{req.Name}
}
res, err := vm.CreateRaw(ctx, req)
if err != nil {
return nil, err
}
item := models.CreateVMResponse{}
err = json.Unmarshal(res, &item)
if err != nil {
return nil, err
}
return &item, nil
}
// CreateRaw return information about created VMas an array of bytes
func (vm VM) CreateRaw(ctx context.Context, req requests.CreateVMRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
var bootDevices []string
if req.BootDeviceList != nil && len(req.BootDeviceList) != 0 {
bootDevices = make([]string, 0, len(req.BootDeviceList))
for i := range req.BootDeviceList {
d, err := json.Marshal(req.BootDeviceList[i])
if err != nil {
return nil, err
}
bootDevices = append(bootDevices, string(d))
}
}
var devices []string
if req.Devices != nil && len(req.Devices) != 0 {
devices = make([]string, 0, len(req.Devices))
for i := range req.Devices {
d, err := json.Marshal(req.Devices[i])
if err != nil {
return nil, err
}
devices = append(devices, string(d))
}
}
reqWrapped := wrapperCreateVMRequest{
CreateVMRequest: req,
BootDevices: bootDevices,
Device: devices,
}
url := constants.APIv0 + "/vms"
res, err := vm.client.ApiCall(ctx, http.MethodPost, url, reqWrapped)
return res, err
}

43
pkg/vm/get.go Normal file
View File

@@ -0,0 +1,43 @@
package vm
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/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// Get return information about specified VM
func (vm VM) Get(ctx context.Context, req requests.GetVMRequest) (*models.RecordVMResponse, error) {
res, err := vm.GetRaw(ctx, req)
if err != nil {
return nil, err
}
item := models.RecordVMResponse{}
err = json.Unmarshal(res, &item)
if err != nil {
return nil, err
}
return &item, nil
}
// GetRaw return information about specified VMas an array of bytes
func (vm VM) GetRaw(ctx context.Context, req requests.GetVMRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req.VmID)
res, err := vm.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}

43
pkg/vm/get_disks.go Normal file
View File

@@ -0,0 +1,43 @@
package vm
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/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// GetDisks return information about disks of the specified VM
func (vm VM) GetDisks(ctx context.Context, req requests.GetDisksRequest) (*models.ListDiskResponse, error) {
res, err := vm.GetDisksRaw(ctx, req)
if err != nil {
return nil, err
}
list := models.ListDiskResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// GetDisksRaw return information about disks of the specified VM an array of bytes
func (vm VM) GetDisksRaw(ctx context.Context, req requests.GetDisksRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req.VmID) + "/device/hard_disk"
res, err := vm.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}

45
pkg/vm/list.go Normal file
View File

@@ -0,0 +1,45 @@
package vm
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/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// List gets a list of all vms the user has access to a ListAccounts struct
func (vm VM) List(ctx context.Context, req requests.ListVMRequest) (*models.ListVMResponse, error) {
res, err := vm.ListRaw(ctx, req)
if err != nil {
return nil, err
}
if req.FolderSubtree == nil {
req.FolderSubtree = true
}
list := models.ListVMResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets a list of all vms the user has access to as an array of bytes
func (vm VM) ListRaw(ctx context.Context, req requests.ListVMRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm"
res, err := vm.client.ApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,32 @@
package models
import "time"
type CreateVMResponse struct {
Task CreateTask `json:"task"`
VMIds []int `json:"vm_ids"`
RequestID string `json:"request_id"`
}
type CreateTask struct {
Error string `json:"error"`
Snapshot string `json:"snapshot"`
ParentID int `json:"parent_id"`
Status string `json:"status"`
Created time.Time `json:"created"`
Progress string `json:"progress"`
Command string `json:"command"`
Finished time.Time `json:"finished"`
Type string `json:"type"`
TimeoutAt time.Time `json:"timeout_at"`
InitiatorID int `json:"initiator_id"`
RequestID string `json:"request_id"`
Started time.Time `json:"started"`
VMID int `json:"vm_id"`
NodeID int `json:"node_id"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}

176
pkg/vm/models/model_get.go Normal file
View File

@@ -0,0 +1,176 @@
package models
import (
"encoding/json"
"time"
)
// RecordVMResponse represents the virtual machine information.
type RecordVMResponse struct {
VMInfo RecordVM `json:"vm_info"`
RequestID string `json:"request_id"`
}
// RecordVM represents the detailed virtual machine information.
type RecordVM struct {
Domain string `json:"domain"`
Status string `json:"status"`
VMID int `json:"vm_id"`
SystemFlags string `json:"system_flags"`
IopsLimit int `json:"iops_limit"`
IsInfrastructure bool `json:"is_infrastructure"`
TpmEnabled bool `json:"tpm_enabled"`
SecureBoot bool `json:"secure_boot"`
Created time.Time `json:"created"`
ResourcePoolID int `json:"resource_pool_id"`
ExternalStorageID int `json:"external_storage_id"`
AutoStartDelay int `json:"auto_start_delay"`
GuestOsVersion string `json:"guest_os_version"`
RAMSize int `json:"ram_size"`
IsTemplate bool `json:"is_template"`
Description string `json:"description"`
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
AutoStart string `json:"auto_start"`
MemGuaranteeSize int `json:"mem_guarantee_size"`
RAMTotalHotplug int `json:"ram_total_hotplug"`
Maxmemory int `json:"maxmemory"`
HaPriority int `json:"ha_priority"`
IoPriority int `json:"io_priority"`
CPUSockets int `json:"cpu_sockets"`
NodeMask string `json:"node_mask"`
MaxRAMSize int `json:"max_ram_size"`
Name string `json:"name"`
CPUMask string `json:"cpu_mask"`
NodeID int `json:"node_id"`
BootDeviceList []BootDevice `json:"boot_device_list"`
DisableAutobalance bool `json:"disable_autobalance"`
CPUUnits int `json:"cpu_units"`
SmbiosUUID string `json:"smbios_uuid"`
InstallOs bool `json:"install_os"`
UsedByDesktop bool `json:"used_by_desktop"`
CPUCount int `json:"cpu_count"`
VirtType string `json:"virt_type"`
VncPassword string `json:"vnc_password"`
VncHostname string `json:"vnc_hostname"`
Ratebound bool `json:"ratebound"`
EfiEnabled bool `json:"efi_enabled"`
Affinity string `json:"affinity"`
GuestOs string `json:"guest_os"`
CPUHotplug bool `json:"cpu_hotplug"`
Imported bool `json:"imported"`
ExternalResourceName string `json:"external_resource_name"`
CoresCount int `json:"cores_count"`
AutoStop string `json:"auto_stop"`
Hostname string `json:"hostname"`
VideoRAMSize int `json:"video_ram_size"`
HaStatus string `json:"ha_status"`
MacAddresses []string `json:"mac_addresses"`
ClusterID int `json:"cluster_id"`
ParentUUID string `json:"parent_uuid"`
ClockOffset string `json:"clock_offset"`
IsLinkedClone bool `json:"is_linked_clone"`
GuestToolsState string `json:"guest_tools_state"`
VncMode string `json:"vnc_mode"`
ExternalUUID string `json:"external_uuid"`
Deleted time.Time `json:"deleted"`
LinkedVMUUID string `json:"linked_vm_uuid"`
RAMBalloonActualHotplug int `json:"ram_balloon_actual_hotplug"`
IPAddress string `json:"ip_address"`
Rates any `json:"rates"` //I don't now type
UUID string `json:"uuid"`
CPULimit int `json:"cpu_limit"`
Location string `json:"location"`
CreationDate time.Time `json:"creation_date"`
VncPort int `json:"vnc_port"`
MonitoringEnabled bool `json:"monitoring_enabled"`
ExternalStorageName string `json:"external_storage_name"`
HaEnabled bool `json:"ha_enabled"`
IoLimit int `json:"io_limit"`
ExternalResourceID int `json:"external_resource_id"`
FolderID int `json:"folder_id"`
Lock bool `json:"lock"`
IsVzTemplate bool `json:"is_vz_template"`
Chipset string `json:"chipset"`
LinkedVMID int `json:"linked_vm_id"`
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"`
EditableParams EditableParams `json:"editable_params"`
Metrics interface{} `json:"metrics"` //Metrics
ParentTree []ParentTree `json:"parent_tree"`
}
// 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"`
}
// EditableParams represents the editable parameters.
type EditableParams struct {
OnTheFly []string `json:"on_the_fly"`
NeedRestart []string `json:"need_restart"`
}
// Metrics represents the metrics parameters.
type Metrics struct {
CombinedPartitionTotalMb float64 `json:"combined_partition_total_mb"`
MemoryTotalMb float64 `json:"memory_total_mb"`
DiskIoReadPs float64 `json:"disk_io_read_ps"`
CPUUsagePercent float64 `json:"cpu_usage_percent"`
CombinedPartitionFreeMb float64 `json:"combined_partition_free_mb"`
TrafficInMb float64 `json:"traffic_in_mb"`
TrafficOutMb float64 `json:"traffic_out_mb"`
MemoryFreeMb float64 `json:"memory_free_mb"`
CombinedPartitionUsageMb float64 `json:"combined_partition_usage_mb"`
Modified time.Time `json:"modified"`
UptimeSec float64 `json:"uptime_sec"`
CombinedPartitionUsagePercent float64 `json:"combined_partition_usage_percent"`
DiskIoWritePs float64 `json:"disk_io_write_ps"`
MemoryUsagePercent float64 `json:"memory_usage_percent"`
}
// 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"`
}
func (vm *RecordVM) UnmarshalJSON(data []byte) error {
type Alias RecordVM
temp := &struct {
Metrics json.RawMessage `json:"metrics,omitempty"`
*Alias
}{
Alias: (*Alias)(vm),
}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
if len(temp.Metrics) > 0 {
var metrics Metrics
if err := json.Unmarshal(temp.Metrics, &metrics); err != nil {
return err
}
vm.Metrics = metrics
} else {
vm.Metrics = nil
}
return nil
}

View File

@@ -0,0 +1,48 @@
package models
import "time"
// ListDiskResponse represents the hard disks information.
type ListDiskResponse struct {
List DeviceList `json:"device_list"`
RequestID string `json:"request_id"`
}
type DeviceList struct {
Total int `json:"total"`
Page int `json:"page"`
PerPage int `json:"per_page"`
IsApproximateTotal bool `json:"is_approximate_total"`
Items []DiskItem `json:"items"`
HasMore bool `json:"has_more"`
}
type DiskItem struct {
Enabled bool `json:"enabled"`
Status string `json:"status"`
Modified time.Time `json:"modified"`
Created time.Time `json:"created"`
Name string `json:"name"`
StackIndex int `json:"stack_index"`
DiskType string `json:"disk_type"`
ImageID int `json:"image_id"`
Deleted time.Time `json:"deleted"`
ExternalStorageID int `json:"external_storage_id"`
ImagePath string `json:"image_path"`
DeviceID int `json:"device_id"`
IsSharedDisk bool `json:"is_shared_disk"`
ExternalUUID string `json:"external_uuid"`
TierID int `json:"tier_id"`
DeviceIndex int `json:"device_index"`
VolumeID int `json:"volume_id"`
Connected bool `json:"connected"`
DeviceType string `json:"device_type"`
ExternalResourceID int `json:"external_resource_id"`
VMID int `json:"vm_id"`
EmulationType string `json:"emulation_type"`
Size int `json:"size"`
UUID string `json:"uuid"`
InterfaceType string `json:"interface_type"`
EditableParams []string `json:"editable_params"`
DiskCaches []interface{} `json:"disk_caches"`
}

107
pkg/vm/models/model_list.go Normal file
View File

@@ -0,0 +1,107 @@
package models
import "time"
// ListVMResponse represents the entire JSON response
type ListVMResponse struct {
VMList ListVM `json:"vm_list"`
RequestID string `json:"request_id"`
}
// ListVM represents a list of virtual machines.
type ListVM struct {
Total int `json:"total"`
Page int `json:"page"`
PerPage int `json:"per_page"`
IsApproximateTotal bool `json:"is_approximate_total"`
Items []ItemVM `json:"items"`
HasMore bool `json:"has_more"`
}
// ItemVM represents a single virtual machine.
type ItemVM struct {
Domain string `json:"domain"`
Status string `json:"status"`
VMID int `json:"vm_id"`
SystemFlags string `json:"system_flags"`
IopsLimit int `json:"iops_limit"`
IsInfrastructure bool `json:"is_infrastructure"`
TpmEnabled bool `json:"tpm_enabled"`
SecureBoot bool `json:"secure_boot"`
Created time.Time `json:"created"`
ResourcePoolID int `json:"resource_pool_id"`
ExternalStorageID int `json:"external_storage_id"`
AutoStartDelay int `json:"auto_start_delay"`
GuestOsVersion string `json:"guest_os_version"`
RAMSize int `json:"ram_size"`
IsTemplate bool `json:"is_template"`
Description string `json:"description"`
RAMHotplugEnabled bool `json:"ram_hotplug_enabled"`
AutoStart string `json:"auto_start"`
MemGuaranteeSize int `json:"mem_guarantee_size"`
RAMTotalHotplug int `json:"ram_total_hotplug"`
Maxmemory int `json:"maxmemory"`
HaPriority int `json:"ha_priority"`
IoPriority int `json:"io_priority"`
CPUSockets int `json:"cpu_sockets"`
NodeMask string `json:"node_mask"`
MaxRAMSize int `json:"max_ram_size"`
Name string `json:"name"`
CPUMask string `json:"cpu_mask"`
NodeID int `json:"node_id"`
BootDeviceList []BootDevice `json:"boot_device_list"`
DisableAutobalance bool `json:"disable_autobalance"`
CPUUnits int `json:"cpu_units"`
SmbiosUUID string `json:"smbios_uuid"`
InstallOs bool `json:"install_os"`
UsedByDesktop bool `json:"used_by_desktop"`
CPUCount int `json:"cpu_count"`
VirtType string `json:"virt_type"`
VncPassword string `json:"vnc_password"`
VncHostname string `json:"vnc_hostname"`
Ratebound bool `json:"ratebound"`
EfiEnabled bool `json:"efi_enabled"`
Affinity string `json:"affinity"`
GuestOs string `json:"guest_os"`
CPUHotplug bool `json:"cpu_hotplug"`
Imported bool `json:"imported"`
ExternalResourceName string `json:"external_resource_name"`
CoresCount int `json:"cores_count"`
AutoStop string `json:"auto_stop"`
Hostname string `json:"hostname"`
VideoRAMSize int `json:"video_ram_size"`
HaStatus string `json:"ha_status"`
MacAddresses []string `json:"mac_addresses"`
ClusterID int `json:"cluster_id"`
ParentUUID string `json:"parent_uuid"`
ClockOffset string `json:"clock_offset"`
IsLinkedClone bool `json:"is_linked_clone"`
GuestToolsState string `json:"guest_tools_state"`
VncMode string `json:"vnc_mode"`
ExternalUUID string `json:"external_uuid"`
Deleted time.Time `json:"deleted"`
LinkedVMUUID string `json:"linked_vm_uuid"`
RAMBalloonActualHotplug int `json:"ram_balloon_actual_hotplug"`
IPAddress string `json:"ip_address"`
Rates any `json:"rates"` //I don't now type
UUID string `json:"uuid"`
CPULimit int `json:"cpu_limit"`
Location string `json:"location"`
CreationDate time.Time `json:"creation_date"`
VncPort int `json:"vnc_port"`
MonitoringEnabled bool `json:"monitoring_enabled"`
ExternalStorageName string `json:"external_storage_name"`
HaEnabled bool `json:"ha_enabled"`
IoLimit int `json:"io_limit"`
ExternalResourceID int `json:"external_resource_id"`
FolderID int `json:"folder_id"`
Lock bool `json:"lock"`
IsVzTemplate bool `json:"is_vz_template"`
Chipset string `json:"chipset"`
LinkedVMID int `json:"linked_vm_id"`
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"`
}

View File

@@ -0,0 +1,110 @@
package models
import "time"
// DisableInfoResponse represents the response containing disable information for a VM operation.
type DisableInfoResponse struct {
DisableInfo DisableInfo `json:"task_info"`
RequestID string `json:"request_id"`
}
// DisableInfo represents the detailed task information for a VM operation.
type DisableInfo struct {
Progress int `json:"progress"`
RequestID string `json:"request_id"`
Finished time.Time `json:"finished"`
ParentID int `json:"parent_id"`
NodeID int `json:"node_id"`
Error string `json:"error"`
VMID int `json:"vm_id"`
NewVMStatus string `json:"new_vm_status"`
CurrentVMStatus string `json:"current_vm_status"`
Snapshot string `json:"snapshot"`
InitiatorID int `json:"initiator_id"`
Type string `json:"type"`
Started time.Time `json:"started"`
TimeoutAt time.Time `json:"timeout_at"`
NewNodeID int `json:"new_node_id"`
Status string `json:"status"`
Command string `json:"command"`
Created time.Time `json:"created"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}
// Initiator represents the initiator of the task.
type Initiator struct {
Name string `json:"name"`
UserID int `json:"user_id"`
Email string `json:"email"`
Login string `json:"login"`
}
// TaskNode represents the node information.
type TaskNode struct {
ServerUUID string `json:"server_uuid"`
SDKStatus string `json:"sdk_status"`
NodeID int `json:"node_id"`
Status string `json:"status"`
Compute bool `json:"compute"`
Name string `json:"name"`
VStorageClusterID int `json:"vstorage_cluster_id"`
VStorageStatus string `json:"vstorage_status"`
MaintenanceStatus string `json:"maintenance_status"`
StorageStatus string `json:"storage_status"`
ClusterID int `json:"cluster_id"`
IPAddress string `json:"ip_address"`
Deleted time.Time `json:"deleted"`
Modified time.Time `json:"modified"`
VStorageHostID int `json:"vstorage_host_id"`
Description string `json:"description"`
Created time.Time `json:"created"`
}
// Cluster represents the cluster information.
type Cluster struct {
CPUOvercommit float64 `json:"cpu_overcommit"`
FenixPingIP string `json:"fenix_ping_ip"`
Created time.Time `json:"created"`
FenixClusterStatus string `json:"fenix_cluster_status"`
StorageName string `json:"storage_name"`
FenixBalancingStrategy string `json:"fenix_balancing_strategy"`
FenixEnabled bool `json:"fenix_enabled"`
Name string `json:"name"`
VStorageClusterID int `json:"vstorage_cluster_id"`
FenixClusterID int `json:"fenix_cluster_id"`
FenixBroadcastIP string `json:"fenix_broadcast_ip"`
DRSMode string `json:"drs_mode"`
MemoryOvercommit float64 `json:"memory_overcommit"`
ClusterID int `json:"cluster_id"`
StorageType string `json:"storage_type"`
Deleted time.Time `json:"deleted"`
Modified time.Time `json:"modified"`
NodeCount int `json:"node_count"`
VMTotalRAM int `json:"vm_total_ram"`
VMCount int `json:"vm_count"`
}
// VM represents the virtual machine information.
type VM struct {
VMID int `json:"vm_id"`
Name string `json:"name"`
UUID string `json:"uuid"`
IPAddress string `json:"ip_address"`
Status string `json:"status"`
LinkedCloneCount int `json:"linked_clone_count"`
SnapshotCount int `json:"snapshot_count"`
HostDeviceCount int `json:"host_device_count"`
Node NodeRef `json:"node"`
SMBIOSUUID string `json:"smbios_uuid"`
AllMD5 bool `json:"all_md5"`
}
// NodeRef represents a reference to a node, used within VM information.
type NodeRef struct {
NodeID int `json:"node_id"`
Name string `json:"name"`
}

View File

@@ -0,0 +1,36 @@
package models
import "time"
// EnableInfoResponse represents the response containing enable information for a VM operation.
type EnableInfoResponse struct {
EnableInfo EnableInfo `json:"task_info"`
RequestID string `json:"request_id"`
}
// EnableInfo represents the detailed task information for a VM operation.
type EnableInfo struct {
Progress int `json:"progress"`
RequestID string `json:"request_id"`
Finished time.Time `json:"finished"`
ParentID int `json:"parent_id"`
NodeID int `json:"node_id"`
Error string `json:"error"`
VMID int `json:"vm_id"`
NewVMStatus string `json:"new_vm_status"`
CurrentVMStatus string `json:"current_vm_status"`
Snapshot string `json:"snapshot"`
InitiatorID int `json:"initiator_id"`
Type string `json:"type"`
Started time.Time `json:"started"`
TimeoutAt time.Time `json:"timeout_at"`
NewNodeID int `json:"new_node_id"`
Status string `json:"status"`
Command string `json:"command"`
Created time.Time `json:"created"`
HasChildren bool `json:"has_children"`
Initiator Initiator `json:"initiator"`
Node TaskNode `json:"node"`
Cluster Cluster `json:"cluster"`
VM VM `json:"vm"`
}

50
pkg/vm/power_off.go Normal file
View File

@@ -0,0 +1,50 @@
package vm
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/vm/common"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// PowerOff Power off vm
func (vm VM) PowerOff(ctx context.Context, req requests.PowerOffRequest) (*models.DisableInfoResponse, error) {
res, err := vm.PowerOffRaw(ctx, req)
if err != nil {
return nil, err
}
list := models.DisableInfoResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// PowerOffRaw Power off vm with response as an array of bytes
func (vm VM) PowerOffRaw(ctx context.Context, req requests.PowerOffRequest) ([]byte, error) {
realReq := common.PowerVMRequest{
VmID: req.VmID,
Command: common.PowerOff,
Graceful: req.Graceful,
Force: req.Force,
}
if err := validators.ValidateRequest(realReq); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req.VmID) + "/task"
res, err := vm.client.ApiCall(ctx, http.MethodPost, url, realReq)
return res, err
}

48
pkg/vm/power_on.go Normal file
View File

@@ -0,0 +1,48 @@
package vm
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/vm/common"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/models"
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/pkg/vm/requests"
)
// Enable vm
func (vm VM) PowerOn(ctx context.Context, req requests.PowerOnRequest) (*models.EnableInfoResponse, error) {
res, err := vm.PowerOnRaw(ctx, req)
if err != nil {
return nil, err
}
list := models.EnableInfoResponse{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// Enable vm with response as an array of bytes
func (vm VM) PowerOnRaw(ctx context.Context, req requests.PowerOnRequest) ([]byte, error) {
realReq := common.PowerVMRequest{
VmID: req.VmID,
Command: common.PowerOn,
}
if err := validators.ValidateRequest(realReq); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := constants.APIv0 + "/vm/" + fmt.Sprint(req) + "/task"
res, err := vm.client.ApiCall(ctx, http.MethodPost, url, realReq)
return res, err
}

View File

@@ -0,0 +1,404 @@
package requests
import "time"
// CreateVMRequest struct to create a virtual machine.
type CreateVMRequest struct {
// Parent template or VM uuid
// Required: false
ParentUUID string `url:"parent_uuid,omitempty" json:"parent_uuid,omitempty"`
// VM name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// VM description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// VM location on server
// Required: false
Location string `url:"location,omitempty" json:"location,omitempty"`
// Is HA mode enabled on VM
// Required: false
HaEnabled bool `url:"ha_enabled" json:"ha_enabled"`
// Current HA priority of VM
// Required: false
HaPriority int `url:"ha_priority" json:"ha_priority"`
// VM is infrastructure; specify ``True`` to mark VM as infrastructure
// Required: false
IsInfrastructure bool `url:"is_infrastructure" json:"is_infrastructure"`
// Is a monitoring via guest tools enabled on VM
// Required: false
MonitoringEnabled bool `url:"monitoring_enabled" json:"monitoring_enabled"`
// VM CPU units
// Required: false
CPUUnits int `url:"cpu_units,omitempty" json:"cpu_units,omitempty" validate:"omitempty,cpu_units"`
// VM CPU limit
// Required: false
CPULimit int `url:"cpu_limit" json:"cpu_limit"`
// Is CPU hotplug mode enabled
// Required: false
CPUHotplug bool `url:"cpu_hotplug,omitempty" json:"cpu_hotplug,omitempty"`
// CPU sockets
// Required: true
CPUSockets int `url:"cpu_sockets" json:"cpu_sockets" validate:"required"`
// CPU mask for a virtual machine
// Required: false
CPUMask string `url:"cpu_mask,omitempty" json:"cpu_mask,omitempty"`
// NUMA node mask for a virtual machine
// Required: false
NodeMask string `url:"node_mask,omitempty" json:"node_mask,omitempty"`
// Affinity rule type
// Required: false
Affinity string `url:"affinity,omitempty" json:"affinity,omitempty" validate:"omitempty,affinity"`
// Time delay used during the virtual machine automatic startup
// Required: false
AutoStartDelay int `url:"auto_start_delay,omitempty" json:"auto_start_delay,omitempty"`
// RAM size in Megabytes
// Required: true
RAMSize int `url:"ram_size,omitempty" json:"ram_size,omitempty" validate:"required"`
// Required guarantee memory in percent
// Required: false default -1
MemGuaranteeSize int `url:"mem_guarantee_size,omitempty" json:"mem_guarantee_size,omitempty" validate:"omitempty,mem_guarantee_size"`
// Is RAM hotplug enabled
// Required: false
RAMHotplugEnabled bool `url:"ram_hotplug_enabled,omitempty" json:"ram_hotplug_enabled,omitempty"`
// Video RAM size in Megabytes
// Required: true
VideoRAMSize int `url:"video_ram_size,omitempty" json:"video_ram_size,omitempty" validate:"required,video_ram"`
// VM guest OS type
// Required: false //validation
GuestOs string `url:"guest_os,omitempty" json:"guest_os,omitempty" validate:"omitempty,guest_os"`
// Is VM uses EFI instead of BIOS
// Required: false
EfiEnabled bool `url:"efi_enabled" json:"efi_enabled"`
// Enabled TMP
// Required: false
TpmEnabled bool `url:"tpm_enabled" json:"tpm_enabled"`
// is VM uses Secure Boot
// Required: false
SecureBoot bool `url:"secure_boot" json:"secure_boot"`
// VM disk I/O priority level
// Required: false ///0-7
IoPriority int `url:"io_priority,omitempty" json:"io_priority,omitempty" validate:"omitempty,io_priority"`
// Allowed bandwidth for VM disk I/O operations in bytes
// Required: false
IoLimit int `url:"io_limit,omitempty" json:"io_limit,omitempty"`
// IOPS limit for VM disk I/O operations
// Required: false
IopsLimit int `url:"iops_limit,omitempty" json:"iops_limit,omitempty"`
// If True don't move this VM by DRS auto balancing
// Required: false
DisableAutobalance bool `url:"disable_autobalance" json:"disable_autobalance"`
// If ``True``, the bandwidth guarantee (the global rate parameter) is also the limit for the virtual machine or container
// Required: false
Ratebound bool `url:"ratebound" json:"ratebound"`
// Boot devices order list
// Required: false
BootDeviceList []BootDevice `url:"-" json:"boot_device_list,omitempty"`
// VM CPU units
// Required: false
IPAddress any `url:"ip_address,omitempty" json:"ip_address,omitempty"`
// Guest Tools State
// Required: false
GuestToolsState string `url:"guest_tools_state,omitempty" json:"guest_tools_state,omitempty"`
// Should OS be installed after creation
// Required: false
InstallOs bool `url:"install_os,omitempty" json:"install_os,omitempty"`
// VNC server password
// Required: false
VncPassword string `url:"vnc_password,omitempty" json:"vnc_password,omitempty"`
// External storage name
// Required: false
ExternalStorageName string `url:"external_storage_name,omitempty" json:"external_storage_name,omitempty"`
// Linked vm uuid
// Required: false
LinkedVMUUID any `url:"linked_vm_uuid,omitempty" json:"linked_vm_uuid,omitempty"`
// Creation_date
// Required: false
CreationDate time.Time `url:"creation_date,omitempty" json:"creation_date,omitempty"`
// Imported
// Required: false
Imported bool `url:"imported,omitempty" json:"imported,omitempty"`
// Type of virtualization
// Required: false
VirtType string `url:"virt_type,omitempty" json:"virt_type,omitempty" validation:"omitempty,virt_type"`
// Used by dekstop
// Required: false
UsedByDesktop bool `url:"used_by_desktop,omitempty" json:"used_by_desktop,omitempty"`
// VNC server hostname
// Required: false
VncHostname string `url:"vnc_hostname,omitempty" json:"vnc_hostname,omitempty"`
// Ram total hotplug flag
// Required: false
RAMTotalHotplug any `url:"ram_total_hotplug,omitempty" json:"ram_total_hotplug,omitempty"`
// Linked VM ID
// Required: false
LinkedVMID any `url:"linked_vm_id,omitempty" json:"linked_vm_id,omitempty"`
// Ram balloon actual hotplug
// Required: false
RAMBalloonActualHotplug any `url:"ram_balloon_actual_hotplug,omitempty" json:"ram_balloon_actual_hotplug,omitempty"`
// Smbios uuid
// Required: false
SmbiosUUID string `url:"smbios_uuid,omitempty" json:"smbios_uuid,omitempty"`
// Parent template or VM uuid
// Required: false
UUID string `url:"uuid,omitempty" json:"uuid,omitempty"`
// Name of external resource
// Required: false
ExternalResourceName string `url:"external_resource_name,omitempty" json:"external_resource_name,omitempty"`
// HA Status
// Required: false
HaStatus string `url:"ha_status,omitempty" json:"ha_status,omitempty"`
// External uuid
// Required: false
ExternalUUID any `url:"external_uuid,omitempty" json:"external_uuid,omitempty"`
// Time of deleted
// Required: false
Deleted any `url:"deleted,omitempty" json:"deleted,omitempty"`
// VM's System flags
// Required: false
SystemFlags string `url:"system_flags,omitempty" json:"system_flags,omitempty"`
// VM is template; specify ``True`` to create master for linked clone VM
// Required: false
IsVzTemplate bool `url:"is_vz_template,omitempty" json:"is_vz_template,omitempty"`
// VNC port
// Required: false //validate
VncPort int `url:"vnc_port,omitempty" json:"vnc_port,omitempty"`
// status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// vm id
// Required: false
VMID int `url:"vm_id,omitempty" json:"vm_id,omitempty"`
// MaxRamSize
// Required: false
MaxRAMSize int `url:"max_ram_size,omitempty" json:"max_ram_size,omitempty"`
// Cores count
// Required: false
CoresCount int `url:"cores_count,omitempty" json:"cores_count,omitempty"`
// is template
// Required: false
IsTemplate bool `url:"is_template,omitempty" json:"is_template,omitempty"`
// max memory
// Required: false
Maxmemory int `url:"maxmemory,omitempty" json:"maxmemory,omitempty"`
// External resource id
// Required: false
ExternalResourceID any `url:"external_resource_id,omitempty" json:"external_resource_id,omitempty"`
// is linked clone
// Required: false
IsLinkedClone bool `url:"is_linked_clone,omitempty" json:"is_linked_clone,omitempty"`
// created time
// Required: false
Created time.Time `url:"created,omitempty" json:"created,omitempty"`
// list of mac addresses
// Required: false
MacAddresses any `url:"mac_addresses,omitempty" json:"mac_addresses,omitempty"`
// VM guest domain name
// Required: false
Domain string `url:"domain,omitempty" json:"domain,omitempty"`
// Count of linked clones
// Required: false
LinkedCloneCount int `url:"linked_clone_count,omitempty" json:"linked_clone_count,omitempty"`
// Count of snapshot
// Required: false
SnapshotCount int `url:"snapshot_count,omitempty" json:"snapshot_count,omitempty"`
// Count of device host
// Required: false
HostDeviceCount int `url:"host_device_count,omitempty" json:"host_device_count,omitempty"`
// All md5
// Required: false
AllMd5 bool `url:"all_md5,omitempty" json:"all_md5,omitempty"`
// Size of disks
// Required: false
DisksSize int `url:"disks_size,omitempty" json:"disks_size,omitempty"`
// Size of template
// Required: false
TemplateSize float64 `url:"template_size,omitempty" json:"template_size,omitempty"`
// Full hard drive size
// Required: false
FullHardDriveSize int `url:"full_hard_drive_size,omitempty" json:"full_hard_drive_size,omitempty"`
// Used hard drive size
// Required: false
UsedHardDriveSize float64 `url:"used_hard_drive_size,omitempty" json:"used_hard_drive_size,omitempty"`
// Cluster ID
// Required: false
ClusterID int `url:"cluster_id,omitempty" json:"cluster_id,omitempty"`
// External storage ID
// Required: false
ExternalStorageID int `url:"external_storage_id,omitempty" json:"external_storage_id,omitempty"`
// VM guest OS version
// Required: false
GuestOsVersion string `url:"guest_os_version,omitempty" json:"guest_os_version,omitempty" validate:"omitempty,guest_os_version"`
// Virtual machine startup options
// Required: false
AutoStart string `url:"auto_start,omitempty" json:"auto_start,omitempty" validate:"omitempty,auto_start"`
// Automatic shutdown mode
// Required: false
AutoStop string `url:"auto_stop,omitempty" json:"auto_stop,omitempty" validate:"omitempty,auto_stop"`
// VNC server mode
// Required: false
VncMode string `url:"vnc_mode,omitempty" json:"vnc_mode,omitempty" validate:"omitempty,vnc_mode"`
// VM CPU count
// Required: true
CPUCount int `url:"cpu_count,omitempty" json:"cpu_count,omitempty" validate:"required"`
// rates object
// Required: false
Rates struct{} `url:"rates,omitempty" json:"rates,omitempty"`
// List of VM names to create
// Required: false
Names []string `url:"names,omitempty" json:"names,omitempty"`
// List with devices dicts
// Required: false
Devices []Device `json:"devices,omitempty"`
// Host devices
// Required: false
HostDevices []int `url:"host_devices,omitempty" json:"host_devices,omitempty"`
// VM chipset
// Required: false
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
// VM clock offset
// Required: false
ClockOffset string `url:"clock_offset,omitempty" json:"clock_offset,omitempty" validate:"omitempty,clock_offset"`
}
// struct from request JSON no have documentation
type Device struct {
Name any `json:"name,omitempty"`
Modified time.Time `json:"modified,omitempty"`
Status string `json:"status,omitempty"`
EmulationType string `json:"emulation_type,omitempty"`
Enabled bool `json:"enabled,omitempty"`
DeviceType string `json:"device_type,omitempty"`
VolumeID any `json:"volume_id,omitempty"`
IsSharedDisk bool `json:"is_shared_disk,omitempty"`
Size int `json:"size,omitempty"`
VMID int `json:"vm_id,omitempty"`
DeviceIndex int `json:"device_index,omitempty"`
DeviceID int `json:"device_id,omitempty"`
ExternalUUID any `json:"external_uuid,omitempty"`
Deleted any `json:"deleted,omitempty"`
Connected bool `json:"connected,omitempty"`
Created time.Time `json:"created,omitempty"`
ImageID int `json:"image_id,omitempty"`
UUID any `json:"uuid,omitempty"`
ExternalResourceID any `json:"external_resource_id,omitempty"`
ImagePath string `json:"image_path,omitempty"`
EditableParams []string `json:"editable_params,omitempty"`
ImageUUID string `json:"image_uuid,omitempty"`
ImageSource string `json:"image_source,omitempty"`
ImageMd5 string `json:"image_md5,omitempty"`
DiskCaches []any `json:"disk_caches,omitempty"`
ImageName string `json:"image_name,omitempty"`
ImageHashSum string `json:"image_hashSum,omitempty"`
Editing bool `json:"editing,omitempty"`
DiskType string `json:"disk_type,omitempty"`
InterfaceType string `json:"interface_type,omitempty"`
StackIndex int `json:"stack_index,omitempty"`
ExternalStorageID int `json:"external_storage_id,omitempty"`
TierID any `json:"tier_id,omitempty"`
ImageType string `json:"image_type,omitempty"`
IPAddress []any `json:"ip_address,omitempty"`
GuestIPAddress any `json:"guest_ip_address,omitempty"`
DefaultGateway any `json:"default_gateway,omitempty"`
DNSServers []any `json:"dns_servers,omitempty"`
SearchDomains []any `json:"search_domains,omitempty"`
AutoApply bool `json:"auto_apply,omitempty"`
MacAddress any `json:"mac_address,omitempty"`
NetworkName string `json:"network_name,omitempty"`
VirtualNetworkID int `json:"virtual_network_id,omitempty"`
AdapterType string `json:"adapter_type,omitempty"`
PreventIPSpoof bool `json:"prevent_ip_spoof,omitempty"`
PreventMacSpoof bool `json:"prevent_mac_spoof,omitempty"`
PreventPromisc bool `json:"prevent_promisc,omitempty"`
Autoconnect string `json:"autoconnect,omitempty"`
}
type BootDevice struct {
Type string `url:"type" json:"type" validate:"required"`
InUse bool `url:"in_use,omitempty" json:"in_use,omitempty"`
Index int `url:"index,omitempty" json:"index,omitempty"`
}

View File

@@ -0,0 +1,25 @@
package requests
// GetVMRequest struct to get details of a virtual machine.
type GetVMRequest struct {
// Id of source VM
// Required: true
VmID int `url:"vmId" json:"vmId" validate:"required"`
// If true, include VM's current metrics in the metrics field.
// Required: false
WithMetrics bool `url:"with_metrics,omitempty" json:"with_metrics,omitempty"`
// Aggregation period for metrics. Used only if 'WithMetrics' is true.
// Possible values: "latest", "hour", "day", "week".
// Required: false
MetricsPeriod string `url:"metrics_period,omitempty" json:"metrics_period,omitempty" validate:"omitempty,metrics_period"`
// If true, include VM's hierarchy information.
// Required: false
WithParentTree bool `url:"with_parent_tree,omitempty" json:"with_parent_tree,omitempty"`
// If true, request actual info from the agent.
// Required: false
ForceRefresh bool `url:"force_refresh,omitempty" json:"force_refresh,omitempty"`
}

View File

@@ -0,0 +1,8 @@
package requests
// GetDisksRequest struct to get disks of a virtual machine.
type GetDisksRequest struct {
// Id of source VM
// Required: true
VmID int `url:"vmId" json:"vmId" validate:"required"`
}

View File

@@ -0,0 +1,263 @@
package requests
import "time"
// ListVMRequest struct to get list of virtual machines
type ListVMRequest struct {
// Find by partial name match. Ignored if NameExact is provided.
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by exact VM name.
// Required: false
NameExact string `url:"name_exact,omitempty" json:"name_exact,omitempty"`
// Find by UUID.
// Required: false
UUID string `url:"uuid,omitempty" json:"uuid,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
NodeID string `url:"node_id,omitempty" json:"node_id,omitempty"`
// Filter by OS installation.
// Required: false
InstallOS interface{} `url:"install_os,omitempty" json:"install_os,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by name of node.
// Required: false
NodeName string `url:"node_name,omitempty" json:"node_name,omitempty"`
// Filter VMs by description.
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// Filter VMs by IP address.
// Required: false
IPAddress string `url:"ip_address,omitempty" json:"ip_address,omitempty"`
// Filter VMs by MAC address.
// Required: false
MACAddress string `url:"mac_address,omitempty" json:"mac_address,omitempty"`
// Filter VMs by system hostname.
// Required: false
Hostname string `url:"hostname,omitempty" json:"hostname,omitempty"`
// Filter VMs by Windows domain.
// Required: false
Domain string `url:"domain,omitempty" json:"domain,omitempty"`
// Filter VMs by status. Possible values: "RUNNING", "PAUSED", "STOPPED", "SUSPENDED", "ERROR", "DELETED", "CREATING", "FAILED_TO_CREATE", "NODE_OFFLINE".
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty" validate:"omitempty,vm_status"`
// Filter VMs by CPU count.
// Required: false
CPUCount int `url:"cpu_count,omitempty" json:"cpu_count,omitempty"`
// Filter VMs by CPU units (2-262144).
// Required: false
CPUUnits int `url:"cpu_units,omitempty" json:"cpu_units,omitempty" validate:"omitempty,cpu_units"`
// Filter VMs 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"`
// Set CPU hotplug mode for the specified VM.
// Required: false
CPUHotplug interface{} `url:"cpu_hotplug,omitempty" json:"cpu_hotplug,omitempty" validate:"omitempty,is_bool"`
// Set CPU affinity mask for the specified VM.
// Required: false
CPUMask string `url:"cpu_mask,omitempty" json:"cpu_mask,omitempty"`
// Set NUMA node mask for the specified VM.
// Required: false
NodeMask string `url:"node_mask,omitempty" json:"node_mask,omitempty"`
// Filter VMs by CPU sockets.
// Required: false
CPUSockets int `url:"cpu_sockets,omitempty" json:"cpu_sockets,omitempty"`
// Filter VMs by total CPU cores.
// Required: false
CoresCount int `url:"cores_count,omitempty" json:"cores_count,omitempty"`
// Filter VMs by RAM size in Megabytes.
// Required: false
RAMSize int `url:"ram_size,omitempty" json:"ram_size,omitempty"`
// Filter VMs by maximum RAM size in Megabytes.
// Required: false
MaxRAMSize int `url:"max_ram_size,omitempty" json:"max_ram_size,omitempty"`
// Set memory hotplugging mode for the specified VM.
// Required: false
RAMHotplugEnabled bool `url:"ram_hotplug_enabled" json:"ram_hotplug_enabled"`
// 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 VMs by video RAM size in Megabytes.
// Required: false
VideoRAMSize int `url:"video_ram_size,omitempty" json:"video_ram_size,omitempty"`
// Filter VMs by Guest OS version.
// Required: false
GuestOSVersion string `url:"guest_os_version,omitempty" json:"guest_os_version,omitempty"`
// Filter VMs by location.
// Required: false
Location string `url:"location,omitempty" json:"location,omitempty"`
// Filter VMs by EFI usage.
// Required: false
EFIEnabled interface{} `url:"efi_enabled,omitempty" json:"efi_enabled,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by Cluster ID.
// Required: false
ClusterID int `url:"cluster_id,omitempty" json:"cluster_id,omitempty"`
// Filter VMs by folder ID.
// Required: false
FolderID int `url:"folder_id,omitempty" json:"folder_id,omitempty"`
// Filter VMs in all folder subtree.
// Required: false
// Default: true
FolderSubtree interface{} `url:"folder_subtree,omitempty" json:"folder_subtree,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by resource pool ID.
// Required: false
ResourcePoolID int `url:"resource_pool_id,omitempty" json:"resource_pool_id,omitempty"`
// Filter VMs by external resource ID.
// Required: false
ExternalResourceID int `url:"external_resource_id,omitempty" json:"external_resource_id,omitempty"`
// Filter VMs by external storage ID.
// Required: false
ExternalStorageID int `url:"external_storage_id,omitempty" json:"external_storage_id,omitempty"`
// Filter VMs by external storage name.
// Required: false
ExternalStorageName string `url:"external_storage_name,omitempty" json:"external_storage_name,omitempty"`
// Filter VMs by external resource name.
// Required: false
ExternalResourceName string `url:"external_resource_name,omitempty" json:"external_resource_name,omitempty"`
// Include external resource pools for filtering.
// Required: false
IncludeExternal bool `url:"include_external" json:"include_external"`
// Filter VMs by virtual network ID.
// Required: false
VirtualNetworkID int `url:"virtual_network_id,omitempty" json:"virtual_network_id,omitempty"`
// Filter VMs by HA status. Possible values: "ACTIVE", "INACTIVE", "ERROR", "UNKNOWN", "NO LICENSE".
// Required: false
HAStatus string `url:"ha_status,omitempty" json:"ha_status,omitempty" validate:"omitempty,ha_status"`
// Filter VMs by imported status from Virtuozzo.
// Required: false
Imported interface{} `url:"imported,omitempty" json:"imported,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by lock status.
// Required: false
Lock interface{} `url:"lock,omitempty" json:"lock,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by usage in VDI desktops.
// Required: false
UsedByDesktop interface{} `url:"used_by_desktop,omitempty" json:"used_by_desktop,omitempty" validate:"omitempty,is_bool"`
// Filter VMs that are out of any folder.
// Required: false
NoFolder interface{} `url:"no_folder,omitempty" json:"no_folder,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by parent UUID.
// Required: false
ParentUUID string `url:"parent_uuid,omitempty" json:"parent_uuid,omitempty"`
// Filter VMs by linked VM ID.
// Required: false
LinkedVMID int `url:"linked_vm_id,omitempty" json:"linked_vm_id,omitempty"`
// Filter VMs by template flag.
// Required: false
IsVZTemplate interface{} `url:"is_vz_template,omitempty" json:"is_vz_template,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by linked clone status.
// Required: false
IsLinkedClone interface{} `url:"is_linked_clone,omitempty" json:"is_linked_clone,omitempty" validate:"omitempty,is_bool"`
// Filter VMs by infrastructure flag.
// Required: false
IsInfrastructure interface{} `url:"is_infrastructure,omitempty" json:"is_infrastructure,omitempty" validate:"omitempty,is_bool"`
// List of VM IDs to exclude from listing.
// Required: false
ExcludeIDs []int `url:"exclude_ids,omitempty" json:"exclude_ids,omitempty"`
// Filter to search in all text fields.
// Required: false
FilterText string `url:"filter_text,omitempty" json:"filter_text,omitempty"`
// Filter VMs deleted before this date.
// Required: false
DeletedBefore time.Time `url:"deleted_before,omitempty" json:"deleted_before,omitempty"`
// Filter VMs deleted after this date.
// Required: false
DeletedAfter time.Time `url:"deleted_after,omitempty" json:"deleted_after,omitempty"`
// Filter VMs created before this date.
// Required: false
CreatedBefore time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
// Filter VMs created after this date.
// Required: false
CreatedAfter time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
// Filter VMs created in Virtuozzo before this date.
// Required: false
CreationDateBefore time.Time `url:"creation_date_before,omitempty" json:"creation_date_before,omitempty"`
// Filter VMs created in Virtuozzo after this date.
// Required: false
CreationDateAfter time.Time `url:"creation_date_after,omitempty" json:"creation_date_after,omitempty"`
// List columns which will be used by FilterText.
// Required: false
FilterColumns string `url:"filter_columns,omitempty" json:"filter_columns,omitempty"`
// Column sorting, format +|-(field).
// Required: false
Sort []string `url:"sort,omitempty" json:"sort,omitempty"`
// Add disk size info to output.
// Required: false
WithDisksSize bool `url:"with_disks_size,omitempty" json:"with_disks_size,omitempty"`
// Filter VMs by SMBIOS UUID.
// Required: false
SMBIOSUUID string `url:"smbios_uuid,omitempty" json:"smbios_uuid,omitempty"`
// 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"`
// Filter VMs by visibility. Possible values: "visible", "deleted", "all".
// Required: false
Visibility string `url:"visibility,omitempty" json:"visibility,omitempty" validate:"omitempty,visibility"`
}

View File

@@ -0,0 +1,16 @@
package requests
// PowerOffRequest struct to disable VM
type PowerOffRequest struct {
// Id of source VM
// Required: true
VmID int `url:"vm" json:"vm" validate:"required"`
// If true, attempt a graceful operation of the virtual machine.
// Required: false
Graceful bool `url:"graceful" json:"graceful,omitempty"`
// If true, force the operation of the virtual machine.
// Required: false
Force bool `url:"force" json:"force,omitempty"`
}

View File

@@ -0,0 +1,8 @@
package requests
// PowerOnRequest struct to enable VM
type PowerOnRequest struct {
// Id of source VM
// Required: true
VmID int `url:"vm" json:"vm" validate:"required"`
}

17
pkg/vm/vm.go Normal file
View File

@@ -0,0 +1,17 @@
package vm
import (
"repository.basistech.ru/BASIS/dynamix-standart-go-sdk/interfaces"
)
// Structure for creating request to vm
type VM struct {
client interfaces.Caller
}
// Builder for vms endpoints
func New(client interfaces.Caller) *VM {
return &VM{
client,
}
}