@@ -19,6 +19,7 @@ package openstack
1919
2020import (
2121 "context"
22+ "fmt"
2223 "net/http"
2324
2425 "github.com/gophercloud/gophercloud/v2"
@@ -61,17 +62,8 @@ type HyperVisorsDetails struct {
6162 Hypervisors []Hypervisor `json:"hypervisors"`
6263}
6364
64- type NoHypervisorError struct {}
65-
66- func (* NoHypervisorError ) Error () string {
67- return "no hypervisor found"
68- }
69-
70- type MultipleHypervisorsError struct {}
71-
72- func (* MultipleHypervisorsError ) Error () string {
73- return "multiple hypervisors found"
74- }
65+ var ErrNoHypervisor = fmt .Errorf ("no hypervisor found" )
66+ var ErrMultipleHypervisors = fmt .Errorf ("multiple hypervisors found" )
7567
7668func GetHypervisorByName (ctx context.Context , sc * gophercloud.ServiceClient , hypervisorHostnamePattern string , withServers bool ) (* Hypervisor , error ) {
7769 listOpts := hypervisors.ListOpts {
@@ -82,7 +74,7 @@ func GetHypervisorByName(ctx context.Context, sc *gophercloud.ServiceClient, hyp
8274 pages , err := hypervisors .List (sc , listOpts ).AllPages (ctx )
8375 if err != nil {
8476 if gophercloud .ResponseCodeIs (err , http .StatusNotFound ) {
85- return nil , & NoHypervisorError {}
77+ return nil , ErrNoHypervisor
8678 }
8779 return nil , err
8880 }
@@ -94,9 +86,9 @@ func GetHypervisorByName(ctx context.Context, sc *gophercloud.ServiceClient, hyp
9486 }
9587
9688 if len (h .Hypervisors ) == 0 {
97- return nil , & NoHypervisorError {}
89+ return nil , ErrNoHypervisor
9890 } else if len (h .Hypervisors ) > 1 {
99- return nil , & MultipleHypervisorsError {}
91+ return nil , ErrMultipleHypervisors
10092 }
10193
10294 return & h .Hypervisors [0 ], nil
0 commit comments