Documentation ¶
Overview ¶
Package ports contains functionality for working with Neutron port resources.
A port represents a virtual switch port on a logical network switch. Virtual instances attach their interfaces into ports. The logical port also defines the MAC address and the IP address(es) to be assigned to the interfaces plugged into them. When IP addresses are associated to a port, this also implies the port is associated with a subnet, as the IP address was taken from the allocation pool for a specific subnet.
Example to List Ports
listOpts := ports.ListOpts{ DeviceID: "b0b89efe-82f8-461d-958b-adbf80f50c7d", } allPages, err := ports.List(networkClient, listOpts).AllPages() if err != nil { panic(err) } allPorts, err := ports.ExtractPorts(allPages) if err != nil { panic(err) } for _, port := range allPorts { fmt.Printf("%+v\n", port) }
Example to Create a Port
createOtps := ports.CreateOpts{ Name: "private-port", AdminStateUp: &asu, NetworkID: "a87cc70a-3e15-4acf-8205-9b711a3531b7", FixedIPs: []ports.IP{ {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"}, }, SecurityGroups: &[]string{"foo"}, AllowedAddressPairs: []ports.AddressPair{ {IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"}, }, } port, err := ports.Create(networkClient, createOpts).Extract() if err != nil { panic(err) }
Example to Update a Port
portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8" updateOpts := ports.UpdateOpts{ Name: "new_name", SecurityGroups: &[]string{}, } port, err := ports.Update(networkClient, portID, updateOpts).Extract() if err != nil { panic(err) }
Example to Delete a Port
portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8" err := ports.Delete(networkClient, portID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func ExtractPortsInto(r pagination.Page, v interface{}) error
- func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type AddressPair
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type FixedIPOpts
- type GetResult
- type IP
- type ListOpts
- type ListOptsBuilder
- type Port
- type PortPage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPortsInto ¶
func ExtractPortsInto(r pagination.Page, v interface{}) 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 ports. It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.
Default policy settings return only those ports that are owned by the tenant who submits the request, unless the request is submitted by a user with administrative rights.
Types ¶
type AddressPair ¶
type AddressPair struct { IPAddress string `json:"ip_address,omitempty"` MACAddress string `json:"mac_address,omitempty"` }
AddressPair contains the IP Address and the MAC address.
type CreateOpts ¶
type CreateOpts struct { NetworkID string `json:"network_id" required:"true"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` MACAddress string `json:"mac_address,omitempty"` FixedIPs interface{} `json:"fixed_ips,omitempty"` DeviceID string `json:"device_id,omitempty"` DeviceOwner string `json:"device_owner,omitempty"` TenantID string `json:"tenant_id,omitempty"` ProjectID string `json:"project_id,omitempty"` SecurityGroups *[]string `json:"security_groups,omitempty"` AllowedAddressPairs []AddressPair `json:"allowed_address_pairs,omitempty"` }
CreateOpts represents the attributes used when creating a new port.
func (CreateOpts) ToPortCreateMap ¶
func (opts CreateOpts) ToPortCreateMap() (map[string]interface{}, error)
ToPortCreateMap 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 Port.
func Create ¶
func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create accepts a CreateOpts struct and creates a new network using the values provided. You must remember to provide a NetworkID value.
func (CreateResult) Extract ¶
Extract is a function that accepts a result and extracts a port resource.
func (CreateResult) ExtractInto ¶
func (r CreateResult) ExtractInto(v interface{}) error
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.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult)
Delete accepts a unique ID and deletes the port associated with it.
type FixedIPOpts ¶
func (FixedIPOpts) String ¶
func (f FixedIPOpts) String() string
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 Port.
func Get ¶
func Get(c *gophercloud.ServiceClient, id string) (r GetResult)
Get retrieves a specific port based on its unique ID.
func (GetResult) Extract ¶
Extract is a function that accepts a result and extracts a port resource.
func (GetResult) ExtractInto ¶
func (r GetResult) ExtractInto(v interface{}) error
type IP ¶
type IP struct { SubnetID string `json:"subnet_id"` IPAddress string `json:"ip_address,omitempty"` IPVersion int `json:"ip_version,omitempty"` }
IP is a sub-struct that represents an individual IP.
type ListOpts ¶
type ListOpts struct { Status string `q:"status"` Name string `q:"name"` Description string `q:"description"` AdminStateUp *bool `q:"admin_state_up"` NetworkID string `q:"network_id"` TenantID string `q:"tenant_id"` ProjectID string `q:"project_id"` DeviceOwner string `q:"device_owner"` MACAddress string `q:"mac_address"` ID string `q:"id"` DeviceID string `q:"device_id"` Limit int `q:"limit"` Marker string `q:"marker"` 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"` FixedIPs []FixedIPOpts }
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 port attributes you want to see returned. SortKey allows you to sort by a particular port attribute. SortDir sets the direction, and is either `asc' or `desc'. Marker and Limit are used for pagination.
func (ListOpts) ToPortListQuery ¶
ToPortListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Port ¶
type Port struct { // UUID for the port. ID string `json:"id"` // Network that this port is associated with. NetworkID string `json:"network_id"` // Human-readable name for the port. Might not be unique. Name string `json:"name"` // Describes the port. Description string `json:"description"` // Administrative state of port. If false (down), port 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"` // Mac address to use on this port. MACAddress string `json:"mac_address"` // Specifies IP addresses for the port thus associating the port itself with // the subnets where the IP addresses are picked from FixedIPs []IP `json:"fixed_ips"` // TenantID is the project owner of the port. TenantID string `json:"tenant_id"` // ProjectID is the project owner of the port. ProjectID string `json:"project_id"` // Identifies the entity (e.g.: dhcp agent) using this port. DeviceOwner string `json:"device_owner"` // Specifies the IDs of any security groups associated with a port. SecurityGroups []string `json:"security_groups"` // Identifies the device (e.g., virtual server) using this port. DeviceID string `json:"device_id"` // Identifies the list of IP addresses the port will recognize/accept AllowedAddressPairs []AddressPair `json:"allowed_address_pairs"` // Tags optionally set via extensions/attributestags Tags []string `json:"tags"` // RevisionNumber optionally set via extensions/standard-attr-revisions RevisionNumber int `json:"revision_number"` // Timestamp when the port was created CreatedAt time.Time `json:"created_at"` // Timestamp when the port was last updated UpdatedAt time.Time `json:"updated_at"` }
Port represents a Neutron port. See package documentation for a top-level description of what this is.
func ExtractPorts ¶
func ExtractPorts(r pagination.Page) ([]Port, error)
ExtractPorts accepts a Page struct, specifically a PortPage struct, and extracts the elements into a slice of Port structs. In other words, a generic collection is mapped into a relevant slice.
func (*Port) UnmarshalJSON ¶
type PortPage ¶
type PortPage struct {
pagination.LinkedPageBase
}
PortPage is the page returned by a pager when traversing over a collection of network ports.
func (PortPage) NextPageURL ¶
NextPageURL is invoked when a paginated collection of ports 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 { Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` AdminStateUp *bool `json:"admin_state_up,omitempty"` FixedIPs interface{} `json:"fixed_ips,omitempty"` DeviceID *string `json:"device_id,omitempty"` DeviceOwner *string `json:"device_owner,omitempty"` SecurityGroups *[]string `json:"security_groups,omitempty"` AllowedAddressPairs *[]AddressPair `json:"allowed_address_pairs,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 the attributes used when updating an existing port.
func (UpdateOpts) ToPortUpdateMap ¶
func (opts UpdateOpts) ToPortUpdateMap() (map[string]interface{}, error)
ToPortUpdateMap 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 Port.
func Update ¶
func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)
Update accepts a UpdateOpts struct and updates an existing port using the values provided.
func (UpdateResult) Extract ¶
Extract is a function that accepts a result and extracts a port resource.
func (UpdateResult) ExtractInto ¶
func (r UpdateResult) ExtractInto(v interface{}) error