github.com/IBM-Cloud/bluemix-go@v0.0.0-20240314082800-4e02a69b84b2/api/cis/cisv1/pools.go (about) 1 package cisv1 2 3 import ( 4 "fmt" 5 6 "github.com/IBM-Cloud/bluemix-go/client" 7 ) 8 9 type Pool struct { 10 Id string `json:"id"` 11 Description string `json:"description"` 12 Name string `json:"name"` 13 CheckRegions []string `json:"check_regions"` 14 Enabled bool `json:"enabled"` 15 MinOrigins int `json:"minimum_origins"` 16 Monitor string `json:"monitor"` 17 NotEmail string `json:"notification_email"` 18 Origins []Origin `json:"origins"` 19 Health string `json:"health"` 20 CreatedOn string `json:"created_on"` 21 ModifiedOn string `json:"modified_on"` 22 } 23 24 type CheckRegion struct { 25 Region string `json:"0"` 26 } 27 28 type Origin struct { 29 Name string `json:"name"` 30 Address string `json:"address"` 31 Enabled bool `json:"enabled"` 32 Weight int `json:"weight"` 33 Healthy bool `json:"healthy"` 34 } 35 36 type PoolResults struct { 37 PoolList []Pool `json:"result"` 38 ResultsInfo ResultsCount `json:"result_info"` 39 Success bool `json:"success"` 40 Errors []Error `json:"errors"` 41 } 42 43 type PoolResult struct { 44 Pool Pool `json:"result"` 45 Success bool `json:"success"` 46 Errors []Error `json:"errors"` 47 Messages []string `json:"messages"` 48 } 49 50 type PoolBody struct { 51 Name string `json:"name"` 52 Description string `json:"description,omitempty"` 53 Origins []Origin `json:"origins"` 54 CheckRegions []string `json:"check_regions"` 55 Enabled bool `json:"enabled"` 56 MinOrigins int `json:"minimum_origins,omitempty"` 57 Monitor string `json:"monitor,omitempty"` 58 NotEmail string `json:"notification_email,omitempty"` 59 } 60 61 type PoolDelete struct { 62 Result struct { 63 PoolId string 64 } `json:"result"` 65 Success bool `json:"success"` 66 Errors []Error `json:"errors"` 67 Messages []string `json:"messages"` 68 } 69 70 type Pools interface { 71 ListPools(cisId string) ([]Pool, error) 72 GetPool(cisId string, poolId string) (*Pool, error) 73 CreatePool(cisId string, poolBody PoolBody) (*Pool, error) 74 DeletePool(cisId string, poolId string) error 75 UpdatePool(cisId string, poolId string, poolBody PoolBody) (*Pool, error) 76 } 77 78 type pools struct { 79 client *client.Client 80 } 81 82 func newPoolAPI(c *client.Client) Pools { 83 return &pools{ 84 client: c, 85 } 86 } 87 88 func (r *pools) ListPools(cisId string) ([]Pool, error) { 89 poolResults := PoolResults{} 90 rawURL := fmt.Sprintf("/v1/%s/load_balancers/pools/", cisId) 91 _, err := r.client.Get(rawURL, &poolResults) 92 if err != nil { 93 return nil, err 94 } 95 return poolResults.PoolList, err 96 } 97 98 func (r *pools) GetPool(cisId string, poolId string) (*Pool, error) { 99 poolResult := PoolResult{} 100 rawURL := fmt.Sprintf("/v1/%s/load_balancers/pools/%s", cisId, poolId) 101 _, err := r.client.Get(rawURL, &poolResult, nil) 102 if err != nil { 103 return nil, err 104 } 105 return &poolResult.Pool, nil 106 } 107 108 func (r *pools) DeletePool(cisId string, poolId string) error { 109 rawURL := fmt.Sprintf("/v1/%s/load_balancers/pools/%s", cisId, poolId) 110 _, err := r.client.Delete(rawURL) 111 if err != nil { 112 return err 113 } 114 return nil 115 } 116 117 func (r *pools) CreatePool(cisId string, poolBody PoolBody) (*Pool, error) { 118 poolResult := PoolResult{} 119 rawURL := fmt.Sprintf("/v1/%s/load_balancers/pools/", cisId) 120 _, err := r.client.Post(rawURL, &poolBody, &poolResult) 121 if err != nil { 122 return nil, err 123 } 124 return &poolResult.Pool, nil 125 } 126 127 func (r *pools) UpdatePool(cisId string, poolId string, poolBody PoolBody) (*Pool, error) { 128 poolResult := PoolResult{} 129 rawURL := fmt.Sprintf("/v1/%s/load_balancers/pools/%s", cisId, poolId) 130 _, err := r.client.Put(rawURL, &poolBody, &poolResult) 131 if err != nil { 132 return nil, err 133 } 134 return &poolResult.Pool, nil 135 }