changed actual handlers

This commit is contained in:
Nan Deng 2014-06-12 15:03:18 -07:00
parent 5a8bceb43e
commit 89b5484734
2 changed files with 15 additions and 9 deletions

View File

@ -285,12 +285,12 @@ func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err
return return
} }
func (self *dockerContainerHandler) ListContainers(listType container.ListType) ([]string, error) { func (self *dockerContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerRef, error) {
if self.isDockerContainer() { if self.isDockerContainer() {
return nil, nil return nil, nil
} }
if self.isRootContainer() && listType == container.LIST_SELF { if self.isRootContainer() && listType == container.LIST_SELF {
return []string{"/docker"}, nil return []info.ContainerRef{info.ContainerRef{Name: "/docker"}}, nil
} }
opt := docker.ListContainersOptions{ opt := docker.ListContainersOptions{
All: true, All: true,
@ -299,16 +299,21 @@ func (self *dockerContainerHandler) ListContainers(listType container.ListType)
if err != nil { if err != nil {
return nil, err return nil, err
} }
ret := make([]string, 0, len(containers)+1) ret := make([]info.ContainerRef, 0, len(containers)+1)
for _, c := range containers { for _, c := range containers {
if !strings.HasPrefix(c.Status, "Up ") { if !strings.HasPrefix(c.Status, "Up ") {
continue continue
} }
path := fmt.Sprintf("/docker/%v", c.ID) path := fmt.Sprintf("/docker/%v", c.ID)
ret = append(ret, path) aliases := c.Names
ref := info.ContainerRef{
Name: path,
Aliases: aliases,
}
ret = append(ret, ref)
} }
if self.isRootContainer() { if self.isRootContainer() {
ret = append(ret, "/docker") ret = append(ret, info.ContainerRef{Name: "/docker"})
} }
return ret, nil return ret, nil
} }

View File

@ -157,7 +157,7 @@ func (c *lmctfyContainerHandler) GetStats() (*info.ContainerStats, error) {
} }
// Gets all subcontainers. // Gets all subcontainers.
func (c *lmctfyContainerHandler) ListContainers(listType container.ListType) ([]string, error) { func (c *lmctfyContainerHandler) ListContainers(listType container.ListType) ([]info.ContainerRef, error) {
// Prepare the arguments. // Prepare the arguments.
args := []string{"list", "containers", "-v"} args := []string{"list", "containers", "-v"}
if listType == container.LIST_RECURSIVE { if listType == container.LIST_RECURSIVE {
@ -174,13 +174,14 @@ func (c *lmctfyContainerHandler) ListContainers(listType container.ListType) ([]
// Parse lines as container names. // Parse lines as container names.
if len(data) == 0 { if len(data) == 0 {
return []string{}, nil return nil, nil
} }
names := strings.Split(string(data), "\n") names := strings.Split(string(data), "\n")
containerNames := make([]string, 0, len(names)) containerNames := make([]info.ContainerRef, 0, len(names))
for _, name := range names { for _, name := range names {
if len(name) != 0 { if len(name) != 0 {
containerNames = append(containerNames, name) ref := info.ContainerRef{Name: name}
containerNames = append(containerNames, ref)
} }
} }
return containerNames, nil return containerNames, nil