github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/routetables/Create.go (about)

     1  package routetables
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateOpts struct {
    10  	// The VPC ID that the route table belongs to
    11  	VpcID string `json:"vpc_id" required:"true"`
    12  	// The name of the route table. The name can contain a maximum of 64 characters,
    13  	// which may consist of letters, digits, underscores (_), hyphens (-), and periods (.).
    14  	// The name cannot contain spaces.
    15  	Name string `json:"name" required:"true"`
    16  	// The supplementary information about the route table. The description can contain
    17  	// a maximum of 255 characters and cannot contain angle brackets (< or >).
    18  	Description string `json:"description,omitempty"`
    19  	// The route information
    20  	Routes []RouteOpts `json:"routes,omitempty"`
    21  }
    22  
    23  // RouteOpts contains all the values needed to manage a vpc route
    24  type RouteOpts struct {
    25  	// The destination CIDR block. The destination of each route must be unique.
    26  	// The destination cannot overlap with any subnet CIDR block in the VPC.
    27  	Destination string `json:"destination" required:"true"`
    28  	// the type of the next hop. value range:
    29  	// ecs, eni, vip, nat, peering, vpn, dc, cc, egw
    30  	Type string `json:"type" required:"true"`
    31  	// the instance ID of next hop
    32  	NextHop string `json:"nexthop" required:"true"`
    33  	// The supplementary information about the route. The description can contain
    34  	// a maximum of 255 characters and cannot contain angle brackets (< or >).
    35  	Description *string `json:"description,omitempty"`
    36  }
    37  
    38  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*RouteTable, error) {
    39  	b, err := build.RequestBody(opts, "routetable")
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	raw, err := client.Post(client.ServiceURL(client.ProjectID, "routetables"), b, nil, &golangsdk.RequestOpts{
    45  		OkCodes: []int{200},
    46  	})
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	var res RouteTable
    52  	err = extract.IntoStructPtr(raw.Body, &res, "routetable")
    53  	return &res, err
    54  }
    55  
    56  // RouteTable represents a route table
    57  type RouteTable struct {
    58  	// Name is the human-readable name for the route table
    59  	Name string `json:"name"`
    60  	// Description is the supplementary information about the route table
    61  	Description string `json:"description"`
    62  	// ID is the unique identifier for the route table
    63  	ID string `json:"id"`
    64  	// the VPC ID that the route table belongs to.
    65  	VpcID string `json:"vpc_id"`
    66  	// project id
    67  	TenantID string `json:"tenant_id"`
    68  	// Default indicates whether it is a default route table
    69  	Default bool `json:"default"`
    70  	// Routes is an array of static routes that the route table will host
    71  	Routes []Route `json:"routes"`
    72  	// Subnets is an array of subnets that associated with the route table
    73  	Subnets []Subnet `json:"subnets"`
    74  	// Specifies the time (UTC) when the route table is created.
    75  	CreatedAt string `json:"created_at"`
    76  	// Specifies the time (UTC) when the route table is updated.
    77  	UpdatedAt string `json:"updated_at"`
    78  }
    79  
    80  // Route represents a route object in a route table
    81  type Route struct {
    82  	Type            string `json:"type"`
    83  	DestinationCIDR string `json:"destination"`
    84  	NextHop         string `json:"nexthop"`
    85  	Description     string `json:"description"`
    86  }
    87  
    88  // Subnet represents a subnet object associated with a route table
    89  type Subnet struct {
    90  	ID string `json:"id"`
    91  }