github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/networking/v2/peeringconnectionrequests/requests.go (about)

     1  package peeringconnectionrequests
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     8  )
     9  
    10  type ListOptsBuilder interface {
    11  	ToPeeringConnectionRequestListQuery() (string, error)
    12  }
    13  
    14  type ListOpts struct {
    15  }
    16  
    17  func (opts ListOpts) ToPeeringConnectionRequestListQuery() (string, error) {
    18  	q, err := gophercloud.BuildQueryString(opts)
    19  	return q.String(), err
    20  }
    21  
    22  func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    23  	url := listURL(c)
    24  	if opts != nil {
    25  		query, err := opts.ToPeeringConnectionRequestListQuery()
    26  		if err != nil {
    27  			return pagination.Pager{Err: err}
    28  		}
    29  		url += query
    30  	}
    31  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    32  		return PeeringConnectionRequestPage{pagination.LinkedPageBase{PageResult: r}}
    33  	})
    34  }
    35  
    36  func Get(ctx context.Context, c *gophercloud.ServiceClient, id string) (r GetResult) {
    37  	resp, err := c.Get(ctx, getURL(c, id), &r.Body, nil)
    38  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    39  	return
    40  }
    41  
    42  type CreateOptsBuilder interface {
    43  	ToPeeringConnectionCreateMap() (map[string]any, error)
    44  }
    45  
    46  type CreateOpts struct {
    47  	PeerVPCId   string `json:"dest_vpc_id,omitempty"`
    48  	PeerOrgId   string `json:"dest_org_id,omitempty"`
    49  	VPCId       string `json:"src_vpc_id,omitempty"`
    50  	Description string `json:"description,omitempty"`
    51  }
    52  
    53  func (opts CreateOpts) ToPeeringConnectionCreateMap() (map[string]any, error) {
    54  	return gophercloud.BuildRequestBody(opts, "peering_connection_request")
    55  }
    56  
    57  func Create(ctx context.Context, c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    58  	b, err := opts.ToPeeringConnectionCreateMap()
    59  	if err != nil {
    60  		r.Err = err
    61  		return
    62  	}
    63  
    64  	resp, err := c.Post(ctx, createURL(c), b, &r.Body, nil)
    65  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    66  	return
    67  }