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 IDFromName(client *golangsdk.ServiceClient, name string) (string, error)
- func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type AddressPair
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type DnsAssignment
- type ExtraDhcpOpt
- type GetResult
- type IP
- type ListOpts
- type ListOptsBuilder
- type Port
- type PortPage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
- type VifDetail
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPortsInto ¶
func ExtractPortsInto(r pagination.Page, v interface{}) error
func IDFromName ¶
IDFromName is a convenience function that returns a port's ID, given its name.
func List ¶
func List(c *golangsdk.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"`
AdminStateUp *bool `json:"admin_state_up,omitempty"`
MACAddress string `json:"mac_address,omitempty"`
FixedIPs []IP `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"`
ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts,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 *golangsdk.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 {
golangsdk.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 *golangsdk.ServiceClient, id string) (r DeleteResult)
Delete accepts a unique ID and deletes the port associated with it.
type DnsAssignment ¶ added in v0.9.6
type DnsAssignment struct {
// Specifies the hostname.
Hostname string `json:"hostname"`
// Specifies the IP address of the port.
IpAddress string `json:"ip_address"`
// Specifies the FQDN.
Fqdn string `json:"fqdn"`
}
DnsAssignment is an Object specifying the private network domain information.
type ExtraDhcpOpt ¶ added in v0.9.6
type ExtraDhcpOpt struct {
// Specifies the DHCP option name.
// Currently, only '51' is supported to indicate the DHCP lease time.
OptName string `json:"opt_name,omitempty"`
// Specifies the DHCP option value.
// When 'OptName' is '51', the parameter format is 'Xh', indicating that the DHCP lease time is X hours.
// The value range of 'X' is '1~30000' or '-1', '-1' means the DHCP lease time is infinite.
OptValue string `json:"opt_value,omitempty"`
}
ExtraDhcpOpt is an Object specifying the DHCP extended properties.
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 (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 {
// Specifies the subnet ID.
// You cannot change the parameter value.
SubnetID string `json:"subnet_id,omitempty"`
// Specifies the port IP address.
// You cannot change the parameter value.
IPAddress string `json:"ip_address,omitempty"`
}
IP is an Object specifying the IP information of the port.
type ListOpts ¶
type ListOpts struct {
Status string `q:"status"`
Name string `q:"name"`
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"`
EnterpriseProjectID string `q:"enterprise_project_id"`
// fixed_ips=ip_address={ip_address}&fixed_ips=subnet_id={subnet_id}
FixedIps []string `q:"fixed_ips"`
}
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"`
// 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"`
// Specifies the extended option (extended attribute) of DHCP.
ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts"`
// Specifies the VIF details. Parameter ovs_hybrid_plug specifies whether the OVS/bridge hybrid mode is used.
VifDetails VifDetail `json:"binding:vif_details"`
// Specifies the custom information configured by users. This is an extended attribute.
Profile interface{} `json:"binding:profile"`
// Specifies the type of the bound vNIC. The value can be normal or direct.
// Parameter normal indicates software switching.
// Parameter direct indicates SR-IOV PCIe passthrough, which is not supported.
VnicType string `json:"binding:vnic_type"`
// Specifies the default private network domain name information of the primary NIC.
// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
DnsAssignment []DnsAssignment `json:"dns_assignment"`
// Specifies the default private network DNS name of the primary NIC.
// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
DnsName string `json:"dns_name"`
// Specifies the ID of the instance to which the port belongs, for example, RDS instance ID.
// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
InstanceId string `json:"instance_id"`
// Specifies the type of the instance to which the port belongs, for example, RDS.
// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
InstanceType string `json:"instance_type"`
// Specifies whether the security option is enabled for the port.
// If the option is not enabled, the security group and DHCP snooping do not take effect.
PortSecurityEnabled bool `json:"port_security_enabled"`
// Availability zone to which the port belongs.
ZoneId string `json:"zone_id"`
// Whether to enable efi
EnableEfi bool `json:"enable_efi"`
// The Shared bandwidth ID bound to IPv6
Ipv6BandwidthId string `json:"ipv6_bandwidth_id"`
}
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.
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"`
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"`
ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts,omitempty"`
}
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 *golangsdk.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