types.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package ionet
  2. import (
  3. "time"
  4. )
  5. // Client represents the IO.NET API client
  6. type Client struct {
  7. BaseURL string
  8. APIKey string
  9. HTTPClient HTTPClient
  10. }
  11. // HTTPClient interface for making HTTP requests
  12. type HTTPClient interface {
  13. Do(req *HTTPRequest) (*HTTPResponse, error)
  14. }
  15. // HTTPRequest represents an HTTP request
  16. type HTTPRequest struct {
  17. Method string
  18. URL string
  19. Headers map[string]string
  20. Body []byte
  21. }
  22. // HTTPResponse represents an HTTP response
  23. type HTTPResponse struct {
  24. StatusCode int
  25. Headers map[string]string
  26. Body []byte
  27. }
  28. // DeploymentRequest represents a container deployment request
  29. type DeploymentRequest struct {
  30. ResourcePrivateName string `json:"resource_private_name"`
  31. DurationHours int `json:"duration_hours"`
  32. GPUsPerContainer int `json:"gpus_per_container"`
  33. HardwareID int `json:"hardware_id"`
  34. LocationIDs []int `json:"location_ids"`
  35. ContainerConfig ContainerConfig `json:"container_config"`
  36. RegistryConfig RegistryConfig `json:"registry_config"`
  37. }
  38. // ContainerConfig represents container configuration
  39. type ContainerConfig struct {
  40. ReplicaCount int `json:"replica_count"`
  41. EnvVariables map[string]string `json:"env_variables,omitempty"`
  42. SecretEnvVariables map[string]string `json:"secret_env_variables,omitempty"`
  43. Entrypoint []string `json:"entrypoint,omitempty"`
  44. TrafficPort int `json:"traffic_port,omitempty"`
  45. Args []string `json:"args,omitempty"`
  46. }
  47. // RegistryConfig represents registry configuration
  48. type RegistryConfig struct {
  49. ImageURL string `json:"image_url"`
  50. RegistryUsername string `json:"registry_username,omitempty"`
  51. RegistrySecret string `json:"registry_secret,omitempty"`
  52. }
  53. // DeploymentResponse represents the response from deployment creation
  54. type DeploymentResponse struct {
  55. DeploymentID string `json:"deployment_id"`
  56. Status string `json:"status"`
  57. }
  58. // DeploymentDetail represents detailed deployment information
  59. type DeploymentDetail struct {
  60. ID string `json:"id"`
  61. Status string `json:"status"`
  62. CreatedAt time.Time `json:"created_at"`
  63. StartedAt *time.Time `json:"started_at,omitempty"`
  64. FinishedAt *time.Time `json:"finished_at,omitempty"`
  65. AmountPaid float64 `json:"amount_paid"`
  66. CompletedPercent float64 `json:"completed_percent"`
  67. TotalGPUs int `json:"total_gpus"`
  68. GPUsPerContainer int `json:"gpus_per_container"`
  69. TotalContainers int `json:"total_containers"`
  70. HardwareName string `json:"hardware_name"`
  71. HardwareID int `json:"hardware_id"`
  72. Locations []DeploymentLocation `json:"locations"`
  73. BrandName string `json:"brand_name"`
  74. ComputeMinutesServed int `json:"compute_minutes_served"`
  75. ComputeMinutesRemaining int `json:"compute_minutes_remaining"`
  76. ContainerConfig DeploymentContainerConfig `json:"container_config"`
  77. }
  78. // DeploymentLocation represents a location in deployment details
  79. type DeploymentLocation struct {
  80. ID int `json:"id"`
  81. ISO2 string `json:"iso2"`
  82. Name string `json:"name"`
  83. }
  84. // DeploymentContainerConfig represents container config in deployment details
  85. type DeploymentContainerConfig struct {
  86. Entrypoint []string `json:"entrypoint"`
  87. EnvVariables map[string]interface{} `json:"env_variables"`
  88. TrafficPort int `json:"traffic_port"`
  89. ImageURL string `json:"image_url"`
  90. }
  91. // Container represents a container within a deployment
  92. type Container struct {
  93. DeviceID string `json:"device_id"`
  94. ContainerID string `json:"container_id"`
  95. Hardware string `json:"hardware"`
  96. BrandName string `json:"brand_name"`
  97. CreatedAt time.Time `json:"created_at"`
  98. UptimePercent int `json:"uptime_percent"`
  99. GPUsPerContainer int `json:"gpus_per_container"`
  100. Status string `json:"status"`
  101. ContainerEvents []ContainerEvent `json:"container_events"`
  102. PublicURL string `json:"public_url"`
  103. }
  104. // ContainerEvent represents a container event
  105. type ContainerEvent struct {
  106. Time time.Time `json:"time"`
  107. Message string `json:"message"`
  108. }
  109. // ContainerList represents a list of containers
  110. type ContainerList struct {
  111. Total int `json:"total"`
  112. Workers []Container `json:"workers"`
  113. }
  114. // Deployment represents a deployment in the list
  115. type Deployment struct {
  116. ID string `json:"id"`
  117. Status string `json:"status"`
  118. Name string `json:"name"`
  119. CompletedPercent float64 `json:"completed_percent"`
  120. HardwareQuantity int `json:"hardware_quantity"`
  121. BrandName string `json:"brand_name"`
  122. HardwareName string `json:"hardware_name"`
  123. Served string `json:"served"`
  124. Remaining string `json:"remaining"`
  125. ComputeMinutesServed int `json:"compute_minutes_served"`
  126. ComputeMinutesRemaining int `json:"compute_minutes_remaining"`
  127. CreatedAt time.Time `json:"created_at"`
  128. GPUCount int `json:"-"` // Derived from HardwareQuantity
  129. Replicas int `json:"-"` // Derived from HardwareQuantity
  130. }
  131. // DeploymentList represents a list of deployments with pagination
  132. type DeploymentList struct {
  133. Deployments []Deployment `json:"deployments"`
  134. Total int `json:"total"`
  135. Statuses []string `json:"statuses"`
  136. }
  137. // AvailableReplica represents replica availability for a location
  138. type AvailableReplica struct {
  139. LocationID int `json:"location_id"`
  140. LocationName string `json:"location_name"`
  141. HardwareID int `json:"hardware_id"`
  142. HardwareName string `json:"hardware_name"`
  143. AvailableCount int `json:"available_count"`
  144. MaxGPUs int `json:"max_gpus"`
  145. }
  146. // AvailableReplicasResponse represents the response for available replicas
  147. type AvailableReplicasResponse struct {
  148. Replicas []AvailableReplica `json:"replicas"`
  149. }
  150. // MaxGPUResponse represents the response for maximum GPUs per container
  151. type MaxGPUResponse struct {
  152. Hardware []MaxGPUInfo `json:"hardware"`
  153. Total int `json:"total"`
  154. }
  155. // MaxGPUInfo represents max GPU information for a hardware type
  156. type MaxGPUInfo struct {
  157. MaxGPUsPerContainer int `json:"max_gpus_per_container"`
  158. Available int `json:"available"`
  159. HardwareID int `json:"hardware_id"`
  160. HardwareName string `json:"hardware_name"`
  161. BrandName string `json:"brand_name"`
  162. }
  163. // PriceEstimationRequest represents a price estimation request
  164. type PriceEstimationRequest struct {
  165. LocationIDs []int `json:"location_ids"`
  166. HardwareID int `json:"hardware_id"`
  167. GPUsPerContainer int `json:"gpus_per_container"`
  168. DurationHours int `json:"duration_hours"`
  169. ReplicaCount int `json:"replica_count"`
  170. Currency string `json:"currency"`
  171. DurationType string `json:"duration_type"`
  172. DurationQty int `json:"duration_qty"`
  173. HardwareQty int `json:"hardware_qty"`
  174. }
  175. // PriceEstimationResponse represents the price estimation response
  176. type PriceEstimationResponse struct {
  177. EstimatedCost float64 `json:"estimated_cost"`
  178. Currency string `json:"currency"`
  179. PriceBreakdown PriceBreakdown `json:"price_breakdown"`
  180. EstimationValid bool `json:"estimation_valid"`
  181. }
  182. // PriceBreakdown represents detailed cost breakdown
  183. type PriceBreakdown struct {
  184. ComputeCost float64 `json:"compute_cost"`
  185. NetworkCost float64 `json:"network_cost,omitempty"`
  186. StorageCost float64 `json:"storage_cost,omitempty"`
  187. TotalCost float64 `json:"total_cost"`
  188. HourlyRate float64 `json:"hourly_rate"`
  189. }
  190. // ContainerLogs represents container log entries
  191. type ContainerLogs struct {
  192. ContainerID string `json:"container_id"`
  193. Logs []LogEntry `json:"logs"`
  194. HasMore bool `json:"has_more"`
  195. NextCursor string `json:"next_cursor,omitempty"`
  196. }
  197. // LogEntry represents a single log entry
  198. type LogEntry struct {
  199. Timestamp time.Time `json:"timestamp"`
  200. Level string `json:"level,omitempty"`
  201. Message string `json:"message"`
  202. Source string `json:"source,omitempty"`
  203. }
  204. // UpdateDeploymentRequest represents request to update deployment configuration
  205. type UpdateDeploymentRequest struct {
  206. EnvVariables map[string]string `json:"env_variables,omitempty"`
  207. SecretEnvVariables map[string]string `json:"secret_env_variables,omitempty"`
  208. Entrypoint []string `json:"entrypoint,omitempty"`
  209. TrafficPort *int `json:"traffic_port,omitempty"`
  210. ImageURL string `json:"image_url,omitempty"`
  211. RegistryUsername string `json:"registry_username,omitempty"`
  212. RegistrySecret string `json:"registry_secret,omitempty"`
  213. Args []string `json:"args,omitempty"`
  214. Command string `json:"command,omitempty"`
  215. }
  216. // ExtendDurationRequest represents request to extend deployment duration
  217. type ExtendDurationRequest struct {
  218. DurationHours int `json:"duration_hours"`
  219. }
  220. // UpdateDeploymentResponse represents response from deployment update
  221. type UpdateDeploymentResponse struct {
  222. Status string `json:"status"`
  223. DeploymentID string `json:"deployment_id"`
  224. }
  225. // UpdateClusterNameRequest represents request to update cluster name
  226. type UpdateClusterNameRequest struct {
  227. Name string `json:"cluster_name"`
  228. }
  229. // UpdateClusterNameResponse represents response from cluster name update
  230. type UpdateClusterNameResponse struct {
  231. Status string `json:"status"`
  232. Message string `json:"message"`
  233. }
  234. // APIError represents an API error response
  235. type APIError struct {
  236. Code int `json:"code"`
  237. Message string `json:"message"`
  238. Details string `json:"details,omitempty"`
  239. }
  240. // Error implements the error interface
  241. func (e *APIError) Error() string {
  242. if e.Details != "" {
  243. return e.Message + ": " + e.Details
  244. }
  245. return e.Message
  246. }
  247. // ListDeploymentsOptions represents options for listing deployments
  248. type ListDeploymentsOptions struct {
  249. Status string `json:"status,omitempty"` // filter by status
  250. LocationID int `json:"location_id,omitempty"` // filter by location
  251. Page int `json:"page,omitempty"` // pagination
  252. PageSize int `json:"page_size,omitempty"` // pagination
  253. SortBy string `json:"sort_by,omitempty"` // sort field
  254. SortOrder string `json:"sort_order,omitempty"` // asc/desc
  255. }
  256. // GetLogsOptions represents options for retrieving container logs
  257. type GetLogsOptions struct {
  258. StartTime *time.Time `json:"start_time,omitempty"`
  259. EndTime *time.Time `json:"end_time,omitempty"`
  260. Level string `json:"level,omitempty"` // filter by log level
  261. Stream string `json:"stream,omitempty"` // filter by stdout/stderr streams
  262. Limit int `json:"limit,omitempty"` // max number of log entries
  263. Cursor string `json:"cursor,omitempty"` // pagination cursor
  264. Follow bool `json:"follow,omitempty"` // stream logs
  265. }
  266. // HardwareType represents a hardware type available for deployment
  267. type HardwareType struct {
  268. ID int `json:"id"`
  269. Name string `json:"name"`
  270. Description string `json:"description,omitempty"`
  271. GPUType string `json:"gpu_type"`
  272. GPUMemory int `json:"gpu_memory"` // in GB
  273. MaxGPUs int `json:"max_gpus"`
  274. CPU string `json:"cpu,omitempty"`
  275. Memory int `json:"memory,omitempty"` // in GB
  276. Storage int `json:"storage,omitempty"` // in GB
  277. HourlyRate float64 `json:"hourly_rate"`
  278. Available bool `json:"available"`
  279. BrandName string `json:"brand_name,omitempty"`
  280. AvailableCount int `json:"available_count,omitempty"`
  281. }
  282. // Location represents a deployment location
  283. type Location struct {
  284. ID int `json:"id"`
  285. Name string `json:"name"`
  286. ISO2 string `json:"iso2,omitempty"`
  287. Region string `json:"region,omitempty"`
  288. Country string `json:"country,omitempty"`
  289. Latitude float64 `json:"latitude,omitempty"`
  290. Longitude float64 `json:"longitude,omitempty"`
  291. Available int `json:"available,omitempty"`
  292. Description string `json:"description,omitempty"`
  293. }
  294. // LocationsResponse represents the list of locations and aggregated metadata.
  295. type LocationsResponse struct {
  296. Locations []Location `json:"locations"`
  297. Total int `json:"total"`
  298. }
  299. // LocationAvailability represents real-time availability for a location
  300. type LocationAvailability struct {
  301. LocationID int `json:"location_id"`
  302. LocationName string `json:"location_name"`
  303. Available bool `json:"available"`
  304. HardwareAvailability []HardwareAvailability `json:"hardware_availability"`
  305. UpdatedAt time.Time `json:"updated_at"`
  306. }
  307. // HardwareAvailability represents availability for specific hardware at a location
  308. type HardwareAvailability struct {
  309. HardwareID int `json:"hardware_id"`
  310. HardwareName string `json:"hardware_name"`
  311. AvailableCount int `json:"available_count"`
  312. MaxGPUs int `json:"max_gpus"`
  313. }