Documentation ¶
Overview ¶
Package networks contains functionality for working with Neutron network resources. A network is an isolated virtual layer-2 broadcast domain that is typically reserved for the tenant who created it (unless you configure the network to be shared). Tenants can create multiple networks until the thresholds per-tenant quota is reached.
In the v2.0 Networking API, the network is the main entity. Ports and subnets are always associated with a network.
Example to List Networks
listOpts := networks.ListOpts{ TenantID: "a99e9b4e620e4db09a2dfb6e42a01e66", } allPages, err := networks.List(networkClient, listOpts).AllPages(context.TODO()) if err != nil { panic(err) } allNetworks, err := networks.ExtractNetworks(allPages) if err != nil { panic(err) } for _, network := range allNetworks { fmt.Printf("%+v", network) }
Example to Create a Network
iTrue := true createOpts := networks.CreateOpts{ Name: "network_1", AdminStateUp: &iTrue, } network, err := networks.Create(context.TODO(), networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Update a Network
networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78" name := "new_name" updateOpts := networks.UpdateOpts{ Name: &name, } network, err := networks.Update(context.TODO(), networkClient, networkID, updateOpts).Extract() if err != nil { panic(err) }
Example to Delete a Network
networkID := "484cda0e-106f-4f4b-bb3f-d413710bbe78" err := networks.Delete(context.TODO(), networkClient, networkID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func ExtractNetworksInto(r pagination.Page, v any) error
- func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type ListOpts
- type ListOptsBuilder
- type Network
- type NetworkPage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractNetworksInto ¶
func ExtractNetworksInto(r pagination.Page, v any) error
func List ¶
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List returns a Pager which allows you to iterate over a collection of networks. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.
Types ¶
type CreateOpts ¶
type CreateOpts struct { AdminStateUp *bool `json:"admin_state_up,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` TenantID string `json:"tenant_id,omitempty"` ProjectID string `json:"project_id,omitempty"` AvailabilityZoneHints []string `json:"availability_zone_hints,omitempty"` }
CreateOpts represents options used to create a network.
func (CreateOpts) ToNetworkCreateMap ¶
func (opts CreateOpts) ToNetworkCreateMap() (map[string]any, error)
ToNetworkCreateMap 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 represents the result of a create operation. Call its Extract method to interpret it as a Network.
func Create ¶
func Create(ctx context.Context, c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create accepts a CreateOpts struct and creates a new network using the values provided. This operation does not actually require a request body, i.e. the CreateOpts struct argument can be empty.
The tenant ID that is contained in the URI is the tenant that creates the network. An admin user, however, has the option of specifying another tenant ID in the CreateOpts struct.
func (CreateResult) Extract ¶
Extract is a function that accepts a result and extracts a network resource.
func (CreateResult) ExtractInto ¶
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult represents the result of a get operation. Call its Extract method to interpret it as a Network.
func (GetResult) Extract ¶
Extract is a function that accepts a result and extracts a network resource.
func (GetResult) ExtractInto ¶
type ListOpts ¶
type ListOpts struct { Status string `q:"status"` Name string `q:"name"` Description string `q:"description"` AdminStateUp *bool `q:"admin_state_up"` TenantID string `q:"tenant_id"` ProjectID string `q:"project_id"` ID string `q:"id"` Marker string `q:"marker"` Limit int `q:"limit"` SortKey string `q:"sort_key"` SortDir string `q:"sort_dir"` 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 network attributes you want to see returned. SortKey allows you to sort by a particular network attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.
func (ListOpts) ToNetworkListQuery ¶
ToNetworkListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Network ¶
type Network struct { // UUID for the network ID string `json:"id"` // Human-readable name for the network. Might not be unique. Name string `json:"name"` // Description for the network Description string `json:"description"` // The administrative state of network. If false (down), the network does not // forward packets. AdminStateUp bool `json:"admin_state_up"` // Indicates whether network is currently operational. Possible values include // `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define additional // values. Status string `json:"status"` // Subnets associated with this network. Subnets []string `json:"subnets"` // TenantID is the project owner of the network. TenantID string `json:"tenant_id"` // UpdatedAt and CreatedAt contain ISO-8601 timestamps of when the state of the // network last changed, and when it was created. UpdatedAt time.Time `json:"-"` CreatedAt time.Time `json:"-"` // ProjectID is the project owner of the network. ProjectID string `json:"project_id"` Shared bool `json:"shared"` // Availability zone hints groups network nodes that run services like DHCP, L3, FW, and others. // Used to make network resources highly available. AvailabilityZoneHints []string `json:"availability_zone_hints"` // Tags optionally set via extensions/attributestags Tags []string `json:"tags"` // RevisionNumber optionally set via extensions/standard-attr-revisions RevisionNumber int `json:"revision_number"` }
Network represents, well, a network.
func ExtractNetworks ¶
func ExtractNetworks(r pagination.Page) ([]Network, error)
ExtractNetworks accepts a Page struct, specifically a NetworkPage struct, and extracts the elements into a slice of Network structs. In other words, a generic collection is mapped into a relevant slice.
func (*Network) UnmarshalJSON ¶
type NetworkPage ¶
type NetworkPage struct {
pagination.LinkedPageBase
}
NetworkPage is the page returned by a pager when traversing over a collection of networks.
func (NetworkPage) IsEmpty ¶
func (r NetworkPage) IsEmpty() (bool, error)
IsEmpty checks whether a NetworkPage struct is empty.
func (NetworkPage) NextPageURL ¶
func (r NetworkPage) NextPageURL() (string, error)
NextPageURL is invoked when a paginated collection of networks has reached the end of a page and the pager seeks to traverse over a new one. In order to do this, it needs to construct the next page's URL.
type UpdateOpts ¶
type UpdateOpts struct { AdminStateUp *bool `json:"admin_state_up,omitempty"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` // RevisionNumber implements extension:standard-attr-revisions. If != "" it // will set revision_number=%s. If the revision number does not match, the // update will fail. RevisionNumber *int `json:"-" h:"If-Match"` }
UpdateOpts represents options used to update a network.
func (UpdateOpts) ToNetworkUpdateMap ¶
func (opts UpdateOpts) ToNetworkUpdateMap() (map[string]any, error)
ToNetworkUpdateMap builds a request body from UpdateOpts.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult represents the result of an update operation. Call its Extract method to interpret it as a Network.
func Update ¶
func Update(ctx context.Context, c *gophercloud.ServiceClient, networkID string, opts UpdateOptsBuilder) (r UpdateResult)
Update accepts a UpdateOpts struct and updates an existing network using the values provided. For more information, see the Create function.
func (UpdateResult) Extract ¶
Extract is a function that accepts a result and extracts a network resource.