The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4578
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) === Fixes #4576 Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From e5e7a2a31ff20842a104edf2d83927a2ab629705 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Wed, 23 May 2018 11:59:42 +0200 Subject: [PATCH] lxd-p2c: Handle target URL smarter Fixes #4576 Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd-p2c/main_migrate.go | 7 ++++++- lxd-p2c/utils.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lxd-p2c/main_migrate.go b/lxd-p2c/main_migrate.go index 39134e3f7..69555d701 100644 --- a/lxd-p2c/main_migrate.go +++ b/lxd-p2c/main_migrate.go @@ -109,8 +109,13 @@ func (c *cmdMigrate) Run(cmd *cobra.Command, args []string) error { return fmt.Errorf("Failed to setup the source: %v", err) } + URL, err := parseURL(args[0]) + if err != nil { + return err + } + // Connect to the target - dst, err := connectTarget(args[0]) + dst, err := connectTarget(URL) if err != nil { return err } diff --git a/lxd-p2c/utils.go b/lxd-p2c/utils.go index 6a30bf36e..5268508ab 100644 --- a/lxd-p2c/utils.go +++ b/lxd-p2c/utils.go @@ -4,6 +4,7 @@ import ( "crypto/x509" "encoding/pem" "fmt" + "net/url" "strings" "syscall" @@ -180,3 +181,25 @@ func setupSource(path string, mounts []string) error { return nil } + +func parseURL(URL string) (string, error) { + u, err := url.Parse(URL) + if err != nil { + return "", err + } + + // Create a URL with scheme and hostname since it wasn't provided + if u.Scheme == "" && u.Host == "" && u.Path != "" { + u, err = url.Parse(fmt.Sprintf("https://%s", u.Path)) + if err != nil { + return "", err + } + } + + // If no port was provided, use port 8443 + if u.Port() == "" { + u.Host = fmt.Sprintf("%s:8443", u.Hostname()) + } + + return u.String(), nil +}
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel