File size: 13,782 Bytes
daa8246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package ionet

import (
	"time"
)

// Client represents the IO.NET API client
type Client struct {
	BaseURL    string
	APIKey     string
	HTTPClient HTTPClient
}

// HTTPClient interface for making HTTP requests
type HTTPClient interface {
	Do(req *HTTPRequest) (*HTTPResponse, error)
}

// HTTPRequest represents an HTTP request
type HTTPRequest struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    []byte
}

// HTTPResponse represents an HTTP response
type HTTPResponse struct {
	StatusCode int
	Headers    map[string]string
	Body       []byte
}

// DeploymentRequest represents a container deployment request
type DeploymentRequest struct {
	ResourcePrivateName string          `json:"resource_private_name"`
	DurationHours       int             `json:"duration_hours"`
	GPUsPerContainer    int             `json:"gpus_per_container"`
	HardwareID          int             `json:"hardware_id"`
	LocationIDs         []int           `json:"location_ids"`
	ContainerConfig     ContainerConfig `json:"container_config"`
	RegistryConfig      RegistryConfig  `json:"registry_config"`
}

// ContainerConfig represents container configuration
type ContainerConfig struct {
	ReplicaCount       int               `json:"replica_count"`
	EnvVariables       map[string]string `json:"env_variables,omitempty"`
	SecretEnvVariables map[string]string `json:"secret_env_variables,omitempty"`
	Entrypoint         []string          `json:"entrypoint,omitempty"`
	TrafficPort        int               `json:"traffic_port,omitempty"`
	Args               []string          `json:"args,omitempty"`
}

// RegistryConfig represents registry configuration
type RegistryConfig struct {
	ImageURL         string `json:"image_url"`
	RegistryUsername string `json:"registry_username,omitempty"`
	RegistrySecret   string `json:"registry_secret,omitempty"`
}

// DeploymentResponse represents the response from deployment creation
type DeploymentResponse struct {
	DeploymentID string `json:"deployment_id"`
	Status       string `json:"status"`
}

// DeploymentDetail represents detailed deployment information
type DeploymentDetail struct {
	ID                      string                    `json:"id"`
	Status                  string                    `json:"status"`
	CreatedAt               time.Time                 `json:"created_at"`
	StartedAt               *time.Time                `json:"started_at,omitempty"`
	FinishedAt              *time.Time                `json:"finished_at,omitempty"`
	AmountPaid              float64                   `json:"amount_paid"`
	CompletedPercent        float64                   `json:"completed_percent"`
	TotalGPUs               int                       `json:"total_gpus"`
	GPUsPerContainer        int                       `json:"gpus_per_container"`
	TotalContainers         int                       `json:"total_containers"`
	HardwareName            string                    `json:"hardware_name"`
	HardwareID              int                       `json:"hardware_id"`
	Locations               []DeploymentLocation      `json:"locations"`
	BrandName               string                    `json:"brand_name"`
	ComputeMinutesServed    int                       `json:"compute_minutes_served"`
	ComputeMinutesRemaining int                       `json:"compute_minutes_remaining"`
	ContainerConfig         DeploymentContainerConfig `json:"container_config"`
}

// DeploymentLocation represents a location in deployment details
type DeploymentLocation struct {
	ID   int    `json:"id"`
	ISO2 string `json:"iso2"`
	Name string `json:"name"`
}

// DeploymentContainerConfig represents container config in deployment details
type DeploymentContainerConfig struct {
	Entrypoint   []string               `json:"entrypoint"`
	EnvVariables map[string]interface{} `json:"env_variables"`
	TrafficPort  int                    `json:"traffic_port"`
	ImageURL     string                 `json:"image_url"`
}

// Container represents a container within a deployment
type Container struct {
	DeviceID         string           `json:"device_id"`
	ContainerID      string           `json:"container_id"`
	Hardware         string           `json:"hardware"`
	BrandName        string           `json:"brand_name"`
	CreatedAt        time.Time        `json:"created_at"`
	UptimePercent    int              `json:"uptime_percent"`
	GPUsPerContainer int              `json:"gpus_per_container"`
	Status           string           `json:"status"`
	ContainerEvents  []ContainerEvent `json:"container_events"`
	PublicURL        string           `json:"public_url"`
}

// ContainerEvent represents a container event
type ContainerEvent struct {
	Time    time.Time `json:"time"`
	Message string    `json:"message"`
}

// ContainerList represents a list of containers
type ContainerList struct {
	Total   int         `json:"total"`
	Workers []Container `json:"workers"`
}

// Deployment represents a deployment in the list
type Deployment struct {
	ID                      string    `json:"id"`
	Status                  string    `json:"status"`
	Name                    string    `json:"name"`
	CompletedPercent        float64   `json:"completed_percent"`
	HardwareQuantity        int       `json:"hardware_quantity"`
	BrandName               string    `json:"brand_name"`
	HardwareName            string    `json:"hardware_name"`
	Served                  string    `json:"served"`
	Remaining               string    `json:"remaining"`
	ComputeMinutesServed    int       `json:"compute_minutes_served"`
	ComputeMinutesRemaining int       `json:"compute_minutes_remaining"`
	CreatedAt               time.Time `json:"created_at"`
	GPUCount                int       `json:"-"` // Derived from HardwareQuantity
	Replicas                int       `json:"-"` // Derived from HardwareQuantity
}

// DeploymentList represents a list of deployments with pagination
type DeploymentList struct {
	Deployments []Deployment `json:"deployments"`
	Total       int          `json:"total"`
	Statuses    []string     `json:"statuses"`
}

// AvailableReplica represents replica availability for a location
type AvailableReplica struct {
	LocationID     int    `json:"location_id"`
	LocationName   string `json:"location_name"`
	HardwareID     int    `json:"hardware_id"`
	HardwareName   string `json:"hardware_name"`
	AvailableCount int    `json:"available_count"`
	MaxGPUs        int    `json:"max_gpus"`
}

// AvailableReplicasResponse represents the response for available replicas
type AvailableReplicasResponse struct {
	Replicas []AvailableReplica `json:"replicas"`
}

// MaxGPUResponse represents the response for maximum GPUs per container
type MaxGPUResponse struct {
	Hardware []MaxGPUInfo `json:"hardware"`
	Total    int          `json:"total"`
}

// MaxGPUInfo represents max GPU information for a hardware type
type MaxGPUInfo struct {
	MaxGPUsPerContainer int    `json:"max_gpus_per_container"`
	Available           int    `json:"available"`
	HardwareID          int    `json:"hardware_id"`
	HardwareName        string `json:"hardware_name"`
	BrandName           string `json:"brand_name"`
}

// PriceEstimationRequest represents a price estimation request
type PriceEstimationRequest struct {
	LocationIDs      []int  `json:"location_ids"`
	HardwareID       int    `json:"hardware_id"`
	GPUsPerContainer int    `json:"gpus_per_container"`
	DurationHours    int    `json:"duration_hours"`
	ReplicaCount     int    `json:"replica_count"`
	Currency         string `json:"currency"`
	DurationType     string `json:"duration_type"`
	DurationQty      int    `json:"duration_qty"`
	HardwareQty      int    `json:"hardware_qty"`
}

// PriceEstimationResponse represents the price estimation response
type PriceEstimationResponse struct {
	EstimatedCost   float64        `json:"estimated_cost"`
	Currency        string         `json:"currency"`
	PriceBreakdown  PriceBreakdown `json:"price_breakdown"`
	EstimationValid bool           `json:"estimation_valid"`
}

// PriceBreakdown represents detailed cost breakdown
type PriceBreakdown struct {
	ComputeCost float64 `json:"compute_cost"`
	NetworkCost float64 `json:"network_cost,omitempty"`
	StorageCost float64 `json:"storage_cost,omitempty"`
	TotalCost   float64 `json:"total_cost"`
	HourlyRate  float64 `json:"hourly_rate"`
}

// ContainerLogs represents container log entries
type ContainerLogs struct {
	ContainerID string     `json:"container_id"`
	Logs        []LogEntry `json:"logs"`
	HasMore     bool       `json:"has_more"`
	NextCursor  string     `json:"next_cursor,omitempty"`
}

// LogEntry represents a single log entry
type LogEntry struct {
	Timestamp time.Time `json:"timestamp"`
	Level     string    `json:"level,omitempty"`
	Message   string    `json:"message"`
	Source    string    `json:"source,omitempty"`
}

// UpdateDeploymentRequest represents request to update deployment configuration
type UpdateDeploymentRequest struct {
	EnvVariables       map[string]string `json:"env_variables,omitempty"`
	SecretEnvVariables map[string]string `json:"secret_env_variables,omitempty"`
	Entrypoint         []string          `json:"entrypoint,omitempty"`
	TrafficPort        *int              `json:"traffic_port,omitempty"`
	ImageURL           string            `json:"image_url,omitempty"`
	RegistryUsername   string            `json:"registry_username,omitempty"`
	RegistrySecret     string            `json:"registry_secret,omitempty"`
	Args               []string          `json:"args,omitempty"`
	Command            string            `json:"command,omitempty"`
}

// ExtendDurationRequest represents request to extend deployment duration
type ExtendDurationRequest struct {
	DurationHours int `json:"duration_hours"`
}

// UpdateDeploymentResponse represents response from deployment update
type UpdateDeploymentResponse struct {
	Status       string `json:"status"`
	DeploymentID string `json:"deployment_id"`
}

// UpdateClusterNameRequest represents request to update cluster name
type UpdateClusterNameRequest struct {
	Name string `json:"cluster_name"`
}

// UpdateClusterNameResponse represents response from cluster name update
type UpdateClusterNameResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
}

// APIError represents an API error response
type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details string `json:"details,omitempty"`
}

// Error implements the error interface
func (e *APIError) Error() string {
	if e.Details != "" {
		return e.Message + ": " + e.Details
	}
	return e.Message
}

// ListDeploymentsOptions represents options for listing deployments
type ListDeploymentsOptions struct {
	Status     string `json:"status,omitempty"`      // filter by status
	LocationID int    `json:"location_id,omitempty"` // filter by location
	Page       int    `json:"page,omitempty"`        // pagination
	PageSize   int    `json:"page_size,omitempty"`   // pagination
	SortBy     string `json:"sort_by,omitempty"`     // sort field
	SortOrder  string `json:"sort_order,omitempty"`  // asc/desc
}

// GetLogsOptions represents options for retrieving container logs
type GetLogsOptions struct {
	StartTime *time.Time `json:"start_time,omitempty"`
	EndTime   *time.Time `json:"end_time,omitempty"`
	Level     string     `json:"level,omitempty"`  // filter by log level
	Stream    string     `json:"stream,omitempty"` // filter by stdout/stderr streams
	Limit     int        `json:"limit,omitempty"`  // max number of log entries
	Cursor    string     `json:"cursor,omitempty"` // pagination cursor
	Follow    bool       `json:"follow,omitempty"` // stream logs
}

// HardwareType represents a hardware type available for deployment
type HardwareType struct {
	ID             int     `json:"id"`
	Name           string  `json:"name"`
	Description    string  `json:"description,omitempty"`
	GPUType        string  `json:"gpu_type"`
	GPUMemory      int     `json:"gpu_memory"` // in GB
	MaxGPUs        int     `json:"max_gpus"`
	CPU            string  `json:"cpu,omitempty"`
	Memory         int     `json:"memory,omitempty"`  // in GB
	Storage        int     `json:"storage,omitempty"` // in GB
	HourlyRate     float64 `json:"hourly_rate"`
	Available      bool    `json:"available"`
	BrandName      string  `json:"brand_name,omitempty"`
	AvailableCount int     `json:"available_count,omitempty"`
}

// Location represents a deployment location
type Location struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	ISO2        string  `json:"iso2,omitempty"`
	Region      string  `json:"region,omitempty"`
	Country     string  `json:"country,omitempty"`
	Latitude    float64 `json:"latitude,omitempty"`
	Longitude   float64 `json:"longitude,omitempty"`
	Available   int     `json:"available,omitempty"`
	Description string  `json:"description,omitempty"`
}

// LocationsResponse represents the list of locations and aggregated metadata.
type LocationsResponse struct {
	Locations []Location `json:"locations"`
	Total     int        `json:"total"`
}

// LocationAvailability represents real-time availability for a location
type LocationAvailability struct {
	LocationID           int                    `json:"location_id"`
	LocationName         string                 `json:"location_name"`
	Available            bool                   `json:"available"`
	HardwareAvailability []HardwareAvailability `json:"hardware_availability"`
	UpdatedAt            time.Time              `json:"updated_at"`
}

// HardwareAvailability represents availability for specific hardware at a location
type HardwareAvailability struct {
	HardwareID     int    `json:"hardware_id"`
	HardwareName   string `json:"hardware_name"`
	AvailableCount int    `json:"available_count"`
	MaxGPUs        int    `json:"max_gpus"`
}