provider/openstack: gophercloud migration: Add a BuildRequest function, and refactor types 'SubnetCreateMap' function to use

This commit is contained in:
Gavin Williams 2016-10-03 19:12:28 +01:00 committed by Joe Topjian
parent edf80d2ae1
commit 1eab2121ad
2 changed files with 19 additions and 12 deletions

View File

@ -14,16 +14,5 @@ type SubnetCreateOpts struct {
// ToSubnetCreateMap casts a CreateOpts struct to a map.
// It overrides subnets.ToSubnetCreateMap to add the ValueSpecs field.
func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
if opts.ValueSpecs != nil {
for k, v := range opts.ValueSpecs {
b[k] = v
}
}
return map[string]interface{}{"subnet": b}, nil
return BuildRequest(opts, "subnet")
}

View File

@ -17,3 +17,21 @@ func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
return fmt.Errorf("%s: %s", msg, err)
}
// BuildRequest takes an opts struct and builds a request body for
// Gophercloud to execute
func BuildRequest(opts interface{}, parent string) (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
if opts.ValueSpecs != nil {
for k, v := range opts.ValueSpecs {
b[k] = v
}
delete(b, "value_specs")
}
return map[string]interface{}{parent: b}, nil
}