github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetalintrospection/v1/introspection/requests.go (about) 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 resp, err := client.Get(introspectionURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{ 52 OkCodes: []int{200}, 53 }) 54 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 55 return 56 } 57 58 // StartOptsBuilder allows extensions to add additional parameters to the 59 // Start request. 60 type StartOptsBuilder interface { 61 ToStartIntrospectionQuery() (string, error) 62 } 63 64 // StartOpts represents options to start an introspection. 65 type StartOpts struct { 66 // Whether the current installation of ironic-inspector can manage PXE booting of nodes. 67 ManageBoot *bool `q:"manage_boot"` 68 } 69 70 // ToStartIntrospectionQuery converts a StartOpts into a request. 71 func (opts StartOpts) ToStartIntrospectionQuery() (string, error) { 72 q, err := gophercloud.BuildQueryString(opts) 73 return q.String(), err 74 } 75 76 // StartIntrospection initiate hardware introspection for node NodeID . 77 // All power management configuration for this node needs to be done prior to calling the endpoint. 78 func StartIntrospection(client *gophercloud.ServiceClient, nodeID string, opts StartOptsBuilder) (r StartResult) { 79 _, err := opts.ToStartIntrospectionQuery() 80 if err != nil { 81 r.Err = err 82 return 83 } 84 85 resp, err := client.Post(introspectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ 86 OkCodes: []int{202}, 87 }) 88 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 89 return 90 } 91 92 // AbortIntrospection abort running introspection. 93 func AbortIntrospection(client *gophercloud.ServiceClient, nodeID string) (r AbortResult) { 94 resp, err := client.Post(abortIntrospectionURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ 95 OkCodes: []int{202}, 96 }) 97 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 98 return 99 } 100 101 // GetIntrospectionData return stored data from successful introspection. 102 func GetIntrospectionData(client *gophercloud.ServiceClient, nodeID string) (r DataResult) { 103 resp, err := client.Get(introspectionDataURL(client, nodeID), &r.Body, &gophercloud.RequestOpts{ 104 OkCodes: []int{200}, 105 }) 106 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 107 return 108 } 109 110 // ReApplyIntrospection triggers introspection on stored unprocessed data. 111 // No data is allowed to be sent along with the request. 112 func ReApplyIntrospection(client *gophercloud.ServiceClient, nodeID string) (r ApplyDataResult) { 113 resp, err := client.Post(introspectionUnprocessedDataURL(client, nodeID), nil, nil, &gophercloud.RequestOpts{ 114 OkCodes: []int{202}, 115 }) 116 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 117 return 118 }