Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
node: Use cluster.Containers instead of duplicating code
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Luzzardi <[email protected]>
  • Loading branch information
aluzzardi committed Oct 6, 2015
1 parent 581704d commit e234503
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions scheduler/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package node

import (
"errors"
"strings"

"github.com/docker/swarm/cluster"
)
Expand All @@ -14,7 +13,7 @@ type Node struct {
Addr string
Name string
Labels map[string]string
Containers []*cluster.Container
Containers cluster.Containers
Images []*cluster.Image

UsedMemory int64
Expand Down Expand Up @@ -45,26 +44,7 @@ func NewNode(e *cluster.Engine) *Node {

// Container returns the container with IDOrName in the engine.
func (n *Node) Container(IDOrName string) *cluster.Container {
// Abort immediately if the name is empty.
if len(IDOrName) == 0 {
return nil
}

for _, container := range n.Containers {
// Match ID prefix.
if strings.HasPrefix(container.Id, IDOrName) {
return container
}

// Match name, /name or engine/name.
for _, name := range container.Names {
if name == IDOrName || name == "/"+IDOrName || container.Engine.ID+name == IDOrName || container.Engine.Name+name == IDOrName {
return container
}
}
}

return nil
return n.Containers.Get(IDOrName)
}

// AddContainer injects a container into the internal state.
Expand Down

0 comments on commit e234503

Please sign in to comment.