github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/vpc/v3/vpcs/AddSecondaryCIDR.go (about)

     1  package vpcs
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type AddExtendCidrOption struct {
    10  	// Secondary CIDR blocks that can be added to VPCs
    11  	// The value cannot contain the following:
    12  	// 100.64.0.0/10
    13  	// 214.0.0.0/7
    14  	// 198.18.0.0/15
    15  	// 169.254.0.0/16
    16  	// 0.0.0.0/8
    17  	// 127.0.0.0/8
    18  	// 240.0.0.0/4
    19  	// 172.31.0.0/16
    20  	// 192.168.0.0/16
    21  	// Currently, only one secondary CIDR block can be added to each VPC.
    22  	ExtendCidrs []string `json:"extend_cidrs"`
    23  }
    24  
    25  type CidrOpts struct {
    26  	// Whether to only check the request.
    27  	// Value range:
    28  	// true: Only the check request will be sent and no secondary CIDR block will be added.
    29  	// Check items include mandatory parameters, request format, and constraints.
    30  	// If the check fails, an error will be returned. If the check succeeds, response code 202 will be returned.
    31  	// false (default value): A request will be sent and a secondary CIDR block will be added.
    32  	DryRun *bool `json:"dry_run,omitempty"`
    33  	// Request body for adding a secondary CIDR block.
    34  	Vpc *AddExtendCidrOption `json:"vpc"`
    35  }
    36  
    37  // AddSecondaryCidr is used to add a secondary CIDR block to a VPC.
    38  func AddSecondaryCidr(client *golangsdk.ServiceClient, id string, opts CidrOpts) (*Vpc, error) {
    39  	b, err := build.RequestBody(opts, "")
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	// PUT /v3/{project_id}/vpc/vpcs/{vpc_id}/add-extend-cidr
    45  	raw, err := client.Put(client.ServiceURL("vpcs", id, "add-extend-cidr"), b, nil, &golangsdk.RequestOpts{
    46  		OkCodes: []int{200},
    47  	})
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	var res Vpc
    53  	err = extract.IntoStructPtr(raw.Body, &res, "vpc")
    54  	return &res, err
    55  }