github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/ports/results.go (about)

     1  package ports
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  type portResult struct {
    11  	gophercloud.Result
    12  }
    13  
    14  func (r portResult) Extract() (*Port, error) {
    15  	var s Port
    16  	err := r.ExtractInto(&s)
    17  	return &s, err
    18  }
    19  
    20  func (r portResult) ExtractInto(v interface{}) error {
    21  	return r.Result.ExtractIntoStructPtr(v, "")
    22  }
    23  
    24  func ExtractPortsInto(r pagination.Page, v interface{}) error {
    25  	return r.(PortPage).Result.ExtractIntoSlicePtr(v, "ports")
    26  }
    27  
    28  // Port represents a port in the OpenStack Bare Metal API.
    29  type Port struct {
    30  	// UUID for the resource.
    31  	UUID string `json:"uuid"`
    32  
    33  	// Physical hardware address of this network Port,
    34  	// typically the hardware MAC address.
    35  	Address string `json:"address"`
    36  
    37  	// UUID of the Node this resource belongs to.
    38  	NodeUUID string `json:"node_uuid"`
    39  
    40  	// UUID of the Portgroup this resource belongs to.
    41  	PortGroupUUID string `json:"portgroup_uuid"`
    42  
    43  	// The Port binding profile. If specified, must contain switch_id (only a MAC
    44  	// address or an OpenFlow based datapath_id of the switch are accepted in this
    45  	// field) and port_id (identifier of the physical port on the switch to which
    46  	// node’s port is connected to) fields. switch_info is an optional string
    47  	// field to be used to store any vendor-specific information.
    48  	LocalLinkConnection map[string]interface{} `json:"local_link_connection"`
    49  
    50  	// Indicates whether PXE is enabled or disabled on the Port.
    51  	PXEEnabled bool `json:"pxe_enabled"`
    52  
    53  	// The name of the physical network to which a port is connected.
    54  	// May be empty.
    55  	PhysicalNetwork string `json:"physical_network"`
    56  
    57  	// Internal metadata set and stored by the Port. This field is read-only.
    58  	InternalInfo map[string]interface{} `json:"internal_info"`
    59  
    60  	// A set of one or more arbitrary metadata key and value pairs.
    61  	Extra map[string]interface{} `json:"extra"`
    62  
    63  	// The UTC date and time when the resource was created, ISO 8601 format.
    64  	CreatedAt time.Time `json:"created_at"`
    65  
    66  	// The UTC date and time when the resource was updated, ISO 8601 format.
    67  	// May be “null”.
    68  	UpdatedAt time.Time `json:"updated_at"`
    69  
    70  	// A list of relative links. Includes the self and bookmark links.
    71  	Links []interface{} `json:"links"`
    72  
    73  	// Indicates whether the Port is a Smart NIC port.
    74  	IsSmartNIC bool `json:"is_smartnic"`
    75  }
    76  
    77  // PortPage abstracts the raw results of making a List() request against
    78  // the API.
    79  type PortPage struct {
    80  	pagination.LinkedPageBase
    81  }
    82  
    83  // IsEmpty returns true if a page contains no Port results.
    84  func (r PortPage) IsEmpty() (bool, error) {
    85  	if r.StatusCode == 204 {
    86  		return true, nil
    87  	}
    88  
    89  	s, err := ExtractPorts(r)
    90  	return len(s) == 0, err
    91  }
    92  
    93  // NextPageURL uses the response's embedded link reference to navigate to the
    94  // next page of results.
    95  func (r PortPage) NextPageURL() (string, error) {
    96  	var s struct {
    97  		Links []gophercloud.Link `json:"ports_links"`
    98  	}
    99  	err := r.ExtractInto(&s)
   100  	if err != nil {
   101  		return "", err
   102  	}
   103  	return gophercloud.ExtractNextURL(s.Links)
   104  }
   105  
   106  // ExtractPorts interprets the results of a single page from a List() call,
   107  // producing a slice of Port entities.
   108  func ExtractPorts(r pagination.Page) ([]Port, error) {
   109  	var s []Port
   110  	err := ExtractPortsInto(r, &s)
   111  	return s, err
   112  }
   113  
   114  // GetResult is the response from a Get operation. Call its Extract
   115  // method to interpret it as a Port.
   116  type GetResult struct {
   117  	portResult
   118  }
   119  
   120  // CreateResult is the response from a Create operation.
   121  type CreateResult struct {
   122  	portResult
   123  }
   124  
   125  // UpdateResult is the response from an Update operation. Call its Extract
   126  // method to interpret it as a Port.
   127  type UpdateResult struct {
   128  	portResult
   129  }
   130  
   131  // DeleteResult is the response from a Delete operation. Call its ExtractErr
   132  // method to determine if the call succeeded or failed.
   133  type DeleteResult struct {
   134  	gophercloud.ErrResult
   135  }