Skip to content

Commit

Permalink
Merge pull request #252 from stgraber/migrate
Browse files Browse the repository at this point in the history
Add support for migrating from LXD COPR
  • Loading branch information
tych0 committed Nov 29, 2023
2 parents abb77db + 12451b2 commit f700f9f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/lxd-to-incus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ Instead this tool will be providing specific commands for each of the servers.
for _, dir := range []string{"devices", "devlxd", "security", "shmounts"} {
_, _ = logFile.WriteString(fmt.Sprintf("Cleaning up path %q\n", filepath.Join(targetPaths.Daemon, dir)))

_ = unix.Unmount(filepath.Join(targetPaths.Daemon, dir), unix.MNT_DETACH)
err = os.RemoveAll(filepath.Join(targetPaths.Daemon, dir))
if err != nil && !os.IsNotExist(err) {
_, _ = logFile.WriteString(fmt.Sprintf("ERROR: %v\n", err))
Expand Down
1 change: 1 addition & 0 deletions cmd/lxd-to-incus/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ type Source interface {
var sources = []Source{
&srcSnap{},
&srcDeb{},
&srcCOPR{},
&srcManual{},
}
55 changes: 55 additions & 0 deletions cmd/lxd-to-incus/sources_copr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"github.com/canonical/lxd/client"

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

type srcCOPR struct{}

func (s *srcCOPR) Present() bool {
// Validate that the RPM package is installed.
_, err := subprocess.RunCommand("rpm", "-q", "lxd")
if err != nil {
return false
}

if !util.PathExists("/run/lxd.socket") {
return false
}

return true
}

func (s *srcCOPR) Name() string {
return "COPR package"
}

func (s *srcCOPR) Stop() error {
_, err := subprocess.RunCommand("systemctl", "stop", "lxd-containers.service", "lxd.service", "lxd.socket")
return err
}

func (s *srcCOPR) Start() error {
_, err := subprocess.RunCommand("systemctl", "start", "lxd.socket", "lxd-containers.service")
return err
}

func (s *srcCOPR) Purge() error {
_, err := subprocess.RunCommand("dnf", "remove", "-y", "lxd")
return err
}

func (s *srcCOPR) Connect() (lxd.InstanceServer, error) {
return lxd.ConnectLXDUnix("/run/lxd.socket", nil)
}

func (s *srcCOPR) Paths() (*DaemonPaths, error) {
return &DaemonPaths{
Daemon: "/var/lib/lxd/",
Logs: "/var/log/lxd/",
Cache: "/var/cache/lxd/",
}, nil
}

0 comments on commit f700f9f

Please sign in to comment.