github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/hypervisors/requests.go (about)

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