Add alias and namespace information to /spec endpoint
This commit is contained in:
parent
7a6f5ddaaf
commit
53d25cc90e
@ -368,8 +368,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
specV2 := convertSpec(spec)
|
||||
return writeResult(specV2, w)
|
||||
return writeResult(spec, w)
|
||||
case storageApi:
|
||||
var err error
|
||||
fi := []v2.FsInfo{}
|
||||
@ -393,26 +392,6 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
||||
}
|
||||
}
|
||||
|
||||
// Convert container spec from v1 to v2.
|
||||
func convertSpec(specV1 info.ContainerSpec) v2.ContainerSpec {
|
||||
specV2 := v2.ContainerSpec{
|
||||
CreationTime: specV1.CreationTime,
|
||||
HasCpu: specV1.HasCpu,
|
||||
HasMemory: specV1.HasMemory,
|
||||
}
|
||||
if specV1.HasCpu {
|
||||
specV2.Cpu.Limit = specV1.Cpu.Limit
|
||||
specV2.Cpu.MaxLimit = specV1.Cpu.MaxLimit
|
||||
specV2.Cpu.Mask = specV1.Cpu.Mask
|
||||
}
|
||||
if specV1.HasMemory {
|
||||
specV2.Memory.Limit = specV1.Memory.Limit
|
||||
specV2.Memory.Reservation = specV1.Memory.Reservation
|
||||
specV2.Memory.SwapLimit = specV1.Memory.SwapLimit
|
||||
}
|
||||
return specV2
|
||||
}
|
||||
|
||||
func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
|
||||
stats := []v2.ContainerStats{}
|
||||
for _, val := range cont.Stats {
|
||||
|
@ -51,6 +51,14 @@ type ContainerSpec struct {
|
||||
// Time at which the container was created.
|
||||
CreationTime time.Time `json:"creation_time,omitempty"`
|
||||
|
||||
// Other names by which the container is known within a certain namespace.
|
||||
// This is unique within that namespace.
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
|
||||
// Namespace under which the aliases of a container are unique.
|
||||
// An example of a namespace is "docker" for Docker containers.
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
|
||||
HasCpu bool `json:"has_cpu"`
|
||||
Cpu CpuSpec `json:"cpu,omitempty"`
|
||||
|
||||
|
@ -64,7 +64,7 @@ type Manager interface {
|
||||
DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error)
|
||||
|
||||
// Gets spec for a container.
|
||||
GetContainerSpec(containerName string) (info.ContainerSpec, error)
|
||||
GetContainerSpec(containerName string) (v2.ContainerSpec, error)
|
||||
|
||||
// Get derived stats for a container.
|
||||
GetContainerDerivedStats(containerName string) (v2.DerivedStats, error)
|
||||
@ -290,16 +290,40 @@ func (self *manager) getContainerData(containerName string) (*containerData, err
|
||||
return cont, nil
|
||||
}
|
||||
|
||||
func (self *manager) GetContainerSpec(containerName string) (info.ContainerSpec, error) {
|
||||
func (self *manager) GetContainerSpec(containerName string) (v2.ContainerSpec, error) {
|
||||
cont, err := self.getContainerData(containerName)
|
||||
if err != nil {
|
||||
return info.ContainerSpec{}, err
|
||||
return v2.ContainerSpec{}, err
|
||||
}
|
||||
cinfo, err := cont.GetInfo()
|
||||
if err != nil {
|
||||
return info.ContainerSpec{}, err
|
||||
return v2.ContainerSpec{}, err
|
||||
}
|
||||
return self.getAdjustedSpec(cinfo), nil
|
||||
spec := self.getV2Spec(cinfo)
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
// Get V2 container spec from v1 container info.
|
||||
func (self *manager) getV2Spec(cinfo *containerInfo) v2.ContainerSpec {
|
||||
specV1 := self.getAdjustedSpec(cinfo)
|
||||
specV2 := v2.ContainerSpec{
|
||||
CreationTime: specV1.CreationTime,
|
||||
HasCpu: specV1.HasCpu,
|
||||
HasMemory: specV1.HasMemory,
|
||||
}
|
||||
if specV1.HasCpu {
|
||||
specV2.Cpu.Limit = specV1.Cpu.Limit
|
||||
specV2.Cpu.MaxLimit = specV1.Cpu.MaxLimit
|
||||
specV2.Cpu.Mask = specV1.Cpu.Mask
|
||||
}
|
||||
if specV1.HasMemory {
|
||||
specV2.Memory.Limit = specV1.Memory.Limit
|
||||
specV2.Memory.Reservation = specV1.Memory.Reservation
|
||||
specV2.Memory.SwapLimit = specV1.Memory.SwapLimit
|
||||
}
|
||||
specV2.Aliases = cinfo.Aliases
|
||||
specV2.Namespace = cinfo.Namespace
|
||||
return specV2
|
||||
}
|
||||
|
||||
func (self *manager) getAdjustedSpec(cinfo *containerInfo) info.ContainerSpec {
|
||||
|
Loading…
Reference in New Issue
Block a user