Skip to content

Commit

Permalink
service: generalize libvirt flag handling
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Polednik <[email protected]>
  • Loading branch information
mpolednik committed Nov 29, 2017
1 parent 4570de7 commit 469c2cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 3 additions & 4 deletions cmd/virt-handler/virt-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const (

type virtHandlerApp struct {
service.ServiceListen
service.ServiceLibvirt
HostOverride string
LibvirtUri string
VirtShareDir string
EphemeralDiskDir string
WatchdogTimeoutDuration time.Duration
Expand Down Expand Up @@ -197,11 +197,10 @@ func (app *virtHandlerApp) AddFlags() {

app.BindAddress = defaultHost
app.Port = defaultPort
app.LibvirtUri = libvirtUri

app.AddCommonFlags()

flag.StringVar(&app.LibvirtUri, "libvirt-uri", libvirtUri,
"Libvirt connection string")
app.AddLibvirtFlags()

flag.StringVar(&app.HostOverride, "hostname-override", hostOverride,
"Name under which the node is registered in kubernetes, where this virt-handler instance is running on")
Expand Down
6 changes: 3 additions & 3 deletions cmd/virt-manifest/virt-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (

type virtManifestApp struct {
service.ServiceListen
service.ServiceLibvirt
LibvirtUri string
}

Expand Down Expand Up @@ -84,11 +85,10 @@ func (app *virtManifestApp) AddFlags() {

app.BindAddress = defaultHost
app.Port = defaultPort
app.LibvirtUri = libvirtUri

app.AddCommonFlags()

flag.StringVar(&app.LibvirtUri, "libvirt-uri", libvirtUri,
"Libvirt connection string")
app.AddLibvirtFlags()

flag.Parse()
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type ServiceListen struct {
Port int
}

type ServiceLibvirt struct {
LibvirtUri string
}

func (service *ServiceListen) Address() string {
return fmt.Sprintf("%s:%s", service.BindAddress, strconv.Itoa(service.Port))
}
Expand All @@ -50,3 +54,8 @@ func (service *ServiceListen) AddCommonFlags() {
flag.StringVar(&service.BindAddress, "listen", service.BindAddress, "Address where to listen on")
flag.IntVar(&service.Port, "port", service.Port, "Port to listen on")
}

func (service *ServiceLibvirt) AddLibvirtFlags() {
flag.StringVar(&service.Uri, "libvirt-uri", service.Uri, "Libvirt connection string")

}

0 comments on commit 469c2cf

Please sign in to comment.