mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 11:00:25 +00:00
metadata: Improve logging
Implementing a String() interface for each provider makes it easier for users to prefix log strings with the provider. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
75f5f058b4
commit
626f02def2
@ -29,6 +29,9 @@ const (
|
|||||||
|
|
||||||
// Provider is a generic interface for metadata/userdata providers.
|
// Provider is a generic interface for metadata/userdata providers.
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
|
// String should return a unique name for the Provider
|
||||||
|
String() string
|
||||||
|
|
||||||
// Probe returns true if the provider was detected.
|
// Probe returns true if the provider was detected.
|
||||||
Probe() bool
|
Probe() bool
|
||||||
|
|
||||||
@ -58,6 +61,7 @@ func main() {
|
|||||||
found := false
|
found := false
|
||||||
for _, p := range netProviders {
|
for _, p := range netProviders {
|
||||||
if p.Probe() {
|
if p.Probe() {
|
||||||
|
log.Printf("%s: Probe succeeded", p)
|
||||||
userdata, err = p.Extract()
|
userdata, err = p.Extract()
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@ -78,6 +82,7 @@ func main() {
|
|||||||
|
|
||||||
for _, p := range cdromProviders {
|
for _, p := range cdromProviders {
|
||||||
if p.Probe() {
|
if p.Probe() {
|
||||||
|
log.Printf("%s: Probe succeeded", p)
|
||||||
userdata, err = p.Extract()
|
userdata, err = p.Extract()
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
@ -22,12 +21,13 @@ func NewCDROM() *ProviderCDROM {
|
|||||||
return &ProviderCDROM{}
|
return &ProviderCDROM{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProviderCDROM) String() string {
|
||||||
|
return "CDROM"
|
||||||
|
}
|
||||||
|
|
||||||
// Probe checks if the CD has the right file
|
// Probe checks if the CD has the right file
|
||||||
func (p *ProviderCDROM) Probe() bool {
|
func (p *ProviderCDROM) Probe() bool {
|
||||||
_, err := os.Stat(path.Join(MountPoint, configFile))
|
_, err := os.Stat(path.Join(MountPoint, configFile))
|
||||||
if err != nil {
|
|
||||||
log.Printf("CDROM: Probe -> %s", err)
|
|
||||||
}
|
|
||||||
return (!os.IsNotExist(err))
|
return (!os.IsNotExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,14 @@ func NewGCP() *ProviderGCP {
|
|||||||
return &ProviderGCP{}
|
return &ProviderGCP{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProviderGCP) String() string {
|
||||||
|
return "GCP"
|
||||||
|
}
|
||||||
|
|
||||||
// Probe checks if we are running on GCP
|
// Probe checks if we are running on GCP
|
||||||
func (p *ProviderGCP) Probe() bool {
|
func (p *ProviderGCP) Probe() bool {
|
||||||
// Getting the hostname should always work...
|
// Getting the hostname should always work...
|
||||||
_, err := gcpGet(instance + "hostname")
|
_, err := gcpGet(instance + "hostname")
|
||||||
log.Printf("GCP: Probe -> %s", err)
|
|
||||||
return (err == nil)
|
return (err == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user