@@ -192,6 +192,45 @@ func AddAccess(client *gophercloud.ServiceClient, id string, opts AddAccessOptsB
192192 return
193193}
194194
195+ // ExtraSpecs requests all the extra-specs for the given flavor ID.
196+ func ListExtraSpecs (client * gophercloud.ServiceClient , flavorID string ) (r ListExtraSpecsResult ) {
197+ _ , r .Err = client .Get (extraSpecsListURL (client , flavorID ), & r .Body , nil )
198+ return
199+ }
200+
201+ func GetExtraSpec (client * gophercloud.ServiceClient , flavorID string , key string ) (r GetExtraSpecResult ) {
202+ _ , r .Err = client .Get (extraSpecsGetURL (client , flavorID , key ), & r .Body , nil )
203+ return
204+ }
205+
206+ // CreateExtraSpecsOptsBuilder allows extensions to add additional parameters to the
207+ // CreateExtraSpecs requests.
208+ type CreateExtraSpecsOptsBuilder interface {
209+ ToExtraSpecsCreateMap () (map [string ]interface {}, error )
210+ }
211+
212+ // ExtraSpecsOpts is a map that contains key-value pairs.
213+ type ExtraSpecsOpts map [string ]string
214+
215+ // ToExtraSpecsCreateMap assembles a body for a Create request based on the
216+ // contents of a ExtraSpecsOpts
217+ func (opts ExtraSpecsOpts ) ToExtraSpecsCreateMap () (map [string ]interface {}, error ) {
218+ return map [string ]interface {}{"extra_specs" : opts }, nil
219+ }
220+
221+ // CreateExtraSpecs will create or update the extra-specs key-value pairs for the specified Flavor
222+ func CreateExtraSpecs (client * gophercloud.ServiceClient , flavorID string , opts CreateExtraSpecsOptsBuilder ) (r CreateExtraSpecsResult ) {
223+ b , err := opts .ToExtraSpecsCreateMap ()
224+ if err != nil {
225+ r .Err = err
226+ return
227+ }
228+ _ , r .Err = client .Post (extraSpecsCreateURL (client , flavorID ), b , & r .Body , & gophercloud.RequestOpts {
229+ OkCodes : []int {200 },
230+ })
231+ return
232+ }
233+
195234// IDFromName is a convienience function that returns a flavor's ID given its
196235// name.
197236func IDFromName (client * gophercloud.ServiceClient , name string ) (string , error ) {
@@ -230,14 +269,3 @@ func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)
230269 return "" , err
231270 }
232271}
233-
234- // ExtraSpecs requests all the extra-specs for the given flavor ID.
235- func ListExtraSpecs (client * gophercloud.ServiceClient , flavorID string ) (r ListExtraSpecsResult ) {
236- _ , r .Err = client .Get (extraSpecsListURL (client , flavorID ), & r .Body , nil )
237- return
238- }
239-
240- func GetExtraSpec (client * gophercloud.ServiceClient , flavorID string , key string ) (r GetExtraSpecResult ) {
241- _ , r .Err = client .Get (extraSpecsGetURL (client , flavorID , key ), & r .Body , nil )
242- return
243- }
0 commit comments