github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/attachinterfaces/results.go (about)

     1  package attachinterfaces
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  type attachInterfaceResult struct {
     9  	golangsdk.Result
    10  }
    11  
    12  // Extract interprets any attachInterfaceResult as an Interface, if possible.
    13  func (r attachInterfaceResult) Extract() (*Interface, error) {
    14  	var s struct {
    15  		Interface *Interface `json:"interfaceAttachment"`
    16  	}
    17  	err := r.ExtractInto(&s)
    18  	return s.Interface, err
    19  }
    20  
    21  // GetResult is the response from a Get operation. Call its Extract
    22  // method to interpret it as an Interface.
    23  type GetResult struct {
    24  	attachInterfaceResult
    25  }
    26  
    27  // CreateResult is the response from a Create operation. Call its Extract
    28  // method to interpret it as an Interface.
    29  type CreateResult struct {
    30  	attachInterfaceResult
    31  }
    32  
    33  // DeleteResult is the response from a Delete operation. Call its ExtractErr
    34  // method to determine if the call succeeded or failed.
    35  type DeleteResult struct {
    36  	golangsdk.ErrResult
    37  }
    38  
    39  // FixedIP represents a Fixed IP Address.
    40  // This struct is also used when creating an attachment,
    41  // but it is not possible to specify a SubnetID.
    42  type FixedIP struct {
    43  	SubnetID  string `json:"subnet_id,omitempty"`
    44  	IPAddress string `json:"ip_address"`
    45  }
    46  
    47  // Interface represents a network interface on a server.
    48  type Interface struct {
    49  	PortState string    `json:"port_state"`
    50  	FixedIPs  []FixedIP `json:"fixed_ips"`
    51  	PortID    string    `json:"port_id"`
    52  	NetID     string    `json:"net_id"`
    53  	MACAddr   string    `json:"mac_addr"`
    54  }
    55  
    56  // InterfacePage abstracts the raw results of making a List() request against
    57  // the API.
    58  //
    59  // As OpenStack extensions may freely alter the response bodies of structures
    60  // returned to the client, you may only safely access the data provided through
    61  // the ExtractInterfaces call.
    62  type InterfacePage struct {
    63  	pagination.SinglePageBase
    64  }
    65  
    66  // IsEmpty returns true if an InterfacePage contains no interfaces.
    67  func (r InterfacePage) IsEmpty() (bool, error) {
    68  	interfaces, err := ExtractInterfaces(r)
    69  	return len(interfaces) == 0, err
    70  }
    71  
    72  // ExtractInterfaces interprets the results of a single page from a List() call,
    73  // producing a slice of Interface structs.
    74  func ExtractInterfaces(r pagination.Page) ([]Interface, error) {
    75  	var s struct {
    76  		Interfaces []Interface `json:"interfaceAttachments"`
    77  	}
    78  	err := (r.(InterfacePage)).ExtractInto(&s)
    79  	return s.Interfaces, err
    80  }