github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/flowlogs/results.go (about)

     1  package flowlogs
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // VPC flow log struct
     9  type FlowLog struct {
    10  	// Specifies the VPC flow log UUID.
    11  	ID string `json:"id"`
    12  
    13  	// Specifies the VPC flow log name.
    14  	Name string `json:"name"`
    15  
    16  	// Provides supplementary information about the VPC flow log.
    17  	Description string `json:"description"`
    18  
    19  	// Specifies the type of resource on which to create the VPC flow log.
    20  	ResourceType string `json:"resource_type"`
    21  
    22  	// Specifies the unique resource ID.
    23  	ResourceID string `json:"resource_id"`
    24  
    25  	// Specifies the type of traffic to log.
    26  	TrafficType string `json:"traffic_type"`
    27  
    28  	// Specifies the log group ID..
    29  	LogGroupID string `json:"log_group_id"`
    30  
    31  	// Specifies the log topic ID.
    32  	LogTopicID string `json:"log_topic_id"`
    33  
    34  	// Specifies the VPC flow log status, the value can be ACTIVE, DOWN or ERROR.
    35  	Status string `json:"status"`
    36  
    37  	// Specifies the project ID.
    38  	TenantID string `json:"tenant_id"`
    39  
    40  	// Specifies whether to enable the VPC flow log function.
    41  	AdminState bool `json:"admin_state"`
    42  
    43  	// Specifies the time when the VPC flow log was created.
    44  	CreatedAt string `json:"created_at"`
    45  
    46  	// Specifies the time when the VPC flow log was updated.
    47  	UpdatedAt string `json:"updated_at"`
    48  }
    49  
    50  // FlowLogPage is the page returned by a pager when traversing over a collection
    51  // of flow logs.
    52  type FlowLogPage struct {
    53  	pagination.LinkedPageBase
    54  }
    55  
    56  // NextPageURL is invoked when a paginated collection of flow logs has reached
    57  // the end of a page and the pager seeks to traverse over a new one. In order
    58  // to do this, it needs to construct the next page's URL.
    59  func (r FlowLogPage) NextPageURL() (string, error) {
    60  	var s struct {
    61  		Links []golangsdk.Link `json:"flowlogs_links"`
    62  	}
    63  	err := r.ExtractInto(&s)
    64  	if err != nil {
    65  		return "", err
    66  	}
    67  	return golangsdk.ExtractNextURL(s.Links)
    68  }
    69  
    70  // IsEmpty checks whether a FlowLogPage struct is empty.
    71  func (r FlowLogPage) IsEmpty() (bool, error) {
    72  	is, err := ExtractFlowLogs(r)
    73  	return len(is) == 0, err
    74  }
    75  
    76  // ExtractFlowLogs accepts a Page struct, specifically a FlowLogPage struct,
    77  // and extracts the elements into a slice of FlowLog structs. In other words,
    78  // a generic collection is mapped into a relevant slice.
    79  func ExtractFlowLogs(r pagination.Page) ([]FlowLog, error) {
    80  	var s struct {
    81  		FlowLogs []FlowLog `json:"flow_logs"`
    82  	}
    83  	err := (r.(FlowLogPage)).ExtractInto(&s)
    84  	return s.FlowLogs, err
    85  }
    86  
    87  type commonResult struct {
    88  	golangsdk.Result
    89  }
    90  
    91  type CreateResult struct {
    92  	commonResult
    93  }
    94  
    95  func (r CreateResult) Extract() (*FlowLog, error) {
    96  	var entity FlowLog
    97  	err := r.ExtractIntoStructPtr(&entity, "flow_log")
    98  	return &entity, err
    99  }
   100  
   101  type DeleteResult struct {
   102  	golangsdk.ErrResult
   103  }
   104  
   105  type GetResult struct {
   106  	commonResult
   107  }
   108  
   109  func (r GetResult) Extract() (*FlowLog, error) {
   110  	var entity FlowLog
   111  	err := r.ExtractIntoStructPtr(&entity, "flow_log")
   112  	return &entity, err
   113  }
   114  
   115  type UpdateResult struct {
   116  	commonResult
   117  }
   118  
   119  func (r UpdateResult) Extract() (*FlowLog, error) {
   120  	var entity FlowLog
   121  	err := r.ExtractIntoStructPtr(&entity, "flow_log")
   122  	return &entity, err
   123  }