github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/eips/results.go (about)

     1  package eips
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  // ApplyResult is a struct which represents the result of apply public ip
     9  type ApplyResult struct {
    10  	golangsdk.Result
    11  }
    12  
    13  func (r ApplyResult) Extract() (*PublicIp, error) {
    14  	s := new(PublicIp)
    15  	err := r.ExtractIntoStructPtr(s, "publicip")
    16  	return s, err
    17  }
    18  
    19  // PublicIp is a struct that represents a public ip
    20  type PublicIp struct {
    21  	ID                 string `json:"id"`
    22  	Status             string `json:"status"`
    23  	Type               string `json:"type"`
    24  	PublicAddress      string `json:"public_ip_address"`
    25  	PrivateAddress     string `json:"private_ip_address"`
    26  	PortID             string `json:"port_id"`
    27  	TenantID           string `json:"tenant_id"`
    28  	CreateTime         string `json:"create_time"`
    29  	BandwidthID        string `json:"bandwidth_id"`
    30  	BandwidthSize      int    `json:"bandwidth_size"`
    31  	BandwidthShareType string `json:"bandwidth_share_type"`
    32  	IpVersion          int    `json:"ip_version"`
    33  	Name               string `json:"alias"`
    34  }
    35  
    36  // GetResult is a return struct of get method
    37  type GetResult struct {
    38  	golangsdk.Result
    39  }
    40  
    41  func (r GetResult) Extract() (*PublicIp, error) {
    42  	s := new(PublicIp)
    43  	err := r.ExtractIntoStructPtr(s, "publicip")
    44  	return s, err
    45  }
    46  
    47  // DeleteResult is a struct of delete result
    48  type DeleteResult struct {
    49  	golangsdk.ErrResult
    50  }
    51  
    52  // UpdateResult is a struct which contains the result of update method
    53  type UpdateResult struct {
    54  	golangsdk.Result
    55  }
    56  
    57  func (r UpdateResult) Extract() (*PublicIp, error) {
    58  	s := new(PublicIp)
    59  	err := r.ExtractIntoStructPtr(s, "publicip")
    60  	return s, err
    61  }
    62  
    63  // EipPage is a single page of Flavor results.
    64  type EipPage struct {
    65  	pagination.MarkerPageBase
    66  }
    67  
    68  // IsEmpty returns true if a page contains no results.
    69  func (r EipPage) IsEmpty() (bool, error) {
    70  	eips, err := ExtractEips(r)
    71  	return len(eips) == 0, err
    72  }
    73  
    74  // LastMarker returns the last Eip ID in a ListResult.
    75  func (r EipPage) LastMarker() (string, error) {
    76  	eips, err := ExtractEips(r)
    77  	if err != nil {
    78  		return "", err
    79  	}
    80  	if len(eips) == 0 {
    81  		return "", nil
    82  	}
    83  	return eips[len(eips)-1].ID, nil
    84  }
    85  
    86  // ExtractEips extracts and returns Public IPs. It is used while iterating over a public ips.
    87  func ExtractEips(r pagination.Page) ([]PublicIp, error) {
    88  	var s []PublicIp
    89  	err := (r.(EipPage)).ExtractIntoSlicePtr(&s, "publicips")
    90  	return s, err
    91  }