Skip to content

Commit 55204d8

Browse files
authored
Enable cpu/mem settings in docker inspect (#8420)
1 parent 266accf commit 55204d8

7 files changed

Lines changed: 40 additions & 1 deletion

File tree

lib/apiservers/engine/proxy/container_proxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,8 @@ func hostConfigFromContainerInfo(vc *viccontainer.VicContainer, info *models.Con
12491249
//
12501250
// The values we fill out below is an abridged list of the original struct.
12511251
resourceConfig := container.Resources{
1252-
Memory: info.ContainerConfig.MemorySizeMB,
1252+
Memory: info.ContainerConfig.MemorySizeMB,
1253+
CpusetCpus: strconv.FormatInt((int64)(info.ContainerConfig.NumCPU), 10),
12531254
// Applicable to all platforms
12541255
// CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
12551256
// Memory int64 // Memory limit (in bytes)

lib/apiservers/portlayer/restapi/handlers/containers_handlers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ func convertContainerToContainerInfo(c *exec.Container) *models.ContainerInfo {
584584
info.ContainerConfig.RestartCount = int64(container.ExecConfig.Diagnostics.ResurrectionCount)
585585
info.ContainerConfig.StorageSize = container.VMUnsharedDisk
586586
info.ContainerConfig.MemorySizeMB = int64(container.MemorySizeMB)
587+
info.ContainerConfig.NumCPU = container.NumCPU
587588

588589
if container.ExecConfig.Annotations != nil && len(container.ExecConfig.Annotations) > 0 {
589590
info.ContainerConfig.Annotations = make(map[string]string)

lib/apiservers/portlayer/swagger.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,6 +3731,10 @@
37313731
},
37323732
"memorySizeMB": {
37333733
"type": "integer"
3734+
},
3735+
"numCpu": {
3736+
"type": "integer",
3737+
"format": "int32"
37343738
}
37353739
}
37363740
},

lib/portlayer/exec/commit.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"time"
2222

23+
"github.com/vmware/govmomi/vim25/mo"
2324
"github.com/vmware/govmomi/vim25/types"
2425
"github.com/vmware/vic/lib/portlayer/event/events"
2526
"github.com/vmware/vic/pkg/retry"
@@ -78,6 +79,15 @@ func Commit(ctx context.Context, sess *session.Session, h *Handle, waitTime *int
7879

7980
h.vm.DisableDestroy(op)
8081
c = newContainer(&h.containerBase)
82+
83+
var o mo.VirtualMachine
84+
if err := h.vm.Properties(op, h.vm.Reference(), []string{"summary"}, &o); err != nil {
85+
op.Errorf("An error occurred while retrieving summary information from the vm.")
86+
return err
87+
}
88+
c.MemorySizeMB = o.Summary.Config.MemorySizeMB
89+
c.NumCPU = o.Summary.Config.NumCpu
90+
8191
Containers.Put(c)
8292

8393
err = Config.addToVMGroup(op)

lib/portlayer/exec/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type ContainerInfo struct {
148148
state State
149149

150150
MemorySizeMB int32
151+
NumCPU int32
151152

152153
// Size of the leaf (unused)
153154
VMUnsharedDisk int64
@@ -950,6 +951,7 @@ func convertInfraContainers(ctx context.Context, sess *session.Session, vms []mo
950951
}
951952

952953
c.MemorySizeMB = v.Summary.Config.MemorySizeMB
954+
c.NumCPU = v.Summary.Config.NumCpu
953955

954956
cons = append(cons, c)
955957
}

tests/test-cases/Group1-Docker-Commands/1-23-Docker-Inspect.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ This test requires that a vSphere server is running and available
3434
21. Issue docker inspect busybox -f '{{.RepoDigest}}'
3535
22. Issue docker inspect on container with both an anonymous and named volume bound to mount points
3636
23. Issue docker inspect container status across container lifecycle (created, running, exited)
37+
24. Issue docker run with specified hostname and inspect hostname included in config
38+
25. Issue docker inspect -f {{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}} <containerID>
39+
26. Issue docker create with specififed DNS and inspect DNS in the result
40+
27. Issue docker create with multiple specififed DNS and inspect all DNS entries in the result
41+
28. Issue docker inspect and get memory and cpu numbers included in hostconfig
3742

3843
# Expected Outcome:
3944
* Step 3,4,7,8 should result in success and a properly formatted JSON response
@@ -56,6 +61,11 @@ Error: No such image or container: fake
5661
* Step 21 should result in a valid digest, previously cached
5762
* Step 22 should result in valid Mounts data
5863
* Step 23 should result in correct container status values (created, running, exited)
64+
* Step 24 should result in hostname in config
65+
* Step 25 should result macaddress in the result
66+
* Step 26 should result DNS
67+
* Step 27 should result multiple DNS entries
68+
* Step 28 should result memory and cpu numbers in hostconfig
5969

6070
# Possible Problems:
6171
None

tests/test-cases/Group1-Docker-Commands/1-23-Docker-Inspect.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,14 @@ Docker inspect container with multiple specified DNS
196196
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${container}
197197
Should Be Equal As Integers ${rc} 0
198198

199+
Docker inspect for cpu and memory settings
200+
${rc} ${container}= Run And Return Rc And Output docker %{VCH-PARAMS} create ${busybox}
201+
Should Be Equal As Integers ${rc} 0
202+
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${container}
203+
Should Be Equal As Integers ${rc} 0
204+
${output}= Evaluate json.loads(r'''${output}''') json
205+
${hostconfig}= Get From Dictionary ${output[0]} HostConfig
206+
${mem}= Get From Dictionary ${hostconfig} Memory
207+
Should Be Equal As Integers ${mem} 2048
208+
${cpu}= Get From Dictionary ${hostconfig} CpusetCpus
209+
Should Be Equal As Integers ${cpu} 2

0 commit comments

Comments
 (0)