Merge pull request #15796 from azurezk/add-size-to-inspect

add container size info to inspect
This commit is contained in:
Vincent Demeester
2015-10-13 23:16:10 +02:00
13 changed files with 108 additions and 8 deletions
+14 -4
View File
@@ -11,7 +11,7 @@ import (
// ContainerInspect returns low-level information about a
// container. Returns an error if the container cannot be found, or if
// there is an error getting the data.
func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error) {
func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.ContainerJSON, error) {
container, err := daemon.Get(name)
if err != nil {
return nil, err
@@ -20,7 +20,7 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
container.Lock()
defer container.Unlock()
base, err := daemon.getInspectData(container)
base, err := daemon.getInspectData(container, size)
if err != nil {
return nil, err
}
@@ -40,7 +40,7 @@ func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, er
container.Lock()
defer container.Unlock()
base, err := daemon.getInspectData(container)
base, err := daemon.getInspectData(container, false)
if err != nil {
return nil, err
}
@@ -54,7 +54,7 @@ func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, er
return &v1p20.ContainerJSON{base, mountPoints, config}, nil
}
func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
func (daemon *Daemon) getInspectData(container *Container, size bool) (*types.ContainerJSONBase, error) {
// make a copy to play with
hostConfig := *container.hostConfig
@@ -106,6 +106,16 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON
HostConfig: &hostConfig,
}
var (
sizeRw int64
sizeRootFs int64
)
if size {
sizeRw, sizeRootFs = container.getSize()
contJSONBase.SizeRw = &sizeRw
contJSONBase.SizeRootFs = &sizeRootFs
}
// Now set any platform-specific fields
contJSONBase = setPlatformSpecificContainerFields(container, contJSONBase)
+1 -1
View File
@@ -27,7 +27,7 @@ func (daemon *Daemon) ContainerInspectPre120(name string) (*v1p19.ContainerJSON,
container.Lock()
defer container.Unlock()
base, err := daemon.getInspectData(container)
base, err := daemon.getInspectData(container, false)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -13,5 +13,5 @@ func addMountPoints(container *Container) []types.MountPoint {
// ContainerInspectPre120 get containers for pre 1.20 APIs.
func (daemon *Daemon) ContainerInspectPre120(name string) (*types.ContainerJSON, error) {
return daemon.ContainerInspect(name)
return daemon.ContainerInspect(name, false)
}