github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/events/results.go (about)

     1  package events
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  // Event represents a detailed Event.
    11  type Event struct {
    12  	Action       string                 `json:"action"`
    13  	Cluster      string                 `json:"cluster"`
    14  	ClusterID    string                 `json:"cluster_id"`
    15  	ID           string                 `json:"id"`
    16  	Level        string                 `json:"level"`
    17  	Metadata     map[string]interface{} `json:"meta_data"`
    18  	OID          string                 `json:"oid"`
    19  	OName        string                 `json:"oname"`
    20  	OType        string                 `json:"otype"`
    21  	Project      string                 `json:"project"`
    22  	Status       string                 `json:"status"`
    23  	StatusReason string                 `json:"status_reason"`
    24  	Timestamp    time.Time              `json:"timestamp"`
    25  	User         string                 `json:"user"`
    26  }
    27  
    28  // commonResult is the response of a base result.
    29  type commonResult struct {
    30  	gophercloud.Result
    31  }
    32  
    33  // Extract interprets any commonResult-based result as an Event.
    34  func (r commonResult) Extract() (*Event, error) {
    35  	var s struct {
    36  		Event *Event `json:"event"`
    37  	}
    38  	err := r.ExtractInto(&s)
    39  	return s.Event, err
    40  }
    41  
    42  // GetResult is the response of a Get operations. Call its Extract method to
    43  // interpret it as an Event.
    44  type GetResult struct {
    45  	commonResult
    46  }
    47  
    48  // EventPage contains a single page of all events from a List call.
    49  type EventPage struct {
    50  	pagination.LinkedPageBase
    51  }
    52  
    53  // IsEmpty determines if a EventPage contains any results.
    54  func (r EventPage) IsEmpty() (bool, error) {
    55  	if r.StatusCode == 204 {
    56  		return true, nil
    57  	}
    58  
    59  	events, err := ExtractEvents(r)
    60  	return len(events) == 0, err
    61  }
    62  
    63  // ExtractEvents returns a slice of Events from the List operation.
    64  func ExtractEvents(r pagination.Page) ([]Event, error) {
    65  	var s struct {
    66  		Events []Event `json:"events"`
    67  	}
    68  	err := (r.(EventPage)).ExtractInto(&s)
    69  	return s.Events, err
    70  }