1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #5759 from vieux/move_register_links_to_daemon

move RegisterLinks to daemon
This commit is contained in:
Victor Vieux 2014-05-12 18:39:47 -07:00
commit a0f799b6d4
2 changed files with 30 additions and 32 deletions

View file

@ -667,6 +667,35 @@ func (daemon *Daemon) RegisterLink(parent, child *Container, alias string) error
return nil
}
func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error {
if hostConfig != nil && hostConfig.Links != nil {
for _, l := range hostConfig.Links {
parts, err := utils.PartParser("name:alias", l)
if err != nil {
return err
}
child, err := daemon.GetByName(parts["name"])
if err != nil {
return err
}
if child == nil {
return fmt.Errorf("Could not get container for %s", parts["name"])
}
if err := daemon.RegisterLink(container, child, parts["alias"]); err != nil {
return err
}
}
// After we load all the links into the daemon
// set them to nil on the hostconfig
hostConfig.Links = nil
if err := container.WriteHostConfig(); err != nil {
return err
}
}
return nil
}
// FIXME: harmonize with NewGraph()
func NewDaemon(config *daemonconfig.Config, eng *engine.Engine) (*Daemon, error) {
daemon, err := NewDaemonFromDirectory(config, eng)

View file

@ -2029,37 +2029,6 @@ func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*imag
return match, nil
}
func (srv *Server) RegisterLinks(container *daemon.Container, hostConfig *runconfig.HostConfig) error {
daemon := srv.daemon
if hostConfig != nil && hostConfig.Links != nil {
for _, l := range hostConfig.Links {
parts, err := utils.PartParser("name:alias", l)
if err != nil {
return err
}
child, err := srv.daemon.GetByName(parts["name"])
if err != nil {
return err
}
if child == nil {
return fmt.Errorf("Could not get container for %s", parts["name"])
}
if err := daemon.RegisterLink(container, child, parts["alias"]); err != nil {
return err
}
}
// After we load all the links into the daemon
// set them to nil on the hostconfig
hostConfig.Links = nil
if err := container.WriteHostConfig(); err != nil {
return err
}
}
return nil
}
func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
if len(job.Args) < 1 {
return job.Errorf("Usage: %s container_id", job.Name)
@ -2100,7 +2069,7 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
}
}
// Register any links from the host config before starting the container
if err := srv.RegisterLinks(container, hostConfig); err != nil {
if err := srv.daemon.RegisterLinks(container, hostConfig); err != nil {
return job.Error(err)
}
container.SetHostConfig(hostConfig)