deployment.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. package controller
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "github.com/QuantumNous/new-api/common"
  8. "github.com/QuantumNous/new-api/pkg/ionet"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func getIoAPIKey(c *gin.Context) (string, bool) {
  12. common.OptionMapRWMutex.RLock()
  13. enabled := common.OptionMap["model_deployment.ionet.enabled"] == "true"
  14. apiKey := common.OptionMap["model_deployment.ionet.api_key"]
  15. common.OptionMapRWMutex.RUnlock()
  16. if !enabled || strings.TrimSpace(apiKey) == "" {
  17. common.ApiErrorMsg(c, "io.net model deployment is not enabled or api key missing")
  18. return "", false
  19. }
  20. return apiKey, true
  21. }
  22. func getIoClient(c *gin.Context) (*ionet.Client, bool) {
  23. apiKey, ok := getIoAPIKey(c)
  24. if !ok {
  25. return nil, false
  26. }
  27. return ionet.NewClient(apiKey), true
  28. }
  29. func getIoEnterpriseClient(c *gin.Context) (*ionet.Client, bool) {
  30. apiKey, ok := getIoAPIKey(c)
  31. if !ok {
  32. return nil, false
  33. }
  34. return ionet.NewEnterpriseClient(apiKey), true
  35. }
  36. func TestIoNetConnection(c *gin.Context) {
  37. var req struct {
  38. APIKey string `json:"api_key"`
  39. }
  40. if err := c.ShouldBindJSON(&req); err != nil {
  41. common.ApiErrorMsg(c, "invalid request payload")
  42. return
  43. }
  44. apiKey := strings.TrimSpace(req.APIKey)
  45. if apiKey == "" {
  46. common.ApiErrorMsg(c, "api_key is required")
  47. return
  48. }
  49. client := ionet.NewEnterpriseClient(apiKey)
  50. result, err := client.GetMaxGPUsPerContainer()
  51. if err != nil {
  52. if apiErr, ok := err.(*ionet.APIError); ok {
  53. message := strings.TrimSpace(apiErr.Message)
  54. if message == "" {
  55. message = "failed to validate api key"
  56. }
  57. common.ApiErrorMsg(c, message)
  58. return
  59. }
  60. common.ApiError(c, err)
  61. return
  62. }
  63. totalHardware := 0
  64. totalAvailable := 0
  65. if result != nil {
  66. totalHardware = len(result.Hardware)
  67. totalAvailable = result.Total
  68. if totalAvailable == 0 {
  69. for _, hw := range result.Hardware {
  70. totalAvailable += hw.Available
  71. }
  72. }
  73. }
  74. common.ApiSuccess(c, gin.H{
  75. "hardware_count": totalHardware,
  76. "total_available": totalAvailable,
  77. })
  78. }
  79. func requireDeploymentID(c *gin.Context) (string, bool) {
  80. deploymentID := strings.TrimSpace(c.Param("id"))
  81. if deploymentID == "" {
  82. common.ApiErrorMsg(c, "deployment ID is required")
  83. return "", false
  84. }
  85. return deploymentID, true
  86. }
  87. func requireContainerID(c *gin.Context) (string, bool) {
  88. containerID := strings.TrimSpace(c.Param("container_id"))
  89. if containerID == "" {
  90. common.ApiErrorMsg(c, "container ID is required")
  91. return "", false
  92. }
  93. return containerID, true
  94. }
  95. func mapIoNetDeployment(d ionet.Deployment) map[string]interface{} {
  96. var created int64
  97. if d.CreatedAt.IsZero() {
  98. created = time.Now().Unix()
  99. } else {
  100. created = d.CreatedAt.Unix()
  101. }
  102. timeRemainingHours := d.ComputeMinutesRemaining / 60
  103. timeRemainingMins := d.ComputeMinutesRemaining % 60
  104. var timeRemaining string
  105. if timeRemainingHours > 0 {
  106. timeRemaining = fmt.Sprintf("%d hour %d minutes", timeRemainingHours, timeRemainingMins)
  107. } else if timeRemainingMins > 0 {
  108. timeRemaining = fmt.Sprintf("%d minutes", timeRemainingMins)
  109. } else {
  110. timeRemaining = "completed"
  111. }
  112. hardwareInfo := fmt.Sprintf("%s %s x%d", d.BrandName, d.HardwareName, d.HardwareQuantity)
  113. return map[string]interface{}{
  114. "id": d.ID,
  115. "deployment_name": d.Name,
  116. "container_name": d.Name,
  117. "status": strings.ToLower(d.Status),
  118. "type": "Container",
  119. "time_remaining": timeRemaining,
  120. "time_remaining_minutes": d.ComputeMinutesRemaining,
  121. "hardware_info": hardwareInfo,
  122. "hardware_name": d.HardwareName,
  123. "brand_name": d.BrandName,
  124. "hardware_quantity": d.HardwareQuantity,
  125. "completed_percent": d.CompletedPercent,
  126. "compute_minutes_served": d.ComputeMinutesServed,
  127. "compute_minutes_remaining": d.ComputeMinutesRemaining,
  128. "created_at": created,
  129. "updated_at": created,
  130. "model_name": "",
  131. "model_version": "",
  132. "instance_count": d.HardwareQuantity,
  133. "resource_config": map[string]interface{}{
  134. "cpu": "",
  135. "memory": "",
  136. "gpu": strconv.Itoa(d.HardwareQuantity),
  137. },
  138. "description": "",
  139. "provider": "io.net",
  140. }
  141. }
  142. func computeStatusCounts(total int, deployments []ionet.Deployment) map[string]int64 {
  143. counts := map[string]int64{
  144. "all": int64(total),
  145. }
  146. for _, status := range []string{"running", "completed", "failed", "deployment requested", "termination requested", "destroyed"} {
  147. counts[status] = 0
  148. }
  149. for _, d := range deployments {
  150. status := strings.ToLower(strings.TrimSpace(d.Status))
  151. counts[status] = counts[status] + 1
  152. }
  153. return counts
  154. }
  155. func GetAllDeployments(c *gin.Context) {
  156. pageInfo := common.GetPageQuery(c)
  157. client, ok := getIoEnterpriseClient(c)
  158. if !ok {
  159. return
  160. }
  161. status := c.Query("status")
  162. opts := &ionet.ListDeploymentsOptions{
  163. Status: strings.ToLower(strings.TrimSpace(status)),
  164. Page: pageInfo.GetPage(),
  165. PageSize: pageInfo.GetPageSize(),
  166. SortBy: "created_at",
  167. SortOrder: "desc",
  168. }
  169. dl, err := client.ListDeployments(opts)
  170. if err != nil {
  171. common.ApiError(c, err)
  172. return
  173. }
  174. items := make([]map[string]interface{}, 0, len(dl.Deployments))
  175. for _, d := range dl.Deployments {
  176. items = append(items, mapIoNetDeployment(d))
  177. }
  178. data := gin.H{
  179. "page": pageInfo.GetPage(),
  180. "page_size": pageInfo.GetPageSize(),
  181. "total": dl.Total,
  182. "items": items,
  183. "status_counts": computeStatusCounts(dl.Total, dl.Deployments),
  184. }
  185. common.ApiSuccess(c, data)
  186. }
  187. func SearchDeployments(c *gin.Context) {
  188. pageInfo := common.GetPageQuery(c)
  189. client, ok := getIoEnterpriseClient(c)
  190. if !ok {
  191. return
  192. }
  193. status := strings.ToLower(strings.TrimSpace(c.Query("status")))
  194. keyword := strings.TrimSpace(c.Query("keyword"))
  195. dl, err := client.ListDeployments(&ionet.ListDeploymentsOptions{
  196. Status: status,
  197. Page: pageInfo.GetPage(),
  198. PageSize: pageInfo.GetPageSize(),
  199. SortBy: "created_at",
  200. SortOrder: "desc",
  201. })
  202. if err != nil {
  203. common.ApiError(c, err)
  204. return
  205. }
  206. filtered := make([]ionet.Deployment, 0, len(dl.Deployments))
  207. if keyword == "" {
  208. filtered = dl.Deployments
  209. } else {
  210. kw := strings.ToLower(keyword)
  211. for _, d := range dl.Deployments {
  212. if strings.Contains(strings.ToLower(d.Name), kw) {
  213. filtered = append(filtered, d)
  214. }
  215. }
  216. }
  217. items := make([]map[string]interface{}, 0, len(filtered))
  218. for _, d := range filtered {
  219. items = append(items, mapIoNetDeployment(d))
  220. }
  221. total := dl.Total
  222. if keyword != "" {
  223. total = len(filtered)
  224. }
  225. data := gin.H{
  226. "page": pageInfo.GetPage(),
  227. "page_size": pageInfo.GetPageSize(),
  228. "total": total,
  229. "items": items,
  230. }
  231. common.ApiSuccess(c, data)
  232. }
  233. func GetDeployment(c *gin.Context) {
  234. client, ok := getIoEnterpriseClient(c)
  235. if !ok {
  236. return
  237. }
  238. deploymentID, ok := requireDeploymentID(c)
  239. if !ok {
  240. return
  241. }
  242. details, err := client.GetDeployment(deploymentID)
  243. if err != nil {
  244. common.ApiError(c, err)
  245. return
  246. }
  247. data := map[string]interface{}{
  248. "id": details.ID,
  249. "deployment_name": details.ID,
  250. "model_name": "",
  251. "model_version": "",
  252. "status": strings.ToLower(details.Status),
  253. "instance_count": details.TotalContainers,
  254. "hardware_id": details.HardwareID,
  255. "resource_config": map[string]interface{}{
  256. "cpu": "",
  257. "memory": "",
  258. "gpu": strconv.Itoa(details.TotalGPUs),
  259. },
  260. "created_at": details.CreatedAt.Unix(),
  261. "updated_at": details.CreatedAt.Unix(),
  262. "description": "",
  263. "amount_paid": details.AmountPaid,
  264. "completed_percent": details.CompletedPercent,
  265. "gpus_per_container": details.GPUsPerContainer,
  266. "total_gpus": details.TotalGPUs,
  267. "total_containers": details.TotalContainers,
  268. "hardware_name": details.HardwareName,
  269. "brand_name": details.BrandName,
  270. "compute_minutes_served": details.ComputeMinutesServed,
  271. "compute_minutes_remaining": details.ComputeMinutesRemaining,
  272. "locations": details.Locations,
  273. "container_config": details.ContainerConfig,
  274. }
  275. common.ApiSuccess(c, data)
  276. }
  277. func UpdateDeploymentName(c *gin.Context) {
  278. client, ok := getIoEnterpriseClient(c)
  279. if !ok {
  280. return
  281. }
  282. deploymentID, ok := requireDeploymentID(c)
  283. if !ok {
  284. return
  285. }
  286. var req struct {
  287. Name string `json:"name" binding:"required"`
  288. }
  289. if err := c.ShouldBindJSON(&req); err != nil {
  290. common.ApiError(c, err)
  291. return
  292. }
  293. updateReq := &ionet.UpdateClusterNameRequest{
  294. Name: strings.TrimSpace(req.Name),
  295. }
  296. if updateReq.Name == "" {
  297. common.ApiErrorMsg(c, "deployment name cannot be empty")
  298. return
  299. }
  300. available, err := client.CheckClusterNameAvailability(updateReq.Name)
  301. if err != nil {
  302. common.ApiError(c, fmt.Errorf("failed to check name availability: %w", err))
  303. return
  304. }
  305. if !available {
  306. common.ApiErrorMsg(c, "deployment name is not available, please choose a different name")
  307. return
  308. }
  309. resp, err := client.UpdateClusterName(deploymentID, updateReq)
  310. if err != nil {
  311. common.ApiError(c, err)
  312. return
  313. }
  314. data := gin.H{
  315. "status": resp.Status,
  316. "message": resp.Message,
  317. "id": deploymentID,
  318. "name": updateReq.Name,
  319. }
  320. common.ApiSuccess(c, data)
  321. }
  322. func UpdateDeployment(c *gin.Context) {
  323. client, ok := getIoEnterpriseClient(c)
  324. if !ok {
  325. return
  326. }
  327. deploymentID, ok := requireDeploymentID(c)
  328. if !ok {
  329. return
  330. }
  331. var req ionet.UpdateDeploymentRequest
  332. if err := c.ShouldBindJSON(&req); err != nil {
  333. common.ApiError(c, err)
  334. return
  335. }
  336. resp, err := client.UpdateDeployment(deploymentID, &req)
  337. if err != nil {
  338. common.ApiError(c, err)
  339. return
  340. }
  341. data := gin.H{
  342. "status": resp.Status,
  343. "deployment_id": resp.DeploymentID,
  344. }
  345. common.ApiSuccess(c, data)
  346. }
  347. func ExtendDeployment(c *gin.Context) {
  348. client, ok := getIoEnterpriseClient(c)
  349. if !ok {
  350. return
  351. }
  352. deploymentID, ok := requireDeploymentID(c)
  353. if !ok {
  354. return
  355. }
  356. var req ionet.ExtendDurationRequest
  357. if err := c.ShouldBindJSON(&req); err != nil {
  358. common.ApiError(c, err)
  359. return
  360. }
  361. details, err := client.ExtendDeployment(deploymentID, &req)
  362. if err != nil {
  363. common.ApiError(c, err)
  364. return
  365. }
  366. data := mapIoNetDeployment(ionet.Deployment{
  367. ID: details.ID,
  368. Status: details.Status,
  369. Name: deploymentID,
  370. CompletedPercent: float64(details.CompletedPercent),
  371. HardwareQuantity: details.TotalGPUs,
  372. BrandName: details.BrandName,
  373. HardwareName: details.HardwareName,
  374. ComputeMinutesServed: details.ComputeMinutesServed,
  375. ComputeMinutesRemaining: details.ComputeMinutesRemaining,
  376. CreatedAt: details.CreatedAt,
  377. })
  378. common.ApiSuccess(c, data)
  379. }
  380. func DeleteDeployment(c *gin.Context) {
  381. client, ok := getIoEnterpriseClient(c)
  382. if !ok {
  383. return
  384. }
  385. deploymentID, ok := requireDeploymentID(c)
  386. if !ok {
  387. return
  388. }
  389. resp, err := client.DeleteDeployment(deploymentID)
  390. if err != nil {
  391. common.ApiError(c, err)
  392. return
  393. }
  394. data := gin.H{
  395. "status": resp.Status,
  396. "deployment_id": resp.DeploymentID,
  397. "message": "Deployment termination requested successfully",
  398. }
  399. common.ApiSuccess(c, data)
  400. }
  401. func CreateDeployment(c *gin.Context) {
  402. client, ok := getIoEnterpriseClient(c)
  403. if !ok {
  404. return
  405. }
  406. var req ionet.DeploymentRequest
  407. if err := c.ShouldBindJSON(&req); err != nil {
  408. common.ApiError(c, err)
  409. return
  410. }
  411. resp, err := client.DeployContainer(&req)
  412. if err != nil {
  413. common.ApiError(c, err)
  414. return
  415. }
  416. data := gin.H{
  417. "deployment_id": resp.DeploymentID,
  418. "status": resp.Status,
  419. "message": "Deployment created successfully",
  420. }
  421. common.ApiSuccess(c, data)
  422. }
  423. func GetHardwareTypes(c *gin.Context) {
  424. client, ok := getIoEnterpriseClient(c)
  425. if !ok {
  426. return
  427. }
  428. hardwareTypes, totalAvailable, err := client.ListHardwareTypes()
  429. if err != nil {
  430. common.ApiError(c, err)
  431. return
  432. }
  433. data := gin.H{
  434. "hardware_types": hardwareTypes,
  435. "total": len(hardwareTypes),
  436. "total_available": totalAvailable,
  437. }
  438. common.ApiSuccess(c, data)
  439. }
  440. func GetLocations(c *gin.Context) {
  441. client, ok := getIoClient(c)
  442. if !ok {
  443. return
  444. }
  445. locationsResp, err := client.ListLocations()
  446. if err != nil {
  447. common.ApiError(c, err)
  448. return
  449. }
  450. total := locationsResp.Total
  451. if total == 0 {
  452. total = len(locationsResp.Locations)
  453. }
  454. data := gin.H{
  455. "locations": locationsResp.Locations,
  456. "total": total,
  457. }
  458. common.ApiSuccess(c, data)
  459. }
  460. func GetAvailableReplicas(c *gin.Context) {
  461. client, ok := getIoEnterpriseClient(c)
  462. if !ok {
  463. return
  464. }
  465. hardwareIDStr := c.Query("hardware_id")
  466. gpuCountStr := c.Query("gpu_count")
  467. if hardwareIDStr == "" {
  468. common.ApiErrorMsg(c, "hardware_id parameter is required")
  469. return
  470. }
  471. hardwareID, err := strconv.Atoi(hardwareIDStr)
  472. if err != nil || hardwareID <= 0 {
  473. common.ApiErrorMsg(c, "invalid hardware_id parameter")
  474. return
  475. }
  476. gpuCount := 1
  477. if gpuCountStr != "" {
  478. if parsed, err := strconv.Atoi(gpuCountStr); err == nil && parsed > 0 {
  479. gpuCount = parsed
  480. }
  481. }
  482. replicas, err := client.GetAvailableReplicas(hardwareID, gpuCount)
  483. if err != nil {
  484. common.ApiError(c, err)
  485. return
  486. }
  487. common.ApiSuccess(c, replicas)
  488. }
  489. func GetPriceEstimation(c *gin.Context) {
  490. client, ok := getIoEnterpriseClient(c)
  491. if !ok {
  492. return
  493. }
  494. var req ionet.PriceEstimationRequest
  495. if err := c.ShouldBindJSON(&req); err != nil {
  496. common.ApiError(c, err)
  497. return
  498. }
  499. priceResp, err := client.GetPriceEstimation(&req)
  500. if err != nil {
  501. common.ApiError(c, err)
  502. return
  503. }
  504. common.ApiSuccess(c, priceResp)
  505. }
  506. func CheckClusterNameAvailability(c *gin.Context) {
  507. client, ok := getIoEnterpriseClient(c)
  508. if !ok {
  509. return
  510. }
  511. clusterName := strings.TrimSpace(c.Query("name"))
  512. if clusterName == "" {
  513. common.ApiErrorMsg(c, "name parameter is required")
  514. return
  515. }
  516. available, err := client.CheckClusterNameAvailability(clusterName)
  517. if err != nil {
  518. common.ApiError(c, err)
  519. return
  520. }
  521. data := gin.H{
  522. "available": available,
  523. "name": clusterName,
  524. }
  525. common.ApiSuccess(c, data)
  526. }
  527. func GetDeploymentLogs(c *gin.Context) {
  528. client, ok := getIoClient(c)
  529. if !ok {
  530. return
  531. }
  532. deploymentID, ok := requireDeploymentID(c)
  533. if !ok {
  534. return
  535. }
  536. containerID := c.Query("container_id")
  537. if containerID == "" {
  538. common.ApiErrorMsg(c, "container_id parameter is required")
  539. return
  540. }
  541. level := c.Query("level")
  542. stream := c.Query("stream")
  543. cursor := c.Query("cursor")
  544. limitStr := c.Query("limit")
  545. follow := c.Query("follow") == "true"
  546. var limit int = 100
  547. if limitStr != "" {
  548. if parsedLimit, err := strconv.Atoi(limitStr); err == nil && parsedLimit > 0 {
  549. limit = parsedLimit
  550. if limit > 1000 {
  551. limit = 1000
  552. }
  553. }
  554. }
  555. opts := &ionet.GetLogsOptions{
  556. Level: level,
  557. Stream: stream,
  558. Limit: limit,
  559. Cursor: cursor,
  560. Follow: follow,
  561. }
  562. if startTime := c.Query("start_time"); startTime != "" {
  563. if t, err := time.Parse(time.RFC3339, startTime); err == nil {
  564. opts.StartTime = &t
  565. }
  566. }
  567. if endTime := c.Query("end_time"); endTime != "" {
  568. if t, err := time.Parse(time.RFC3339, endTime); err == nil {
  569. opts.EndTime = &t
  570. }
  571. }
  572. rawLogs, err := client.GetContainerLogsRaw(deploymentID, containerID, opts)
  573. if err != nil {
  574. common.ApiError(c, err)
  575. return
  576. }
  577. common.ApiSuccess(c, rawLogs)
  578. }
  579. func ListDeploymentContainers(c *gin.Context) {
  580. client, ok := getIoEnterpriseClient(c)
  581. if !ok {
  582. return
  583. }
  584. deploymentID, ok := requireDeploymentID(c)
  585. if !ok {
  586. return
  587. }
  588. containers, err := client.ListContainers(deploymentID)
  589. if err != nil {
  590. common.ApiError(c, err)
  591. return
  592. }
  593. items := make([]map[string]interface{}, 0)
  594. if containers != nil {
  595. items = make([]map[string]interface{}, 0, len(containers.Workers))
  596. for _, ctr := range containers.Workers {
  597. events := make([]map[string]interface{}, 0, len(ctr.ContainerEvents))
  598. for _, event := range ctr.ContainerEvents {
  599. events = append(events, map[string]interface{}{
  600. "time": event.Time.Unix(),
  601. "message": event.Message,
  602. })
  603. }
  604. items = append(items, map[string]interface{}{
  605. "container_id": ctr.ContainerID,
  606. "device_id": ctr.DeviceID,
  607. "status": strings.ToLower(strings.TrimSpace(ctr.Status)),
  608. "hardware": ctr.Hardware,
  609. "brand_name": ctr.BrandName,
  610. "created_at": ctr.CreatedAt.Unix(),
  611. "uptime_percent": ctr.UptimePercent,
  612. "gpus_per_container": ctr.GPUsPerContainer,
  613. "public_url": ctr.PublicURL,
  614. "events": events,
  615. })
  616. }
  617. }
  618. response := gin.H{
  619. "total": 0,
  620. "containers": items,
  621. }
  622. if containers != nil {
  623. response["total"] = containers.Total
  624. }
  625. common.ApiSuccess(c, response)
  626. }
  627. func GetContainerDetails(c *gin.Context) {
  628. client, ok := getIoEnterpriseClient(c)
  629. if !ok {
  630. return
  631. }
  632. deploymentID, ok := requireDeploymentID(c)
  633. if !ok {
  634. return
  635. }
  636. containerID, ok := requireContainerID(c)
  637. if !ok {
  638. return
  639. }
  640. details, err := client.GetContainerDetails(deploymentID, containerID)
  641. if err != nil {
  642. common.ApiError(c, err)
  643. return
  644. }
  645. if details == nil {
  646. common.ApiErrorMsg(c, "container details not found")
  647. return
  648. }
  649. events := make([]map[string]interface{}, 0, len(details.ContainerEvents))
  650. for _, event := range details.ContainerEvents {
  651. events = append(events, map[string]interface{}{
  652. "time": event.Time.Unix(),
  653. "message": event.Message,
  654. })
  655. }
  656. data := gin.H{
  657. "deployment_id": deploymentID,
  658. "container_id": details.ContainerID,
  659. "device_id": details.DeviceID,
  660. "status": strings.ToLower(strings.TrimSpace(details.Status)),
  661. "hardware": details.Hardware,
  662. "brand_name": details.BrandName,
  663. "created_at": details.CreatedAt.Unix(),
  664. "uptime_percent": details.UptimePercent,
  665. "gpus_per_container": details.GPUsPerContainer,
  666. "public_url": details.PublicURL,
  667. "events": events,
  668. }
  669. common.ApiSuccess(c, data)
  670. }