container.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aws
  15. func (self *SRegion) ListClusters() ([]string, error) {
  16. params := map[string]interface{}{
  17. "maxResults": 100,
  18. }
  19. ret := []string{}
  20. for {
  21. part := struct {
  22. ClusterArns []string
  23. NextToken string
  24. }{}
  25. err := self.ecsRequest("ListClusters", params, &part)
  26. if err != nil {
  27. return nil, err
  28. }
  29. ret = append(ret, part.ClusterArns...)
  30. if len(part.ClusterArns) == 0 || len(part.NextToken) == 0 {
  31. break
  32. }
  33. params["nextToken"] = part.NextToken
  34. }
  35. return ret, nil
  36. }
  37. func (self *SRegion) ListServices(cluster string) ([]string, error) {
  38. params := map[string]interface{}{
  39. "cluster": cluster,
  40. "maxResults": 100,
  41. }
  42. ret := []string{}
  43. for {
  44. part := struct {
  45. ServiceArns []string
  46. NextToken string
  47. }{}
  48. err := self.ecsRequest("ListServices", params, &part)
  49. if err != nil {
  50. return nil, err
  51. }
  52. ret = append(ret, part.ServiceArns...)
  53. if len(part.ServiceArns) == 0 || len(part.NextToken) == 0 {
  54. break
  55. }
  56. params["nextToken"] = part.NextToken
  57. }
  58. return ret, nil
  59. }
  60. func (self *SRegion) ListTasks(cluster string) ([]string, error) {
  61. params := map[string]interface{}{
  62. "cluster": cluster,
  63. "maxResults": 100,
  64. }
  65. ret := []string{}
  66. for {
  67. part := struct {
  68. TaskArns []string
  69. NextToken string
  70. }{}
  71. err := self.ecsRequest("ListTasks", params, &part)
  72. if err != nil {
  73. return nil, err
  74. }
  75. ret = append(ret, part.TaskArns...)
  76. if len(part.TaskArns) == 0 || len(part.NextToken) == 0 {
  77. break
  78. }
  79. params["nextToken"] = part.NextToken
  80. }
  81. return ret, nil
  82. }