From 2df01661071e949faabf1fa9ba612c40710b686b Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 30 Jan 2014 12:02:56 -0800 Subject: [PATCH] Implement requesting the name ip Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- container.go | 36 ++++++++++++++++-------------------- networkdriver/lxc/driver.go | 13 +++++++++++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/container.go b/container.go index 8ceec631f0..a9bf32ac6d 100644 --- a/container.go +++ b/container.go @@ -1109,36 +1109,32 @@ func (container *Container) allocateNetwork() error { var ( env *engine.Env + err error eng = container.runtime.eng ) + if container.State.IsGhost() { if container.runtime.config.DisableNetwork { env = &engine.Env{} } else { - // TODO: @crosbymichael - panic("not implemented") - /* - iface = &NetworkInterface{ - IPNet: net.IPNet{IP: net.ParseIP(container.NetworkSettings.IPAddress), Mask: manager.bridgeNetwork.Mask}, - Gateway: manager.bridgeNetwork.IP, - } + currentIP := container.NetworkSettings.IPAddress - // request an existing ip - if iface != nil && iface.IPNet.IP != nil { - if _, err := ipallocator.RequestIP(manager.bridgeNetwork, &iface.IPNet.IP); err != nil { - return err - } - } else { - job = eng.Job("allocate_interface", container.ID) - if err := job.Run(); err != nil { - return err - } - } - */ + job := eng.Job("allocate_interface", container.ID) + if currentIP != "" { + job.Setenv("RequestIP", currentIP) + } + + env, err = job.Stdout.AddEnv() + if err != nil { + return err + } + + if err := job.Run(); err != nil { + return err + } } } else { job := eng.Job("allocate_interface", container.ID) - var err error env, err = job.Stdout.AddEnv() if err != nil { return err diff --git a/networkdriver/lxc/driver.go b/networkdriver/lxc/driver.go index deb09621ba..0401e2de9d 100644 --- a/networkdriver/lxc/driver.go +++ b/networkdriver/lxc/driver.go @@ -304,9 +304,18 @@ func createBridgeIface(name string) error { // Allocate a network interface func Allocate(job *engine.Job) engine.Status { - id := job.Args[0] + var ( + ip *net.IP + err error + id = job.Args[0] + requestedIP = net.ParseIP(job.Getenv("RequestedIP")) + ) - ip, err := ipallocator.RequestIP(bridgeNetwork, nil) + if requestedIP != nil { + ip, err = ipallocator.RequestIP(bridgeNetwork, &requestedIP) + } else { + ip, err = ipallocator.RequestIP(bridgeNetwork, nil) + } if err != nil { job.Error(err) return engine.StatusErr