1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 06:40:31 +00:00

Handle system containers with no hash

This commit is contained in:
Darren Shepherd
2015-03-06 21:21:42 -07:00
parent c837a2ae59
commit f7b5b4f83b

View File

@@ -4,7 +4,6 @@ import (
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"sort" "sort"
@@ -287,27 +286,27 @@ func (c *Container) renameOld(client *dockerClient.Client, opts *dockerClient.Cr
return nil return nil
} }
var newName string
if label, ok := existing.Config.Labels[HASH]; ok { if label, ok := existing.Config.Labels[HASH]; ok {
newName := fmt.Sprintf("%s-%s", existing.Name, label) newName = fmt.Sprintf("%s-%s", existing.Name, label)
} else {
newName = fmt.Sprintf("%s-unknown-%s", existing.Name, util.RandSeq(12))
}
if existing.State.Running { if existing.State.Running {
err := client.StopContainer(existing.ID, 2) err := client.StopContainer(existing.ID, 2)
if err != nil { if err != nil {
return err return err
}
_, err = client.WaitContainer(existing.ID)
if err != nil {
return err
}
} }
log.Debugf("Renaming %s to %s", existing.Name, newName) _, err = client.WaitContainer(existing.ID)
return client.RenameContainer(existing.ID, newName) if err != nil {
} else { return err
//TODO: do something with containers with no hash }
return errors.New("Existing container doesn't have a hash")
} }
log.Debugf("Renaming %s to %s", existing.Name, newName)
return client.RenameContainer(existing.ID, newName)
} }
func (c *Container) getCreateOpts(client *dockerClient.Client) (*dockerClient.CreateContainerOptions, error) { func (c *Container) getCreateOpts(client *dockerClient.Client) (*dockerClient.CreateContainerOptions, error) {