@@ -0,0 +1,183 @@
|
||||
package awsserversdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Page[T any] struct {
|
||||
Items []T `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
type ListOptions struct {
|
||||
Query string
|
||||
CategoryID string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
type Region struct {
|
||||
ID string `json:"id"`
|
||||
NameEN string `json:"name_en"`
|
||||
NameZH string `json:"name_zh"`
|
||||
PlacementCount int `json:"placement_count"`
|
||||
Ready bool `json:"ready"`
|
||||
}
|
||||
type Placement struct {
|
||||
ID string `json:"id"`
|
||||
PlacementID string `json:"placement_id"`
|
||||
Name string `json:"name"`
|
||||
Region string `json:"region"`
|
||||
AvailabilityZone string `json:"availability_zone"`
|
||||
CIDR string `json:"cidr"`
|
||||
MapPublicIPOnLaunch bool `json:"map_public_ip_on_launch"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
type Category struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
type Image struct {
|
||||
CatalogID string `json:"catalog_id"`
|
||||
Region string `json:"region"`
|
||||
CategoryID string `json:"category_id"`
|
||||
ImageID string `json:"image_id"`
|
||||
SourceScope string `json:"source_scope"`
|
||||
SourceName string `json:"source_name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
DisplayIntro string `json:"display_intro"`
|
||||
AvailabilityStatus string `json:"availability_status"`
|
||||
Metadata map[string]any `json:"metadata"`
|
||||
}
|
||||
type InstanceType struct {
|
||||
ID string `json:"id"`
|
||||
Region string `json:"region"`
|
||||
CategoryID string `json:"category_id"`
|
||||
InstanceType string `json:"instance_type"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
VCPUs int32 `json:"vcpus"`
|
||||
MemoryMiB int64 `json:"memory_mib"`
|
||||
Architectures []string `json:"architectures"`
|
||||
NetworkPerformance string `json:"network_performance"`
|
||||
GPUCount float64 `json:"gpu_count"`
|
||||
OSPrices map[string]float64 `json:"os_prices"`
|
||||
HourlyRate float64 `json:"hourly_rate"`
|
||||
Currency string `json:"currency"`
|
||||
PriceMode string `json:"price_mode"`
|
||||
PriceValue float64 `json:"price_value"`
|
||||
}
|
||||
type CreateOptions struct {
|
||||
Region string `json:"region"`
|
||||
ImageCategories []Category `json:"image_categories"`
|
||||
Images []Image `json:"images"`
|
||||
InstanceTypeCategories []Category `json:"instance_type_categories"`
|
||||
InstanceTypes []InstanceType `json:"instance_types"`
|
||||
Placements []Placement `json:"placements"`
|
||||
}
|
||||
type VolumeSpec struct {
|
||||
DeviceName string `json:"device_name,omitempty"`
|
||||
SizeGiB int32 `json:"size_gib,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
IOPS int32 `json:"iops,omitempty"`
|
||||
Throughput int32 `json:"throughput,omitempty"`
|
||||
Encrypted bool `json:"encrypted,omitempty"`
|
||||
KMSKeyID string `json:"kms_key_id,omitempty"`
|
||||
DeleteOnTermination *bool `json:"delete_on_termination,omitempty"`
|
||||
}
|
||||
type CreateInstanceRequest struct {
|
||||
PlacementID string `json:"placement_id,omitempty"`
|
||||
ImageID string `json:"image_id"`
|
||||
InstanceType string `json:"instance_type"`
|
||||
Name string `json:"name,omitempty"`
|
||||
SecurityGroupMode string `json:"security_group_mode,omitempty"`
|
||||
IAMInstanceProfileARN string `json:"iam_instance_profile_arn,omitempty"`
|
||||
UserData string `json:"user_data,omitempty"`
|
||||
PrivateIPAddress string `json:"private_ip_address,omitempty"`
|
||||
AssociateEIP bool `json:"associate_eip,omitempty"`
|
||||
Monitoring bool `json:"monitoring,omitempty"`
|
||||
EBSOptimized bool `json:"ebs_optimized,omitempty"`
|
||||
ShutdownBehavior string `json:"shutdown_behavior,omitempty"`
|
||||
RootVolume *VolumeSpec `json:"root_volume,omitempty"`
|
||||
DataVolumes []VolumeSpec `json:"data_volumes,omitempty"`
|
||||
Tags map[string]string `json:"tags,omitempty"`
|
||||
InstallAgent *bool `json:"install_agent,omitempty"`
|
||||
TrafficLimitGiB *float64 `json:"traffic_limit_gib,omitempty"`
|
||||
}
|
||||
type PriceEstimate struct {
|
||||
Currency string `json:"currency"`
|
||||
HourlyPrice float64 `json:"hourly_price"`
|
||||
MonthlyPrice float64 `json:"monthly_price"`
|
||||
CalendarMonthPrice float64 `json:"calendar_month_price"`
|
||||
Breakdown map[string]any `json:"breakdown"`
|
||||
Raw map[string]any `json:"-"`
|
||||
}
|
||||
type Instance struct {
|
||||
ID string `json:"id"`
|
||||
InstanceID string `json:"instance_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Region string `json:"region"`
|
||||
State string `json:"state"`
|
||||
ProvisionStatus string `json:"provision_status"`
|
||||
ImageID string `json:"image_id"`
|
||||
InstanceType string `json:"instance_type"`
|
||||
AvailabilityZone string `json:"availability_zone"`
|
||||
PrivateIPAddress string `json:"private_ip_address"`
|
||||
PublicIPAddress string `json:"public_ip_address"`
|
||||
HourlyRate float64 `json:"hourly_rate"`
|
||||
MonthCost float64 `json:"month_cost"`
|
||||
ProjectedCost float64 `json:"projected_month_cost"`
|
||||
FullMonthCost float64 `json:"full_month_cost"`
|
||||
CostCurrency string `json:"cost_currency"`
|
||||
LastTaskID string `json:"last_task_id"`
|
||||
LastError string `json:"last_error"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
type InstanceDetails map[string]any
|
||||
type Operation struct {
|
||||
client *Client
|
||||
ID string `json:"id"`
|
||||
TaskID string `json:"task_id"`
|
||||
CommandID string `json:"command_id,omitempty"`
|
||||
Status string `json:"status"`
|
||||
PlacementID string `json:"placement_id,omitempty"`
|
||||
}
|
||||
|
||||
func (o *Operation) Wait(ctx context.Context, options ...WaitOption) (*Task, error) {
|
||||
if o == nil || o.client == nil {
|
||||
return nil, errors.New("awsserversdk: invalid operation")
|
||||
}
|
||||
if o.TaskID == "" {
|
||||
if o.Status == "deleted" || o.Status == "succeeded" {
|
||||
return &Task{ID: o.ID, ResourceID: o.ID, Status: "succeeded", Progress: 100}, nil
|
||||
}
|
||||
return nil, errors.New("awsserversdk: operation has no task ID")
|
||||
}
|
||||
return o.client.Tasks.Wait(ctx, o.TaskID, options...)
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
QueueName string `json:"queue_name"`
|
||||
Region string `json:"region"`
|
||||
ResourceID string `json:"resource_id"`
|
||||
Status string `json:"status"`
|
||||
Progress int `json:"progress"`
|
||||
Attempts int `json:"attempts"`
|
||||
State json.RawMessage `json:"state"`
|
||||
Result json.RawMessage `json:"result"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
FinishedAt *time.Time `json:"finished_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user