Documentation ¶
Overview ¶
Package trunks provides the ability to retrieve and manage trunks through the Neutron API. Trunks allow you to multiplex multiple ports traffic on a single port. For example, you could have a compute instance port be the parent port of a trunk and inside the VM run workloads using other ports, without the need of plugging those ports.
Example of a new empty Trunk creation
iTrue := true createOpts := trunks.CreateOpts{ Name: "gophertrunk", Description: "Trunk created by gophercloud", AdminStateUp: &iTrue, PortID: "a6f0560c-b7a8-401f-bf6e-d0a5c851ae10", } trunk, err := trunks.Create(networkClient, trunkOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", trunk)
Example of a new Trunk creation with 2 subports
iTrue := true createOpts := trunks.CreateOpts{ Name: "gophertrunk", Description: "Trunk created by gophercloud", AdminStateUp: &iTrue, PortID: "a6f0560c-b7a8-401f-bf6e-d0a5c851ae10", Subports: []trunks.Subport{ { SegmentationID: 1, SegmentationType: "vlan", PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a", }, { SegmentationID: 10, SegmentationType: "vlan", PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112", }, }, } trunk, err := trunks.Create(client, trunkOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", trunk)
Example of deleting a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159" err := trunks.Delete(networkClient, trunkID).ExtractErr() if err != nil { panic(err) }
Example of listing Trunks
listOpts := trunks.ListOpts{} allPages, err := trunks.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } allTrunks, err := trunks.ExtractTrunks(allPages) if err != nil { panic(err) } for _, trunk := range allTrunks { fmt.Printf("%+v\n", trunk) }
Example of getting a Trunk
trunkID = "52d8d124-3dc9-4563-9fef-bad3187ecf2d" trunk, err := trunks.Get(networkClient, trunkID).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", trunk)
Example of updating a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159" subports, err := trunks.GetSubports(client, trunkID).Extract() iFalse := false updateOpts := trunks.UpdateOpts{ AdminStateUp: &iFalse, Name: "updated_gophertrunk", Description: "trunk updated by gophercloud", } trunk, err = trunks.Update(networkClient, trunkID, updateOpts).Extract() if err != nil { log.Fatal(err) } fmt.Printf("%+v\n", trunk)
Example of showing subports of a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159" subports, err := trunks.GetSubports(client, trunkID).Extract() fmt.Printf("%+v\n", subports)
Example of adding two subports to a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159" addSubportsOpts := trunks.AddSubportsOpts{ Subports: []trunks.Subport{ { SegmentationID: 1, SegmentationType: "vlan", PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a", }, { SegmentationID: 10, SegmentationType: "vlan", PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112", }, }, } trunk, err := trunks.AddSubports(client, trunkID, addSubportsOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", trunk)
Example of deleting two subports from a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159" removeSubportsOpts := trunks.RemoveSubportsOpts{ Subports: []trunks.RemoveSubport{ {PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a"}, {PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112"}, }, } trunk, err := trunks.RemoveSubports(networkClient, trunkID, removeSubportsOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v\n", trunk)
Index ¶
- func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type AddSubportsOpts
- type AddSubportsOptsBuilder
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type GetSubportsResult
- type ListOpts
- type ListOptsBuilder
- type RemoveSubport
- type RemoveSubportsOpts
- type RemoveSubportsOptsBuilder
- type Subport
- type Trunk
- type TrunkPage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
- type UpdateSubportsResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List returns a Pager which allows you to iterate over a collection of trunks. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.
Default policy settings return only those trunks that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.
Types ¶
type AddSubportsOpts ¶
type AddSubportsOpts struct {
Subports []Subport `json:"sub_ports" required:"true"`
}
func (AddSubportsOpts) ToTrunkAddSubportsMap ¶
func (opts AddSubportsOpts) ToTrunkAddSubportsMap() (map[string]interface{}, error)
type AddSubportsOptsBuilder ¶
type CreateOpts ¶
type CreateOpts struct { TenantID string `json:"tenant_id,omitempty"` ProjectID string `json:"project_id,omitempty"` PortID string `json:"port_id" required:"true"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` Subports []Subport `json:"sub_ports"` }
CreateOpts represents the attributes used when creating a new trunk.
func (CreateOpts) ToTrunkCreateMap ¶
func (opts CreateOpts) ToTrunkCreateMap() (map[string]interface{}, error)
ToTrunkCreateMap builds a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult is the response from a Create operation. Call its Extract method to interpret it as a Trunk.
func Create ¶
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult is the response from a Delete operation. Call its ExtractErr to determine if the request succeeded or failed.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult)
Delete accepts a unique ID and deletes the trunk associated with it.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult is the response from a Get operation. Call its Extract method to interpret it as a Trunk.
func Get ¶
func Get(c *gophercloud.ServiceClient, id string) (r GetResult)
Get retrieves a specific trunk based on its unique ID.
type GetSubportsResult ¶
type GetSubportsResult struct {
// contains filtered or unexported fields
}
GetSubportsResult is the result of a Get request on the trunks subports resource. Call its Extract method to interpret it as a slice of Subport.
func GetSubports ¶
func GetSubports(c *gophercloud.ServiceClient, id string) (r GetSubportsResult)
func (GetSubportsResult) Extract ¶
func (r GetSubportsResult) Extract() ([]Subport, error)
type ListOpts ¶
type ListOpts struct { AdminStateUp *bool `q:"admin_state_up"` Description string `q:"description"` ID string `q:"id"` Name string `q:"name"` PortID string `q:"port_id"` RevisionNumber string `q:"revision_number"` Status string `q:"status"` TenantID string `q:"tenant_id"` ProjectID string `q:"project_id"` SortDir string `q:"sort_dir"` SortKey string `q:"sort_key"` Tags string `q:"tags"` TagsAny string `q:"tags-any"` NotTags string `q:"not-tags"` NotTagsAny string `q:"not-tags-any"` }
ListOpts allows the filtering and sorting of paginated collections through the API. Filtering is achieved by passing in struct field values that map to the trunk attributes you want to see returned. SortKey allows you to sort by a particular trunk attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.
func (ListOpts) ToTrunkListQuery ¶
ToTrunkListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type RemoveSubport ¶
type RemoveSubport struct {
PortID string `json:"port_id" required:"true"`
}
type RemoveSubportsOpts ¶
type RemoveSubportsOpts struct {
Subports []RemoveSubport `json:"sub_ports"`
}
func (RemoveSubportsOpts) ToTrunkRemoveSubportsMap ¶
func (opts RemoveSubportsOpts) ToTrunkRemoveSubportsMap() (map[string]interface{}, error)
type Trunk ¶
type Trunk struct { // Indicates whether the trunk is currently operational. Possible values include // `ACTIVE', `DOWN', `BUILD', 'DEGRADED' or `ERROR'. Status string `json:"status"` // A list of ports associated with the trunk Subports []Subport `json:"sub_ports"` // Human-readable name for the trunk. Might not be unique. Name string `json:"name,omitempty"` // The administrative state of the trunk. If false (down), the trunk does not // forward packets. AdminStateUp bool `json:"admin_state_up,omitempty"` // ProjectID is the project owner of the trunk. ProjectID string `json:"project_id"` // TenantID is the project owner of the trunk. TenantID string `json:"tenant_id"` // The date and time when the resource was created. CreatedAt time.Time `json:"created_at"` // The date and time when the resource was updated, // if the resource has not been updated, this field will show as null. UpdatedAt time.Time `json:"updated_at"` RevisionNumber int `json:"revision_number"` // UUID of the trunk's parent port PortID string `json:"port_id"` // UUID for the trunk resource ID string `json:"id"` // Display description. Description string `json:"description"` // A list of tags associated with the trunk Tags []string `json:"tags,omitempty"` }
func ExtractTrunks ¶
func ExtractTrunks(page pagination.Page) ([]Trunk, error)
type TrunkPage ¶
type TrunkPage struct {
pagination.LinkedPageBase
}
TrunkPage is the page returned by a pager when traversing a collection of trunk resources.
type UpdateOpts ¶
type UpdateOpts struct { AdminStateUp *bool `json:"admin_state_up,omitempty"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` }
func (UpdateOpts) ToTrunkUpdateMap ¶
func (opts UpdateOpts) ToTrunkUpdateMap() (map[string]interface{}, error)
type UpdateOptsBuilder ¶
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult is the result of an Update request. Call its Extract method to interpret it as a Trunk.
func Update ¶
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)
type UpdateSubportsResult ¶
type UpdateSubportsResult struct {
// contains filtered or unexported fields
}
UpdateSubportsResult is the result of either an AddSubports or a RemoveSubports request. Call its Extract method to interpret it as a Trunk.
func AddSubports ¶
func AddSubports(c *gophercloud.ServiceClient, id string, opts AddSubportsOptsBuilder) (r UpdateSubportsResult)
func RemoveSubports ¶
func RemoveSubports(c *gophercloud.ServiceClient, id string, opts RemoveSubportsOptsBuilder) (r UpdateSubportsResult)
func (UpdateSubportsResult) Extract ¶
func (r UpdateSubportsResult) Extract() (t *Trunk, err error)