@@ -27,19 +27,14 @@ type ZonedDialer struct {
2727 Zone string
2828}
2929
30- type provideLibvirtParams struct {
31- fx.In
32-
33- Log * zap.Logger
34- Dialers []* ZonedDialer `group:"libvirt.dialers"`
35- }
36-
37- func ProvideLibvirt (lc fx.Lifecycle , params provideLibvirtParams ) * Hypervisors {
38- virts := make ([]* ZonedHypervisor , len (params .Dialers ))
39- for idx , dialer := range params .Dialers {
30+ func ProvideLibvirt (lc fx.Lifecycle , log * zap.Logger , config * config.Config ) * Hypervisors {
31+ dialers := buildDialers (log , config )
32+ virts := make ([]* ZonedHypervisor , len (dialers ))
33+ for idx , dialer := range dialers {
4034 virts [idx ] = & ZonedHypervisor {Libvirt : libvirt .NewWithDialer (dialer ), Zone : dialer .Zone }
4135 }
4236 lc .Append (fx .StartStopHook (func () error {
37+ log .Info ("connection to hypervisors" , zap .Int ("count" , len (virts )))
4338 for _ , virt := range virts {
4439 if err := virt .Connect (); err != nil {
4540 return err
@@ -48,7 +43,7 @@ func ProvideLibvirt(lc fx.Lifecycle, params provideLibvirtParams) *Hypervisors {
4843 if err != nil {
4944 return err
5045 }
51- params . Log .Info ("libvirt connected" , zap .Uint64 ("version" , version ))
46+ log .Info ("libvirt connected" , zap .Uint64 ("version" , version ))
5247 }
5348 return nil
5449 }, func () error {
@@ -59,16 +54,10 @@ func ProvideLibvirt(lc fx.Lifecycle, params provideLibvirtParams) *Hypervisors {
5954 }
6055 return nil
6156 }))
62- return & Hypervisors {Libvirts : virts , Logger : params .Log .With (zap .String ("tier" , "hypervisor" ))}
63- }
64-
65- type provideLibvirtDialerOutput struct {
66- fx.Out
67-
68- Dialers []* ZonedDialer `group:"libvirt.dialers"`
57+ return & Hypervisors {Libvirts : virts , Logger : log .With (zap .String ("tier" , "hypervisor" ))}
6958}
7059
71- func ProvideLibvirtDialer (log * zap.Logger , config * config.Config ) provideLibvirtDialerOutput {
60+ func buildDialers (log * zap.Logger , config * config.Config ) [] * ZonedDialer {
7261 buildDialer := func (uri string ) * ZonedDialer {
7362 endpoint , err := url .Parse (uri )
7463 if err != nil {
@@ -97,7 +86,7 @@ func ProvideLibvirtDialer(log *zap.Logger, config *config.Config) provideLibvirt
9786 dialers [idx + 1 ] = buildDialer (zone .LibvirtEndpoint )
9887 dialers [idx + 1 ].Zone = zone .Name
9988 }
100- return provideLibvirtDialerOutput { Dialers : dialers }
89+ return dialers
10190}
10291
10392func (h * Hypervisors ) Zone (zone string ) (* libvirt.Libvirt , error ) {
0 commit comments