github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v1/ports/results.go (about)

     1  package ports
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk/pagination"
     5  )
     6  
     7  // Port is an API response structure of the network VIP.
     8  type Port struct {
     9  	// Specifies the administrative state of the port.
    10  	// The value can only be true, and the default value is true.
    11  	AdminStateUp bool `json:"admin_state_up"`
    12  	// Specifies the time when the network VIP was created.
    13  	CreatedAt string `json:"created_at"`
    14  	// Specifies the port ID, which uniquely identifies the port.
    15  	ID string `json:"id"`
    16  	// Specifies the port name.
    17  	// The value can contain no more than 255 characters. This parameter is left blank by default.
    18  	Name string `json:"name"`
    19  	// Specifies the ID of the network to which the port belongs.
    20  	// The network ID must be a real one in the network environment.
    21  	NetworkId string `json:"network_id"`
    22  	// Specifies the port MAC address.
    23  	// The system automatically sets this parameter, and you are not allowed to configure the parameter value.
    24  	MacAddress string `json:"mac_address"`
    25  	// Specifies the port IP address.
    26  	// A port supports only one fixed IP address that cannot be changed.
    27  	FixedIps []FixedIp `json:"fixed_ips"`
    28  	// Specifies the ID of the device to which the port belongs.
    29  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    30  	DeviceId string `json:"device_id"`
    31  	// Specifies the belonged device, which can be the DHCP server, router, load balancer, or Nova.
    32  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    33  	DeviceOwner string `json:"device_owner"`
    34  	// Specifies the project ID.
    35  	TenantId string `json:"tenant_id"`
    36  	// Specifies the port status. The status of a HANA SR-IOV VM port is always DOWN.
    37  	// The value can be ACTIVE, BUILD, or DOWN.
    38  	Status string `json:"status"`
    39  	// Specifies the security group UUID (extended attribute).
    40  	SecurityGroups []string `json:"security_groups"`
    41  	// Specifies a set of zero or more allowed address pairs. An address pair consists of an IP address and MAC address.
    42  	// The IP address cannot be 0.0.0.0/0.
    43  	// Configure an independent security group for the port if a large CIDR block (subnet mask less than 24) is
    44  	// configured for parameter AllowedAddressPairs.
    45  	AllowedAddressPairs []AddressPair `json:"allowed_address_pairs"`
    46  	// Specifies the extended option (extended attribute) of DHCP.
    47  	ExtraDhcpOpts []ExtraDhcpOpt `json:"extra_dhcp_opts"`
    48  	// Specifies the VIF details. Parameter ovs_hybrid_plug specifies whether the OVS/bridge hybrid mode is used.
    49  	VifDetails VifDetail `json:"binding:vif_details"`
    50  	// Specifies the custom information configured by users. This is an extended attribute.
    51  	Profile interface{} `json:"binding:profile"`
    52  	// Specifies the type of the bound vNIC. The value can be normal or direct.
    53  	// Parameter normal indicates software switching.
    54  	// Parameter direct indicates SR-IOV PCIe passthrough, which is not supported.
    55  	VnicType string `json:"binding:vnic_type"`
    56  	// Specifies the default private network domain name information of the primary NIC.
    57  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    58  	DnsAssignment []DnsAssignment `json:"dns_assignment"`
    59  	// Specifies the default private network DNS name of the primary NIC.
    60  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    61  	DnsName string `json:"dns_name"`
    62  	// Specifies the ID of the instance to which the port belongs, for example, RDS instance ID.
    63  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    64  	InstanceId string `json:"instance_id"`
    65  	// Specifies the type of the instance to which the port belongs, for example, RDS.
    66  	// The system automatically sets this parameter, and you are not allowed to configure or change the parameter value.
    67  	InstanceType string `json:"instance_type"`
    68  	// Specifies whether the security option is enabled for the port.
    69  	// If the option is not enabled, the security group and DHCP snooping do not take effect.
    70  	PortSecurityEnabled bool `json:"port_security_enabled"`
    71  	// Availability zone to which the port belongs.
    72  	ZoneId string `json:"zone_id"`
    73  	// Whether to enable efi
    74  	EnableEfi bool `json:"enable_efi"`
    75  	// The Shared bandwidth ID bound to IPv6
    76  	Ipv6BandwidthId string `json:"ipv6_bandwidth_id"`
    77  }
    78  
    79  // VifDetail is an Object specifying the VIF details.
    80  type VifDetail struct {
    81  	// If the value is true, indicating that it is the main network card of the virtual machine.
    82  	PrimaryInterface bool `json:"primary_interface"`
    83  }
    84  
    85  // DnsAssignment is an Object specifying the private network domain information.
    86  type DnsAssignment struct {
    87  	// Specifies the hostname.
    88  	Hostname string `json:"hostname"`
    89  	// Specifies the IP address of the port.
    90  	IpAddress string `json:"ip_address"`
    91  	// Specifies the FQDN.
    92  	Fqdn string `json:"fqdn"`
    93  }
    94  
    95  // PortPage is the page returned by a pager when traversing over a collection
    96  // of network ports.
    97  type PortPage struct {
    98  	pagination.MarkerPageBase
    99  }
   100  
   101  // LastMarker method returns the last ID in a ports page.
   102  func (p PortPage) LastMarker() (string, error) {
   103  	pagePorts, err := ExtractPorts(p)
   104  	if err != nil {
   105  		return "", err
   106  	}
   107  	if len(pagePorts) == 0 {
   108  		return "", nil
   109  	}
   110  	lastPort := pagePorts[len(pagePorts)-1]
   111  	return lastPort.ID, nil
   112  }
   113  
   114  // IsEmpty method checks whether a PortPage struct is empty.
   115  func (p PortPage) IsEmpty() (bool, error) {
   116  	pagePorts, err := ExtractPorts(p)
   117  	return len(pagePorts) == 0, err
   118  }
   119  
   120  // ExtractPorts accepts a Page struct, specifically a PortPage struct,
   121  // and extracts the elements into a slice of Port structs. In other words,
   122  // a generic collection is mapped into a relevant slice.
   123  func ExtractPorts(r pagination.Page) ([]Port, error) {
   124  	var s []Port
   125  	err := r.(PortPage).Result.ExtractIntoSlicePtr(&s, "ports")
   126  	return s, err
   127  }