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