Add alias and namespace information to /spec endpoint

This commit is contained in:
Rohit Jnagal 2015-03-13 21:00:38 +00:00
parent 7a6f5ddaaf
commit 53d25cc90e
3 changed files with 38 additions and 27 deletions

View File

@ -368,8 +368,7 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
if err != nil { if err != nil {
return err return err
} }
specV2 := convertSpec(spec) return writeResult(spec, w)
return writeResult(specV2, w)
case storageApi: case storageApi:
var err error var err error
fi := []v2.FsInfo{} 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 { func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
stats := []v2.ContainerStats{} stats := []v2.ContainerStats{}
for _, val := range cont.Stats { for _, val := range cont.Stats {

View File

@ -51,6 +51,14 @@ type ContainerSpec struct {
// Time at which the container was created. // Time at which the container was created.
CreationTime time.Time `json:"creation_time,omitempty"` 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"` HasCpu bool `json:"has_cpu"`
Cpu CpuSpec `json:"cpu,omitempty"` Cpu CpuSpec `json:"cpu,omitempty"`

View File

@ -64,7 +64,7 @@ type Manager interface {
DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error) DockerContainer(dockerName string, query *info.ContainerInfoRequest) (info.ContainerInfo, error)
// Gets spec for a container. // Gets spec for a container.
GetContainerSpec(containerName string) (info.ContainerSpec, error) GetContainerSpec(containerName string) (v2.ContainerSpec, error)
// Get derived stats for a container. // Get derived stats for a container.
GetContainerDerivedStats(containerName string) (v2.DerivedStats, error) GetContainerDerivedStats(containerName string) (v2.DerivedStats, error)
@ -290,16 +290,40 @@ func (self *manager) getContainerData(containerName string) (*containerData, err
return cont, nil 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) cont, err := self.getContainerData(containerName)
if err != nil { if err != nil {
return info.ContainerSpec{}, err return v2.ContainerSpec{}, err
} }
cinfo, err := cont.GetInfo() cinfo, err := cont.GetInfo()
if err != nil { 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 { func (self *manager) getAdjustedSpec(cinfo *containerInfo) info.ContainerSpec {