github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/external/requests.go (about)

     1  package external
     2  
     3  import (
     4  	"net/url"
     5  	"strconv"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/networks"
     9  )
    10  
    11  // ListOptsExt adds the external network options to the base ListOpts.
    12  type ListOptsExt struct {
    13  	networks.ListOptsBuilder
    14  	External *bool `q:"router:external"`
    15  }
    16  
    17  // ToNetworkListQuery adds the router:external option to the base network
    18  // list options.
    19  func (opts ListOptsExt) ToNetworkListQuery() (string, error) {
    20  	q, err := golangsdk.BuildQueryString(opts.ListOptsBuilder)
    21  	if err != nil {
    22  		return "", err
    23  	}
    24  
    25  	params := q.Query()
    26  	if opts.External != nil {
    27  		v := strconv.FormatBool(*opts.External)
    28  		params.Add("router:external", 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 external network
    36  // resources. It embeds networks.CreateOpts and so inherits all of its required
    37  // and optional fields, with the addition of the External field.
    38  type CreateOptsExt struct {
    39  	networks.CreateOptsBuilder
    40  	External *bool `json:"router:external,omitempty"`
    41  }
    42  
    43  // ToNetworkCreateMap adds the router:external options 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.External == nil {
    52  		return base, nil
    53  	}
    54  
    55  	networkMap := base["network"].(map[string]interface{})
    56  	networkMap["router:external"] = opts.External
    57  
    58  	return base, nil
    59  }
    60  
    61  // UpdateOptsExt is the structure used when updating existing external network
    62  // resources. It embeds networks.UpdateOpts and so inherits all of its required
    63  // and optional fields, with the addition of the External field.
    64  type UpdateOptsExt struct {
    65  	networks.UpdateOptsBuilder
    66  	External *bool `json:"router:external,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.External == nil {
    77  		return base, nil
    78  	}
    79  
    80  	networkMap := base["network"].(map[string]interface{})
    81  	networkMap["router:external"] = opts.External
    82  
    83  	return base, nil
    84  }