provider/openstack: gophercloud migration: Add a BuildRequest function, and refactor types 'SubnetCreateMap' function to use
This commit is contained in:
parent
edf80d2ae1
commit
1eab2121ad
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue