瀏覽代碼

daemon: SystemInfo() extract container counts to a helper function

This makes it more inline with other data we collect, and can be used to
make some info optional at some point.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 年之前
父節點
當前提交
a27f8aecad
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. 9 5
      daemon/info.go

+ 9 - 5
daemon/info.go

@@ -30,14 +30,9 @@ func (daemon *Daemon) SystemInfo() *types.Info {
 	defer metrics.StartTimer(hostInfoFunctions.WithValues("system_info"))()
 	defer metrics.StartTimer(hostInfoFunctions.WithValues("system_info"))()
 
 
 	sysInfo := daemon.RawSysInfo()
 	sysInfo := daemon.RawSysInfo()
-	cRunning, cPaused, cStopped := stateCtr.get()
 
 
 	v := &types.Info{
 	v := &types.Info{
 		ID:                 daemon.ID,
 		ID:                 daemon.ID,
-		Containers:         cRunning + cPaused + cStopped,
-		ContainersRunning:  cRunning,
-		ContainersPaused:   cPaused,
-		ContainersStopped:  cStopped,
 		Images:             daemon.imageService.CountImages(),
 		Images:             daemon.imageService.CountImages(),
 		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
 		IPv4Forwarding:     !sysInfo.IPv4ForwardingDisabled,
 		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
 		BridgeNfIptables:   !sysInfo.BridgeNFCallIPTablesDisabled,
@@ -70,6 +65,7 @@ func (daemon *Daemon) SystemInfo() *types.Info {
 		Isolation:          daemon.defaultIsolation,
 		Isolation:          daemon.defaultIsolation,
 	}
 	}
 
 
+	daemon.fillContainerStates(v)
 	daemon.fillAPIInfo(v)
 	daemon.fillAPIInfo(v)
 	// Retrieve platform specific info
 	// Retrieve platform specific info
 	daemon.fillPlatformInfo(v, sysInfo)
 	daemon.fillPlatformInfo(v, sysInfo)
@@ -181,6 +177,14 @@ func (daemon *Daemon) fillSecurityOptions(v *types.Info, sysInfo *sysinfo.SysInf
 	v.SecurityOptions = securityOptions
 	v.SecurityOptions = securityOptions
 }
 }
 
 
+func (daemon *Daemon) fillContainerStates(v *types.Info) {
+	cRunning, cPaused, cStopped := stateCtr.get()
+	v.Containers = cRunning + cPaused + cStopped
+	v.ContainersPaused = cPaused
+	v.ContainersRunning = cRunning
+	v.ContainersStopped = cStopped
+}
+
 func (daemon *Daemon) fillAPIInfo(v *types.Info) {
 func (daemon *Daemon) fillAPIInfo(v *types.Info) {
 	const warn string = `
 	const warn string = `
          Access to the remote API is equivalent to root access on the host. Refer
          Access to the remote API is equivalent to root access on the host. Refer