github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/orchestration/v1/stackevents/requests.go (about)

     1  package stackevents
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/vnpaycloud-console/gophercloud/v2"
     7  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     8  )
     9  
    10  // Find retrieves stack events for the given stack name.
    11  func Find(ctx context.Context, c *gophercloud.ServiceClient, stackName string) (r FindResult) {
    12  	resp, err := c.Get(ctx, findURL(c, stackName), &r.Body, nil)
    13  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    14  	return
    15  }
    16  
    17  // SortDir is a type for specifying in which direction to sort a list of events.
    18  type SortDir string
    19  
    20  // SortKey is a type for specifying by which key to sort a list of events.
    21  type SortKey string
    22  
    23  // ResourceStatus is a type for specifying by which resource status to filter a
    24  // list of events.
    25  type ResourceStatus string
    26  
    27  // ResourceAction is a type for specifying by which resource action to filter a
    28  // list of events.
    29  type ResourceAction string
    30  
    31  var (
    32  	// ResourceStatusInProgress is used to filter a List request by the 'IN_PROGRESS' status.
    33  	ResourceStatusInProgress ResourceStatus = "IN_PROGRESS"
    34  	// ResourceStatusComplete is used to filter a List request by the 'COMPLETE' status.
    35  	ResourceStatusComplete ResourceStatus = "COMPLETE"
    36  	// ResourceStatusFailed is used to filter a List request by the 'FAILED' status.
    37  	ResourceStatusFailed ResourceStatus = "FAILED"
    38  
    39  	// ResourceActionCreate is used to filter a List request by the 'CREATE' action.
    40  	ResourceActionCreate ResourceAction = "CREATE"
    41  	// ResourceActionDelete is used to filter a List request by the 'DELETE' action.
    42  	ResourceActionDelete ResourceAction = "DELETE"
    43  	// ResourceActionUpdate is used to filter a List request by the 'UPDATE' action.
    44  	ResourceActionUpdate ResourceAction = "UPDATE"
    45  	// ResourceActionRollback is used to filter a List request by the 'ROLLBACK' action.
    46  	ResourceActionRollback ResourceAction = "ROLLBACK"
    47  	// ResourceActionSuspend is used to filter a List request by the 'SUSPEND' action.
    48  	ResourceActionSuspend ResourceAction = "SUSPEND"
    49  	// ResourceActionResume is used to filter a List request by the 'RESUME' action.
    50  	ResourceActionResume ResourceAction = "RESUME"
    51  	// ResourceActionAbandon is used to filter a List request by the 'ABANDON' action.
    52  	ResourceActionAbandon ResourceAction = "ABANDON"
    53  
    54  	// SortAsc is used to sort a list of stacks in ascending order.
    55  	SortAsc SortDir = "asc"
    56  	// SortDesc is used to sort a list of stacks in descending order.
    57  	SortDesc SortDir = "desc"
    58  
    59  	// SortName is used to sort a list of stacks by name.
    60  	SortName SortKey = "name"
    61  	// SortResourceType is used to sort a list of stacks by resource type.
    62  	SortResourceType SortKey = "resource_type"
    63  	// SortCreatedAt is used to sort a list of stacks by date created.
    64  	SortCreatedAt SortKey = "created_at"
    65  )
    66  
    67  // ListOptsBuilder allows extensions to add additional parameters to the
    68  // List request.
    69  type ListOptsBuilder interface {
    70  	ToStackEventListQuery() (string, error)
    71  }
    72  
    73  // ListOpts allows the filtering and sorting of paginated collections through
    74  // the API. Marker and Limit are used for pagination.
    75  type ListOpts struct {
    76  	// The stack resource ID with which to start the listing.
    77  	Marker string `q:"marker"`
    78  	// Integer value for the limit of values to return.
    79  	Limit int `q:"limit"`
    80  	// Filters the event list by the specified ResourceAction. You can use this
    81  	// filter multiple times to filter by multiple resource actions: CREATE, DELETE,
    82  	// UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
    83  	ResourceActions []ResourceAction `q:"resource_action"`
    84  	// Filters the event list by the specified resource_status. You can use this
    85  	// filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
    86  	// COMPLETE or FAILED.
    87  	ResourceStatuses []ResourceStatus `q:"resource_status"`
    88  	// Filters the event list by the specified resource_name. You can use this
    89  	// filter multiple times to filter by multiple resource names.
    90  	ResourceNames []string `q:"resource_name"`
    91  	// Filters the event list by the specified resource_type. You can use this
    92  	// filter multiple times to filter by multiple resource types: OS::Nova::Server,
    93  	// OS::Cinder::Volume, and so on.
    94  	ResourceTypes []string `q:"resource_type"`
    95  	// Sorts the event list by: resource_type or created_at.
    96  	SortKey SortKey `q:"sort_keys"`
    97  	// The sort direction of the event list. Which is asc (ascending) or desc (descending).
    98  	SortDir SortDir `q:"sort_dir"`
    99  }
   100  
   101  // ToStackEventListQuery formats a ListOpts into a query string.
   102  func (opts ListOpts) ToStackEventListQuery() (string, error) {
   103  	q, err := gophercloud.BuildQueryString(opts)
   104  	return q.String(), err
   105  }
   106  
   107  // List makes a request against the API to list resources for the given stack.
   108  func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
   109  	url := listURL(client, stackName, stackID)
   110  	if opts != nil {
   111  		query, err := opts.ToStackEventListQuery()
   112  		if err != nil {
   113  			return pagination.Pager{Err: err}
   114  		}
   115  		url += query
   116  	}
   117  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   118  		p := EventPage{pagination.MarkerPageBase{PageResult: r}}
   119  		p.MarkerPageBase.Owner = p
   120  		return p
   121  	})
   122  }
   123  
   124  // ListResourceEventsOptsBuilder allows extensions to add additional parameters to the
   125  // ListResourceEvents request.
   126  type ListResourceEventsOptsBuilder interface {
   127  	ToResourceEventListQuery() (string, error)
   128  }
   129  
   130  // ListResourceEventsOpts allows the filtering and sorting of paginated resource events through
   131  // the API. Marker and Limit are used for pagination.
   132  type ListResourceEventsOpts struct {
   133  	// The stack resource ID with which to start the listing.
   134  	Marker string `q:"marker"`
   135  	// Integer value for the limit of values to return.
   136  	Limit int `q:"limit"`
   137  	// Filters the event list by the specified ResourceAction. You can use this
   138  	// filter multiple times to filter by multiple resource actions: CREATE, DELETE,
   139  	// UPDATE, ROLLBACK, SUSPEND, RESUME or ADOPT.
   140  	ResourceActions []string `q:"resource_action"`
   141  	// Filters the event list by the specified resource_status. You can use this
   142  	// filter multiple times to filter by multiple resource statuses: IN_PROGRESS,
   143  	// COMPLETE or FAILED.
   144  	ResourceStatuses []string `q:"resource_status"`
   145  	// Filters the event list by the specified resource_name. You can use this
   146  	// filter multiple times to filter by multiple resource names.
   147  	ResourceNames []string `q:"resource_name"`
   148  	// Filters the event list by the specified resource_type. You can use this
   149  	// filter multiple times to filter by multiple resource types: OS::Nova::Server,
   150  	// OS::Cinder::Volume, and so on.
   151  	ResourceTypes []string `q:"resource_type"`
   152  	// Sorts the event list by: resource_type or created_at.
   153  	SortKey SortKey `q:"sort_keys"`
   154  	// The sort direction of the event list. Which is asc (ascending) or desc (descending).
   155  	SortDir SortDir `q:"sort_dir"`
   156  }
   157  
   158  // ToResourceEventListQuery formats a ListResourceEventsOpts into a query string.
   159  func (opts ListResourceEventsOpts) ToResourceEventListQuery() (string, error) {
   160  	q, err := gophercloud.BuildQueryString(opts)
   161  	return q.String(), err
   162  }
   163  
   164  // ListResourceEvents makes a request against the API to list resources for the given stack.
   165  func ListResourceEvents(client *gophercloud.ServiceClient, stackName, stackID, resourceName string, opts ListResourceEventsOptsBuilder) pagination.Pager {
   166  	url := listResourceEventsURL(client, stackName, stackID, resourceName)
   167  	if opts != nil {
   168  		query, err := opts.ToResourceEventListQuery()
   169  		if err != nil {
   170  			return pagination.Pager{Err: err}
   171  		}
   172  		url += query
   173  	}
   174  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
   175  		p := EventPage{pagination.MarkerPageBase{PageResult: r}}
   176  		p.MarkerPageBase.Owner = p
   177  		return p
   178  	})
   179  }
   180  
   181  // Get retreives data for the given stack resource.
   182  func Get(ctx context.Context, c *gophercloud.ServiceClient, stackName, stackID, resourceName, eventID string) (r GetResult) {
   183  	resp, err := c.Get(ctx, getURL(c, stackName, stackID, resourceName, eventID), &r.Body, nil)
   184  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
   185  	return
   186  }