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

     1  package eips
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk/openstack/networking/v1/bandwidths"
     5  	"github.com/chnsz/golangsdk/pagination"
     6  )
     7  
     8  type PublicIp struct {
     9  	ID                  string   `json:"id"`
    10  	Status              string   `json:"status"`
    11  	Type                string   `json:"publicip_pool_name"`
    12  	PublicAddress       string   `json:"public_ip_address"`
    13  	PublicIpv6Address   string   `json:"public_ipv6_address"`
    14  	EnterpriseProjectID string   `json:"enterprise_project_id"`
    15  	IpVersion           int      `json:"ip_version"`
    16  	Alias               string   `json:"alias"`
    17  	BillingInfo         string   `json:"billing_info"`
    18  	CreatedAt           string   `json:"created_at"`
    19  	UpdatedAt           string   `json:"updated_at"`
    20  	Tags                []string `json:"tags"`
    21  
    22  	AssociateInstanceType string `json:"associate_instance_type"`
    23  	AssociateInstanceID   string `json:"associate_instance_id"`
    24  
    25  	Bandwidth bandwidths.BandWidth `json:"bandwidth"`
    26  
    27  	// Vnic return the port info if EIP associate to an instance with port
    28  	Vnic Vnic `json:"vnic"`
    29  }
    30  
    31  type Vnic struct {
    32  	PrivateAddress string `json:"private_ip_address"`
    33  	PortID         string `json:"port_id"`
    34  	IntsanceID     string `json:"instance_id"`
    35  	IntsanceType   string `json:"instance_type"`
    36  }
    37  
    38  func (r GetResult) Extract() (PublicIp, error) {
    39  	var getResp struct {
    40  		IP PublicIp `json:"publicip"`
    41  	}
    42  	err := r.Result.ExtractInto(&getResp)
    43  	return getResp.IP, err
    44  }
    45  
    46  // listResp is the structure that represents the public ip list and page detail.
    47  type listResp struct {
    48  	// The list of the public ips.
    49  	PublicIPs []PublicIp `json:"publicips"`
    50  	// The page information.
    51  	PageInfo pageInfo `json:"page_info"`
    52  }
    53  
    54  // pageInfo is the structure that represents the page information.
    55  type pageInfo struct {
    56  	// The next marker information.
    57  	NextMarker string `json:"next_marker"`
    58  }
    59  
    60  type PublicIPPage struct {
    61  	pagination.MarkerPageBase
    62  }
    63  
    64  func ExtractPublicIPs(r pagination.Page) ([]PublicIp, error) {
    65  	var s listResp
    66  	err := r.(PublicIPPage).ExtractInto(&s)
    67  	return s.PublicIPs, err
    68  }
    69  
    70  // IsEmpty checks whether a NetworkPage struct is empty.
    71  func (r PublicIPPage) IsEmpty() (bool, error) {
    72  	s, err := ExtractPublicIPs(r)
    73  	return len(s) == 0, err
    74  }
    75  
    76  // LastMarker method returns the last public ip ID in a public ip page.
    77  func (p PublicIPPage) LastMarker() (string, error) {
    78  	tasks, err := ExtractPublicIPs(p)
    79  	if err != nil {
    80  		return "", err
    81  	}
    82  	if len(tasks) == 0 {
    83  		return "", nil
    84  	}
    85  	return tasks[len(tasks)-1].ID, nil
    86  }