The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2307
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === newer versions of petname have a smaller name list, which increases the liklehood of conflicts. let's retry a few times to avoid them. Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com>
From 59cf54df5164db543c03df9b64e5d10d505d2527 Mon Sep 17 00:00:00 2001 From: Tycho Andersen <tycho.ander...@canonical.com> Date: Tue, 23 Aug 2016 09:56:33 -0400 Subject: [PATCH] retry generating petnames newer versions of petname have a smaller name list, which increases the liklehood of conflicts. let's retry a few times to avoid them. Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com> --- lxd/containers_post.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lxd/containers_post.go b/lxd/containers_post.go index fe44fd5..10bac2f 100644 --- a/lxd/containers_post.go +++ b/lxd/containers_post.go @@ -394,7 +394,23 @@ func containersPost(d *Daemon, r *http.Request) Response { } if req.Name == "" { - req.Name = strings.ToLower(petname.Generate(2, "-")) + cs, err := dbContainersList(d.db, cTypeRegular) + if err != nil { + return InternalError(err) + } + + i := 0 + for { + i++ + req.Name = strings.ToLower(petname.Generate(2, "-")) + if !shared.StringInSlice(req.Name, cs) { + break + } + + if i > 100 { + return InternalError(fmt.Errorf("couldn't generate a new unique name after 100 tries")) + } + } shared.Debugf("No name provided, creating %s", req.Name) }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel