Skip to content

Commit

Permalink
lxd-migrate: Support using the local server
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
(cherry picked from commit 09e4119da1ca24d2c08a0bd9597a7e6a16803a74)
Signed-off-by: Din Music <din.music@canonical.com>
License: Apache-2.0
  • Loading branch information
stgraber authored and MusicDin committed Jun 13, 2024
1 parent 4462711 commit 50c5df2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lxd-migrate/main_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ func (c *cmdMigrateData) render() string {
}

func (c *cmdMigrate) askServer() (lxd.InstanceServer, string, error) {
// Detect local server.
local, err := c.connectLocal()
if err == nil {
useLocal, err := c.global.asker.AskBool("The local LXD server is the target [default=yes]: ", "yes")
if err != nil {
return nil, "", err
}

if useLocal {
return local, "", nil
}
}

// Server address
serverURL, err := c.global.asker.AskString("Please provide LXD server URL: ", "", nil)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions lxd-migrate/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ func transferRootfs(ctx context.Context, dst lxd.InstanceServer, op lxd.Operatio
return nil
}

func (c *cmdMigrate) connectLocal() (lxd.InstanceServer, error) {
args := lxd.ConnectionArgs{}
args.UserAgent = fmt.Sprintf("LXD-MIGRATE %s", version.Version)

return lxd.ConnectLXDUnix("", &args)
}

func (c *cmdMigrate) connectTarget(url string, certPath string, keyPath string, authType string, token string) (lxd.InstanceServer, string, error) {
args := lxd.ConnectionArgs{
AuthType: authType,
Expand Down

0 comments on commit 50c5df2

Please sign in to comment.