2014-10-04 22:47:54 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerRename(job *engine.Job) engine.Status {
|
|
|
|
if len(job.Args) != 2 {
|
|
|
|
return job.Errorf("usage: %s OLD_NAME NEW_NAME", job.Name)
|
|
|
|
}
|
2015-01-13 20:30:49 -05:00
|
|
|
oldName := job.Args[0]
|
|
|
|
newName := job.Args[1]
|
2014-10-04 22:47:54 -04:00
|
|
|
|
2015-01-13 20:30:49 -05:00
|
|
|
container := daemon.Get(oldName)
|
2014-10-04 22:47:54 -04:00
|
|
|
if container == nil {
|
2015-01-13 20:30:49 -05:00
|
|
|
return job.Errorf("No such container: %s", oldName)
|
2014-10-04 22:47:54 -04:00
|
|
|
}
|
|
|
|
|
2015-01-13 20:30:49 -05:00
|
|
|
oldName = container.Name
|
|
|
|
|
2014-10-04 22:47:54 -04:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2015-01-13 20:30:49 -05:00
|
|
|
if _, err := daemon.reserveName(container.ID, newName); err != nil {
|
2014-10-04 22:47:54 -04:00
|
|
|
return job.Errorf("Error when allocating new name: %s", err)
|
|
|
|
}
|
2015-01-13 20:30:49 -05:00
|
|
|
|
|
|
|
container.Name = newName
|
|
|
|
|
|
|
|
if err := daemon.containerGraph.Delete(oldName); err != nil {
|
|
|
|
return job.Errorf("Failed to delete container %q: %v", oldName, err)
|
|
|
|
}
|
2014-10-04 22:47:54 -04:00
|
|
|
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|