@@ -76,3 +76,94 @@ func DeleteProjectAssociation(client *gophercloud.ServiceClient, id string, proj
7676 _ , r .Header , r .Err = gophercloud .ParseResponse (resp , err )
7777 return
7878}
79+
80+ // CreateOptsBuilder allows extensions to add additional parameters to
81+ // the Create request.
82+ type CreateOptsBuilder interface {
83+ ToGroupCreateMap () (map [string ]interface {}, error )
84+ }
85+
86+ // CreateOpts provides options used to create a group.
87+ type CreateOpts struct {
88+ // Name is the name of the new endpoint group.
89+ Name string `json:"name" required:"true"`
90+
91+ // Description is a description of the endpoint group.
92+ Description * string `json:"description,omitempty"`
93+
94+ // Filters are the filters of the endpoint group.
95+ Filters map [string ]interface {} `json:"filters,omitempty"`
96+ }
97+
98+ // ToGroupCreateMap formats a CreateOpts into a create request.
99+ func (opts CreateOpts ) ToGroupCreateMap () (map [string ]interface {}, error ) {
100+ b , err := gophercloud .BuildRequestBody (opts , "endpoint_group" )
101+ if err != nil {
102+ return nil , err
103+ }
104+
105+ return b , nil
106+ }
107+
108+ // Create creates a new endpoint group.
109+ func Create (client * gophercloud.ServiceClient , opts CreateOptsBuilder ) (r CreateResult ) {
110+ b , err := opts .ToGroupCreateMap ()
111+ if err != nil {
112+ r .Err = err
113+ return
114+ }
115+ resp , err := client .Post (createURL (client ), & b , & r .Body , & gophercloud.RequestOpts {
116+ OkCodes : []int {201 },
117+ })
118+ _ , r .Header , r .Err = gophercloud .ParseResponse (resp , err )
119+ return
120+ }
121+
122+ // UpdateOptsBuilder allows extensions to add additional parameters to
123+ // the Update request.
124+ type UpdateOptsBuilder interface {
125+ ToGroupUpdateMap () (map [string ]interface {}, error )
126+ }
127+
128+ // UpdateOpts provides options for updating an endpoint group.
129+ type UpdateOpts struct {
130+ // Name is the name of the endpoint group.
131+ Name string `json:"name,omitempty"`
132+
133+ // Description is a description of the endpoint group.
134+ Description * string `json:"description,omitempty"`
135+
136+ // Filters are the filters of the endpoint group.
137+ Filters map [string ]interface {} `json:"filters,omitempty"`
138+ }
139+
140+ // ToGroupUpdateMap formats a UpdateOpts into an update request.
141+ func (opts UpdateOpts ) ToGroupUpdateMap () (map [string ]interface {}, error ) {
142+ b , err := gophercloud .BuildRequestBody (opts , "endpoint_group" )
143+ if err != nil {
144+ return nil , err
145+ }
146+
147+ return b , nil
148+ }
149+
150+ // Update updates an existing Endpoint Group.
151+ func Update (client * gophercloud.ServiceClient , groupID string , opts UpdateOptsBuilder ) (r UpdateResult ) {
152+ b , err := opts .ToGroupUpdateMap ()
153+ if err != nil {
154+ r .Err = err
155+ return
156+ }
157+ resp , err := client .Patch (updateURL (client , groupID ), & b , & r .Body , & gophercloud.RequestOpts {
158+ OkCodes : []int {200 },
159+ })
160+ _ , r .Header , r .Err = gophercloud .ParseResponse (resp , err )
161+ return
162+ }
163+
164+ // Delete deletes an endpoint group.
165+ func Delete (client * gophercloud.ServiceClient , groupID string ) (r DeleteResult ) {
166+ resp , err := client .Delete (deleteURL (client , groupID ), nil )
167+ _ , r .Header , r .Err = gophercloud .ParseResponse (resp , err )
168+ return
169+ }
0 commit comments