Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxd-to-incus: Add support for manually built LXD #169

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/lxd-to-incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func (c *cmdMigrate) Run(app *cobra.Command, args []string) error {
return fmt.Errorf("No source server could be found")
}

fmt.Printf("==> Detected: %s\n", source.Name())

// Iterate through potential targets.
fmt.Println("=> Looking for target server")
var target Target
Expand Down
2 changes: 2 additions & 0 deletions cmd/lxd-to-incus/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ type Source interface {
Purge() error
Connect() (lxd.InstanceServer, error)
Paths() (*DaemonPaths, error)
Name() string
}

var sources = []Source{
&srcSnap{},
&srcDeb{},
&srcManual{},
}
4 changes: 4 additions & 0 deletions cmd/lxd-to-incus/sources_deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (s *srcDeb) Present() bool {
return true
}

func (s *srcDeb) Name() string {
return ".deb package"
}

func (s *srcDeb) Stop() error {
_, err := subprocess.RunCommand("systemctl", "stop", "lxd-containers.service", "lxd.service", "lxd.socket")
return err
Expand Down
66 changes: 66 additions & 0 deletions cmd/lxd-to-incus/sources_manual.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"net/http"
"time"

"github.com/canonical/lxd/client"

"github.com/lxc/incus/shared/util"
)

type srcManual struct{}

func (s *srcManual) Present() bool {
if !util.PathExists("/var/lib/lxd") {
return false
}

return true
}

func (s *srcManual) Name() string {
return "manual installation"
}

func (s *srcManual) Stop() error {
d, err := s.Connect()
if err != nil {
return err
}

httpClient, err := d.GetHTTPClient()
if err != nil {
return err
}

// Request shutdown, this shouldn't return until daemon has stopped so use a large request timeout.
httpTransport := httpClient.Transport.(*http.Transport)
httpTransport.ResponseHeaderTimeout = 3600 * time.Second
_, _, err = d.RawQuery("PUT", "/internal/shutdown", nil, "")
if err != nil {
return err
}

return nil
}

func (s *srcManual) Start() error {
return nil
}

func (s *srcManual) Purge() error {
return nil
}

func (s *srcManual) Connect() (lxd.InstanceServer, error) {
return lxd.ConnectLXDUnix("/var/lib/lxd/unix.socket", nil)
}

func (s *srcManual) Paths() (*DaemonPaths, error) {
return &DaemonPaths{
Daemon: "/var/lib/lxd/",
Logs: "/var/log/lxd/",
Cache: "/var/cache/lxd/",
}, nil
}
4 changes: 4 additions & 0 deletions cmd/lxd-to-incus/sources_snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (s *srcSnap) Present() bool {
return true
}

func (s *srcSnap) Name() string {
return "snap package"
}

func (s *srcSnap) Stop() error {
_, err := subprocess.RunCommand("snap", "stop", "lxd")
return err
Expand Down
Loading