github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/vlantransparent/requests.go (about)

     1  package vlantransparent
     2  
     3  import (
     4  	"net/url"
     5  	"strconv"
     6  
     7  	"github.com/gophercloud/gophercloud"
     8  	"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
     9  )
    10  
    11  // ListOptsExt adds the vlan-transparent network options to the base ListOpts.
    12  type ListOptsExt struct {
    13  	networks.ListOptsBuilder
    14  	VLANTransparent *bool `q:"vlan_transparent"`
    15  }
    16  
    17  // ToNetworkListQuery adds the vlan_transparent option to the base network
    18  // list options.
    19  func (opts ListOptsExt) ToNetworkListQuery() (string, error) {
    20  	q, err := gophercloud.BuildQueryString(opts.ListOptsBuilder)
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  
    25  	params := q.Query()
    26  	if opts.VLANTransparent != nil {
    27  		v := strconv.FormatBool(*opts.VLANTransparent)
    28  		params.Add("vlan_transparent", v)
    29  	}
    30  
    31  	q = &url.URL{RawQuery: params.Encode()}
    32  	return q.String(), err
    33  }
    34  
    35  // CreateOptsExt is the structure used when creating new vlan-transparent
    36  // network resources. It embeds networks.CreateOpts and so inherits all of its
    37  // required and optional fields, with the addition of the VLANTransparent field.
    38  type CreateOptsExt struct {
    39  	networks.CreateOptsBuilder
    40  	VLANTransparent *bool `json:"vlan_transparent,omitempty"`
    41  }
    42  
    43  // ToNetworkCreateMap adds the vlan_transparent option to the base network
    44  // creation options.
    45  func (opts CreateOptsExt) ToNetworkCreateMap() (map[string]interface{}, error) {
    46  	base, err := opts.CreateOptsBuilder.ToNetworkCreateMap()
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	if opts.VLANTransparent == nil {
    52  		return base, nil
    53  	}
    54  
    55  	networkMap := base["network"].(map[string]interface{})
    56  	networkMap["vlan_transparent"] = opts.VLANTransparent
    57  
    58  	return base, nil
    59  }
    60  
    61  // UpdateOptsExt is the structure used when updating existing vlan-transparent
    62  // network resources. It embeds networks.UpdateOpts and so inherits all of its
    63  // required and optional fields, with the addition of the VLANTransparent field.
    64  type UpdateOptsExt struct {
    65  	networks.UpdateOptsBuilder
    66  	VLANTransparent *bool `json:"vlan_transparent,omitempty"`
    67  }
    68  
    69  // ToNetworkUpdateMap casts an UpdateOpts struct to a map.
    70  func (opts UpdateOptsExt) ToNetworkUpdateMap() (map[string]interface{}, error) {
    71  	base, err := opts.UpdateOptsBuilder.ToNetworkUpdateMap()
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  
    76  	if opts.VLANTransparent == nil {
    77  		return base, nil
    78  	}
    79  
    80  	networkMap := base["network"].(map[string]interface{})
    81  	networkMap["vlan_transparent"] = opts.VLANTransparent
    82  
    83  	return base, nil
    84  }