github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/hypervisors/requests.go (about) 1 package hypervisors 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 8 ) 9 10 // ListOptsBuilder allows extensions to add additional parameters to the 11 // List request. 12 type ListOptsBuilder interface { 13 ToHypervisorListQuery() (string, error) 14 } 15 16 // ListOpts allows the filtering and sorting of paginated collections through 17 // the API. Filtering is achieved by passing in struct field values that map to 18 // the server attributes you want to see returned. Marker and Limit are used 19 // for pagination. 20 type ListOpts struct { 21 // Limit is an integer value for the limit of values to return. 22 // This requires microversion 2.33 or later. 23 Limit *int `q:"limit"` 24 25 // Marker is the ID of the last-seen item as a UUID. 26 // This requires microversion 2.53 or later. 27 Marker *string `q:"marker"` 28 29 // HypervisorHostnamePattern is the hypervisor hostname or a portion of it. 30 // This requires microversion 2.53 or later 31 HypervisorHostnamePattern *string `q:"hypervisor_hostname_pattern"` 32 33 // WithServers is a bool to include all servers which belong to each hypervisor 34 // This requires microversion 2.53 or later 35 WithServers *bool `q:"with_servers"` 36 } 37 38 // ToHypervisorListQuery formats a ListOpts into a query string. 39 func (opts ListOpts) ToHypervisorListQuery() (string, error) { 40 q, err := gophercloud.BuildQueryString(opts) 41 return q.String(), err 42 } 43 44 // List makes a request against the API to list hypervisors. 45 func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 46 url := hypervisorsListDetailURL(client) 47 if opts != nil { 48 query, err := opts.ToHypervisorListQuery() 49 if err != nil { 50 return pagination.Pager{Err: err} 51 } 52 url += query 53 } 54 55 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 56 return HypervisorPage{pagination.SinglePageBase(r)} 57 }) 58 } 59 60 // Statistics makes a request against the API to get hypervisors statistics. 61 func GetStatistics(ctx context.Context, client *gophercloud.ServiceClient) (r StatisticsResult) { 62 resp, err := client.Get(ctx, hypervisorsStatisticsURL(client), &r.Body, &gophercloud.RequestOpts{ 63 OkCodes: []int{200}, 64 }) 65 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 66 return 67 } 68 69 // Get makes a request against the API to get details for specific hypervisor. 70 func Get(ctx context.Context, client *gophercloud.ServiceClient, hypervisorID string) (r HypervisorResult) { 71 resp, err := client.Get(ctx, hypervisorsGetURL(client, hypervisorID), &r.Body, &gophercloud.RequestOpts{ 72 OkCodes: []int{200}, 73 }) 74 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 75 return 76 } 77 78 // GetUptime makes a request against the API to get uptime for specific hypervisor. 79 func GetUptime(ctx context.Context, client *gophercloud.ServiceClient, hypervisorID string) (r UptimeResult) { 80 resp, err := client.Get(ctx, hypervisorsUptimeURL(client, hypervisorID), &r.Body, &gophercloud.RequestOpts{ 81 OkCodes: []int{200}, 82 }) 83 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 84 return 85 }