|
| 1 | +package introspection |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/gophercloud/gophercloud" |
| 5 | + "github.com/gophercloud/gophercloud/pagination" |
| 6 | +) |
| 7 | + |
| 8 | +// ListIntrospectionsOptsBuilder allows extensions to add additional parameters to the |
| 9 | +// ListIntrospections request. |
| 10 | +type ListIntrospectionsOptsBuilder interface { |
| 11 | + ToIntrospectionsListQuery() (string, error) |
| 12 | +} |
| 13 | + |
| 14 | +// ListIntrospectionsOpts allows the filtering and sorting of paginated collections through |
| 15 | +// the Introspection API. Filtering is achieved by passing in struct field values that map to |
| 16 | +// the node attributes you want to see returned. Marker and Limit are used |
| 17 | +// for pagination. |
| 18 | +type ListIntrospectionsOpts struct { |
| 19 | + // Requests a page size of items. |
| 20 | + Limit int `q:"limit"` |
| 21 | + |
| 22 | + // The ID of the last-seen item. |
| 23 | + Marker string `q:"marker"` |
| 24 | +} |
| 25 | + |
| 26 | +// ToIntrospectionsListQuery formats a ListIntrospectionsOpts into a query string. |
| 27 | +func (opts ListIntrospectionsOpts) ToIntrospectionsListQuery() (string, error) { |
| 28 | + q, err := gophercloud.BuildQueryString(opts) |
| 29 | + return q.String(), err |
| 30 | +} |
| 31 | + |
| 32 | +// ListIntrospections makes a request against the Inspector API to list the current introspections. |
| 33 | +func ListIntrospections(client *gophercloud.ServiceClient, opts ListIntrospectionsOptsBuilder) pagination.Pager { |
| 34 | + url := listIntrospectionsURL(client) |
| 35 | + if opts != nil { |
| 36 | + query, err := opts.ToIntrospectionsListQuery() |
| 37 | + if err != nil { |
| 38 | + return pagination.Pager{Err: err} |
| 39 | + } |
| 40 | + url += query |
| 41 | + } |
| 42 | + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
| 43 | + var rpage = IntrospectionPage{pagination.LinkedPageBase{PageResult: r}} |
| 44 | + return rpage |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +// GetIntrospectionStatus makes a request against the Inspector API to get the |
| 49 | +// status of a single introspection. |
| 50 | +func GetIntrospectionStatus(client *gophercloud.ServiceClient, nodeID string) (r GetIntrospectionStatusResult) { |
| 51 | + _, r.Err = client.Get(introspectionURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{ |
| 52 | + OkCodes: []int{200}, |
| 53 | + }) |
| 54 | + return |
| 55 | +} |
| 56 | + |
| 57 | +// StartOptsBuilder allows extensions to add additional parameters to the |
| 58 | +// Start request. |
| 59 | +type StartOptsBuilder interface { |
| 60 | + ToStartIntrospectionQuery() (string, error) |
| 61 | +} |
| 62 | + |
| 63 | +// StartOpts represents options to start an introspection. |
| 64 | +type StartOpts struct { |
| 65 | + // Whether the current installation of ironic-inspector can manage PXE booting of nodes. |
| 66 | + ManageBoot *bool `q:"manage_boot"` |
| 67 | +} |
| 68 | + |
| 69 | +// ToStartIntrospectionQuery converts a StartOpts into a request. |
| 70 | +func (opts StartOpts) ToStartIntrospectionQuery() (string, error) { |
| 71 | + q, err := gophercloud.BuildQueryString(opts) |
| 72 | + return q.String(), err |
| 73 | +} |
| 74 | + |
| 75 | +// StartIntrospection initiate hardware introspection for node NodeID . |
| 76 | +// All power management configuration for this node needs to be done prior to calling the endpoint. |
| 77 | +func StartIntrospection(client *gophercloud.ServiceClient, nodeID string, opts StartOptsBuilder) (r StartResult) { |
| 78 | + _, err := opts.ToStartIntrospectionQuery() |
| 79 | + if err != nil { |
| 80 | + r.Err = err |
| 81 | + return |
| 82 | + } |
| 83 | + |
| 84 | + _, r.Err = client.Post(introspectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ |
| 85 | + OkCodes: []int{202}, |
| 86 | + }) |
| 87 | + |
| 88 | + return |
| 89 | +} |
| 90 | + |
| 91 | +// AbortIntrospection abort running introspection. |
| 92 | +func AbortIntrospection(client *gophercloud.ServiceClient, nodeID string) (r AbortResult) { |
| 93 | + _, r.Err = client.Post(abortIntrospectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ |
| 94 | + OkCodes: []int{202}, |
| 95 | + }) |
| 96 | + |
| 97 | + return |
| 98 | +} |
| 99 | + |
| 100 | +// GetIntrospectionData return stored data from successful introspection. |
| 101 | +func GetIntrospectionData(client *gophercloud.ServiceClient, nodeID string) (r DataResult) { |
| 102 | + _, r.Err = client.Get(introspectionDataURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{ |
| 103 | + OkCodes: []int{200}, |
| 104 | + }) |
| 105 | + return |
| 106 | +} |
| 107 | + |
| 108 | +// ReApplyIntrospection triggers introspection on stored unprocessed data. |
| 109 | +// No data is allowed to be sent along with the request. |
| 110 | +func ReApplyIntrospection(client *gophercloud.ServiceClient, nodeID string) (r ApplyDataResult) { |
| 111 | + _, r.Err = client.Post(introspectionUnprocessedDataURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ |
| 112 | + OkCodes: []int{202}, |
| 113 | + }) |
| 114 | + |
| 115 | + return |
| 116 | +} |
0 commit comments