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

     1  package bgpvpns
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the List
     9  // request.
    10  type ListOptsBuilder interface {
    11  	ToBGPVPNListQuery() (string, error)
    12  }
    13  
    14  // ListOpts allows the filtering and sorting of paginated collections through the API.
    15  type ListOpts struct {
    16  	Fields    []string `q:"fields"`
    17  	ProjectID string   `q:"project_id"`
    18  	Networks  []string `q:"networks"`
    19  	Routers   []string `q:"routers"`
    20  	Ports     []string `q:"ports"`
    21  	Limit     int      `q:"limit"`
    22  	Marker    string   `q:"marker"`
    23  }
    24  
    25  // ToBGPVPNListQuery formats a ListOpts into a query string.
    26  func (opts ListOpts) ToBGPVPNListQuery() (string, error) {
    27  	q, err := gophercloud.BuildQueryString(opts)
    28  	if err != nil {
    29  		return "", err
    30  	}
    31  	return q.String(), nil
    32  }
    33  
    34  // List the BGP VPNs
    35  func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    36  	url := listURL(c)
    37  	query, err := opts.ToBGPVPNListQuery()
    38  	if err != nil {
    39  		return pagination.Pager{Err: err}
    40  	}
    41  	url += query
    42  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    43  		p := BGPVPNPage{pagination.MarkerPageBase{PageResult: r}}
    44  		p.MarkerPageBase.Owner = p
    45  		return p
    46  	})
    47  }
    48  
    49  // Get retrieve the specific BGP VPN by its uuid
    50  func Get(c *gophercloud.ServiceClient, id string) (r GetResult) {
    51  	resp, err := c.Get(getURL(c, id), &r.Body, nil)
    52  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    53  	return
    54  }
    55  
    56  // CreateOptsBuilder allows extensions to add additional parameters to the
    57  // Create request.
    58  type CreateOptsBuilder interface {
    59  	ToBGPVPNCreateMap() (map[string]interface{}, error)
    60  }
    61  
    62  // CreateOpts represents options used to create a BGP VPN.
    63  type CreateOpts struct {
    64  	Name                string   `json:"name,omitempty"`
    65  	RouteDistinguishers []string `json:"route_distinguishers,omitempty"`
    66  	RouteTargets        []string `json:"route_targets,omitempty"`
    67  	ImportTargets       []string `json:"import_targets,omitempty"`
    68  	ExportTargets       []string `json:"export_targets,omitempty"`
    69  	LocalPref           int      `json:"local_pref,omitempty"`
    70  	VNI                 int      `json:"vni,omitempty"`
    71  	TenantID            string   `json:"tenant_id,omitempty"`
    72  	ProjectID           string   `json:"project_id,omitempty"`
    73  	Type                string   `json:"type,omitempty"`
    74  }
    75  
    76  // ToBGPVPNCreateMap builds a request body from CreateOpts.
    77  func (opts CreateOpts) ToBGPVPNCreateMap() (map[string]interface{}, error) {
    78  	return gophercloud.BuildRequestBody(opts, "bgpvpn")
    79  }
    80  
    81  // Create a BGP VPN
    82  func Create(c *gophercloud.ServiceClient, opts CreateOpts) (r CreateResult) {
    83  	b, err := opts.ToBGPVPNCreateMap()
    84  	if err != nil {
    85  		r.Err = err
    86  		return
    87  	}
    88  	resp, err := c.Post(createURL(c), b, &r.Body, nil)
    89  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    90  	return
    91  }
    92  
    93  // Delete accepts a unique ID and deletes the BGP VPN associated with it.
    94  func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) {
    95  	resp, err := c.Delete(deleteURL(c, id), nil)
    96  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    97  	return
    98  }
    99  
   100  // UpdateOptsBuilder allows extensions to add additional parameters to the
   101  // Update request.
   102  type UpdateOptsBuilder interface {
   103  	ToBGPVPNUpdateMap() (map[string]interface{}, error)
   104  }
   105  
   106  // UpdateOpts represents options used to update a BGP VPN.
   107  type UpdateOpts struct {
   108  	Name                *string   `json:"name,omitempty"`
   109  	RouteDistinguishers *[]string `json:"route_distinguishers,omitempty"`
   110  	RouteTargets        *[]string `json:"route_targets,omitempty"`
   111  	ImportTargets       *[]string `json:"import_targets,omitempty"`
   112  	ExportTargets       *[]string `json:"export_targets,omitempty"`
   113  	LocalPref           *int      `json:"local_pref,omitempty"`
   114  }
   115  
   116  // ToBGPVPNUpdateMap builds a request body from UpdateOpts.
   117  func (opts UpdateOpts) ToBGPVPNUpdateMap() (map[string]interface{}, error) {
   118  	return gophercloud.BuildRequestBody(opts, "bgpvpn")
   119  }
   120  
   121  // Update accept a BGP VPN ID and an UpdateOpts and update the BGP VPN
   122  func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
   123  	b, err := opts.ToBGPVPNUpdateMap()
   124  	if err != nil {
   125  		r.Err = err
   126  		return
   127  	}
   128  	resp, err := c.Put(updateURL(c, id), b, &r.Body, &gophercloud.RequestOpts{
   129  		OkCodes: []int{200},
   130  	})
   131  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   132  	return
   133  }
   134  
   135  // ListNetworkAssociationsOptsBuilder allows extensions to add additional
   136  // parameters to the ListNetworkAssociations request.
   137  type ListNetworkAssociationsOptsBuilder interface {
   138  	ToNetworkAssociationsListQuery() (string, error)
   139  }
   140  
   141  // ListNetworkAssociationsOpts allows the filtering and sorting of paginated
   142  // collections through the API.
   143  type ListNetworkAssociationsOpts struct {
   144  	Fields []string `q:"fields"`
   145  	Limit  int      `q:"limit"`
   146  	Marker string   `q:"marker"`
   147  }
   148  
   149  // ToNetworkAssociationsListQuery formats a ListNetworkAssociationsOpts into a
   150  // query string.
   151  func (opts ListNetworkAssociationsOpts) ToNetworkAssociationsListQuery() (string, error) {
   152  	q, err := gophercloud.BuildQueryString(opts)
   153  	if err != nil {
   154  		return "", err
   155  	}
   156  	return q.String(), nil
   157  }
   158  
   159  // ListNetworkAssociations pages over the network associations of a specified
   160  // BGP VPN.
   161  func ListNetworkAssociations(c *gophercloud.ServiceClient, id string, opts ListNetworkAssociationsOptsBuilder) pagination.Pager {
   162  	url := listNetworkAssociationsURL(c, id)
   163  	query, err := opts.ToNetworkAssociationsListQuery()
   164  	if err != nil {
   165  		return pagination.Pager{Err: err}
   166  	}
   167  	url += query
   168  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   169  		p := NetworkAssociationPage{pagination.MarkerPageBase{PageResult: r}}
   170  		p.MarkerPageBase.Owner = p
   171  		return p
   172  	})
   173  }
   174  
   175  // CreateNetworkAssociationOptsBuilder allows extensions to add additional
   176  // parameters to the CreateNetworkAssociation request.
   177  type CreateNetworkAssociationOptsBuilder interface {
   178  	ToNetworkAssociationCreateMap() (map[string]interface{}, error)
   179  }
   180  
   181  // CreateNetworkAssociationOpts represents options used to create a BGP VPN
   182  // network association.
   183  type CreateNetworkAssociationOpts struct {
   184  	NetworkID string `json:"network_id" required:"true"`
   185  	TenantID  string `json:"tenant_id,omitempty"`
   186  	ProjectID string `json:"project_id,omitempty"`
   187  }
   188  
   189  // ToNetworkAssociationCreateMap builds a request body from
   190  // CreateNetworkAssociationOpts.
   191  func (opts CreateNetworkAssociationOpts) ToNetworkAssociationCreateMap() (map[string]interface{}, error) {
   192  	return gophercloud.BuildRequestBody(opts, "network_association")
   193  }
   194  
   195  // CreateNetworkAssociation creates a new network association for a specified
   196  // BGP VPN.
   197  func CreateNetworkAssociation(client *gophercloud.ServiceClient, id string, opts CreateNetworkAssociationOptsBuilder) (r CreateNetworkAssociationResult) {
   198  	b, err := opts.ToNetworkAssociationCreateMap()
   199  	if err != nil {
   200  		r.Err = err
   201  		return
   202  	}
   203  	resp, err := client.Post(createNetworkAssociationURL(client, id), b, &r.Body, nil)
   204  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   205  	return
   206  }
   207  
   208  // GetNetworkAssociation retrieves a specific network association by BGP VPN id
   209  // and network association id.
   210  func GetNetworkAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r GetNetworkAssociationResult) {
   211  	resp, err := c.Get(getNetworkAssociationURL(c, bgpVpnID, id), &r.Body, nil)
   212  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   213  	return
   214  }
   215  
   216  // DeleteNetworkAssociation deletes a specific network association by BGP VPN id
   217  // and network association id.
   218  func DeleteNetworkAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r DeleteNetworkAssociationResult) {
   219  	resp, err := c.Delete(deleteNetworkAssociationURL(c, bgpVpnID, id), nil)
   220  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   221  	return
   222  }
   223  
   224  // ListRouterAssociationsOptsBuilder allows extensions to add additional
   225  // parameters to the ListRouterAssociations request.
   226  type ListRouterAssociationsOptsBuilder interface {
   227  	ToRouterAssociationsListQuery() (string, error)
   228  }
   229  
   230  // ListRouterAssociationsOpts allows the filtering and sorting of paginated
   231  // collections through the API.
   232  type ListRouterAssociationsOpts struct {
   233  	Fields []string `q:"fields"`
   234  	Limit  int      `q:"limit"`
   235  	Marker string   `q:"marker"`
   236  }
   237  
   238  // ToRouterAssociationsListQuery formats a ListRouterAssociationsOpts into a
   239  // query string.
   240  func (opts ListRouterAssociationsOpts) ToRouterAssociationsListQuery() (string, error) {
   241  	q, err := gophercloud.BuildQueryString(opts)
   242  	if err != nil {
   243  		return "", err
   244  	}
   245  	return q.String(), nil
   246  }
   247  
   248  // ListRouterAssociations pages over the router associations of a specified
   249  // BGP VPN.
   250  func ListRouterAssociations(c *gophercloud.ServiceClient, id string, opts ListRouterAssociationsOptsBuilder) pagination.Pager {
   251  	url := listRouterAssociationsURL(c, id)
   252  	query, err := opts.ToRouterAssociationsListQuery()
   253  	if err != nil {
   254  		return pagination.Pager{Err: err}
   255  	}
   256  	url += query
   257  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   258  		p := RouterAssociationPage{pagination.MarkerPageBase{PageResult: r}}
   259  		p.MarkerPageBase.Owner = p
   260  		return p
   261  	})
   262  }
   263  
   264  // CreateRouterAssociationOptsBuilder allows extensions to add additional
   265  // parameters to the CreateRouterAssociation request.
   266  type CreateRouterAssociationOptsBuilder interface {
   267  	ToRouterAssociationCreateMap() (map[string]interface{}, error)
   268  }
   269  
   270  // CreateRouterAssociationOpts represents options used to create a BGP VPN
   271  // router association.
   272  type CreateRouterAssociationOpts struct {
   273  	RouterID             string `json:"router_id" required:"true"`
   274  	AdvertiseExtraRoutes *bool  `json:"advertise_extra_routes,omitempty"`
   275  	TenantID             string `json:"tenant_id,omitempty"`
   276  	ProjectID            string `json:"project_id,omitempty"`
   277  }
   278  
   279  // ToRouterAssociationCreateMap builds a request body from
   280  // CreateRouterAssociationOpts.
   281  func (opts CreateRouterAssociationOpts) ToRouterAssociationCreateMap() (map[string]interface{}, error) {
   282  	return gophercloud.BuildRequestBody(opts, "router_association")
   283  }
   284  
   285  // CreateRouterAssociation creates a new router association for a specified
   286  // BGP VPN.
   287  func CreateRouterAssociation(client *gophercloud.ServiceClient, id string, opts CreateRouterAssociationOptsBuilder) (r CreateRouterAssociationResult) {
   288  	b, err := opts.ToRouterAssociationCreateMap()
   289  	if err != nil {
   290  		r.Err = err
   291  		return
   292  	}
   293  	resp, err := client.Post(createRouterAssociationURL(client, id), b, &r.Body, nil)
   294  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   295  	return
   296  }
   297  
   298  // GetRouterAssociation retrieves a specific router association by BGP VPN id
   299  // and router association id.
   300  func GetRouterAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r GetRouterAssociationResult) {
   301  	resp, err := c.Get(getRouterAssociationURL(c, bgpVpnID, id), &r.Body, nil)
   302  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   303  	return
   304  }
   305  
   306  // DeleteRouterAssociation deletes a specific router association by BGP VPN id
   307  // and router association id.
   308  func DeleteRouterAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r DeleteRouterAssociationResult) {
   309  	resp, err := c.Delete(deleteRouterAssociationURL(c, bgpVpnID, id), nil)
   310  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   311  	return
   312  }
   313  
   314  // UpdateRouterAssociationOptsBuilder allows extensions to add additional
   315  // parameters to the UpdateRouterAssociation request.
   316  type UpdateRouterAssociationOptsBuilder interface {
   317  	ToRouterAssociationUpdateMap() (map[string]interface{}, error)
   318  }
   319  
   320  // UpdateRouterAssociationOpts represents options used to update a BGP VPN
   321  // router association.
   322  type UpdateRouterAssociationOpts struct {
   323  	AdvertiseExtraRoutes *bool `json:"advertise_extra_routes,omitempty"`
   324  }
   325  
   326  // ToRouterAssociationUpdateMap builds a request body from
   327  // UpdateRouterAssociationOpts.
   328  func (opts UpdateRouterAssociationOpts) ToRouterAssociationUpdateMap() (map[string]interface{}, error) {
   329  	return gophercloud.BuildRequestBody(opts, "router_association")
   330  }
   331  
   332  // UpdateRouterAssociation updates a router association for a specified BGP VPN.
   333  func UpdateRouterAssociation(client *gophercloud.ServiceClient, bgpVpnID string, id string, opts UpdateRouterAssociationOptsBuilder) (r UpdateRouterAssociationResult) {
   334  	b, err := opts.ToRouterAssociationUpdateMap()
   335  	if err != nil {
   336  		r.Err = err
   337  		return
   338  	}
   339  	resp, err := client.Put(updateRouterAssociationURL(client, bgpVpnID, id), b, &r.Body, &gophercloud.RequestOpts{
   340  		OkCodes: []int{200},
   341  	})
   342  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   343  	return
   344  }
   345  
   346  // ListPortAssociationsOptsBuilder allows extensions to add additional
   347  // parameters to the ListPortAssociations request.
   348  type ListPortAssociationsOptsBuilder interface {
   349  	ToPortAssociationsListQuery() (string, error)
   350  }
   351  
   352  // ListPortAssociationsOpts allows the filtering and sorting of paginated
   353  // collections through the API.
   354  type ListPortAssociationsOpts struct {
   355  	Fields []string `q:"fields"`
   356  	Limit  int      `q:"limit"`
   357  	Marker string   `q:"marker"`
   358  }
   359  
   360  // ToPortAssociationsListQuery formats a ListPortAssociationsOpts into a
   361  // query string.
   362  func (opts ListPortAssociationsOpts) ToPortAssociationsListQuery() (string, error) {
   363  	q, err := gophercloud.BuildQueryString(opts)
   364  	if err != nil {
   365  		return "", err
   366  	}
   367  	return q.String(), nil
   368  }
   369  
   370  // ListPortAssociations pages over the port associations of a specified
   371  // BGP VPN.
   372  func ListPortAssociations(c *gophercloud.ServiceClient, id string, opts ListPortAssociationsOptsBuilder) pagination.Pager {
   373  	url := listPortAssociationsURL(c, id)
   374  	query, err := opts.ToPortAssociationsListQuery()
   375  	if err != nil {
   376  		return pagination.Pager{Err: err}
   377  	}
   378  	url += query
   379  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
   380  		p := PortAssociationPage{pagination.MarkerPageBase{PageResult: r}}
   381  		p.MarkerPageBase.Owner = p
   382  		return p
   383  	})
   384  }
   385  
   386  // PortRoutes represents the routes to be advertised by a BGP VPN port
   387  type PortRoutes struct {
   388  	Type      string `json:"type" required:"true"`
   389  	Prefix    string `json:"prefix,omitempty"`
   390  	BGPVPNID  string `json:"bgpvpn_id,omitempty"`
   391  	LocalPref *int   `json:"local_pref,omitempty"`
   392  }
   393  
   394  // CreatePortAssociationOptsBuilder allows extensions to add additional
   395  // parameters to the CreatePortAssociation request.
   396  type CreatePortAssociationOptsBuilder interface {
   397  	ToPortAssociationCreateMap() (map[string]interface{}, error)
   398  }
   399  
   400  // CreatePortAssociationOpts represents options used to create a BGP VPN
   401  // port association.
   402  type CreatePortAssociationOpts struct {
   403  	PortID            string       `json:"port_id" required:"true"`
   404  	Routes            []PortRoutes `json:"routes,omitempty"`
   405  	AdvertiseFixedIPs *bool        `json:"advertise_fixed_ips,omitempty"`
   406  	TenantID          string       `json:"tenant_id,omitempty"`
   407  	ProjectID         string       `json:"project_id,omitempty"`
   408  }
   409  
   410  // ToPortAssociationCreateMap builds a request body from
   411  // CreatePortAssociationOpts.
   412  func (opts CreatePortAssociationOpts) ToPortAssociationCreateMap() (map[string]interface{}, error) {
   413  	return gophercloud.BuildRequestBody(opts, "port_association")
   414  }
   415  
   416  // CreatePortAssociation creates a new port association for a specified
   417  // BGP VPN.
   418  func CreatePortAssociation(client *gophercloud.ServiceClient, id string, opts CreatePortAssociationOptsBuilder) (r CreatePortAssociationResult) {
   419  	b, err := opts.ToPortAssociationCreateMap()
   420  	if err != nil {
   421  		r.Err = err
   422  		return
   423  	}
   424  	resp, err := client.Post(createPortAssociationURL(client, id), b, &r.Body, nil)
   425  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   426  	return
   427  }
   428  
   429  // GetPortAssociation retrieves a specific port association by BGP VPN id
   430  // and port association id.
   431  func GetPortAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r GetPortAssociationResult) {
   432  	resp, err := c.Get(getPortAssociationURL(c, bgpVpnID, id), &r.Body, nil)
   433  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   434  	return
   435  }
   436  
   437  // DeletePortAssociation deletes a specific port association by BGP VPN id
   438  // and port association id.
   439  func DeletePortAssociation(c *gophercloud.ServiceClient, bgpVpnID string, id string) (r DeletePortAssociationResult) {
   440  	resp, err := c.Delete(deletePortAssociationURL(c, bgpVpnID, id), nil)
   441  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   442  	return
   443  }
   444  
   445  // UpdatePortAssociationOptsBuilder allows extensions to add additional
   446  // parameters to the UpdatePortAssociation request.
   447  type UpdatePortAssociationOptsBuilder interface {
   448  	ToPortAssociationUpdateMap() (map[string]interface{}, error)
   449  }
   450  
   451  // UpdatePortAssociationOpts represents options used to update a BGP VPN
   452  // port association.
   453  type UpdatePortAssociationOpts struct {
   454  	Routes            *[]PortRoutes `json:"routes,omitempty"`
   455  	AdvertiseFixedIPs *bool         `json:"advertise_fixed_ips,omitempty"`
   456  }
   457  
   458  // ToPortAssociationUpdateMap builds a request body from
   459  // UpdatePortAssociationOpts.
   460  func (opts UpdatePortAssociationOpts) ToPortAssociationUpdateMap() (map[string]interface{}, error) {
   461  	return gophercloud.BuildRequestBody(opts, "port_association")
   462  }
   463  
   464  // UpdatePortAssociation updates a port association for a specified BGP VPN.
   465  func UpdatePortAssociation(client *gophercloud.ServiceClient, bgpVpnID string, id string, opts UpdatePortAssociationOptsBuilder) (r UpdatePortAssociationResult) {
   466  	b, err := opts.ToPortAssociationUpdateMap()
   467  	if err != nil {
   468  		r.Err = err
   469  		return
   470  	}
   471  	resp, err := client.Put(updatePortAssociationURL(client, bgpVpnID, id), b, &r.Body, &gophercloud.RequestOpts{
   472  		OkCodes: []int{200},
   473  	})
   474  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   475  	return
   476  }