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

Fix reference name of lxd shared #9

Merged
merged 6 commits into from
Feb 15, 2024
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
8 changes: 4 additions & 4 deletions generators/cloud-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"

"github.com/canonical/lxd-imagebuilder/image"
Expand All @@ -23,13 +23,13 @@ func (g *cloudInit) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLX
// Remove all symlinks to /etc/init.d/cloud-{init-local,config,init,final} in /etc/runlevels/*
fullPath := filepath.Join(g.sourceDir, "etc", "runlevels")

if lxd_shared.PathExists(fullPath) {
if lxdShared.PathExists(fullPath) {
err := filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}

if lxd_shared.ValueInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
if lxdShared.ValueInSlice(info.Name(), []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"}) {
err := os.Remove(path)
if err != nil {
return fmt.Errorf("Failed to remove file %q: %w", path, err)
Expand All @@ -46,7 +46,7 @@ func (g *cloudInit) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLX
// With systemd:
path := filepath.Join(g.sourceDir, "/etc/cloud")

if !lxd_shared.PathExists(path) {
if !lxdShared.PathExists(path) {
err := os.MkdirAll(path, 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", path, err)
Expand Down
6 changes: 3 additions & 3 deletions generators/cloud-init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"testing"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/stretchr/testify/require"

"github.com/canonical/lxd-imagebuilder/image"
Expand Down Expand Up @@ -47,15 +47,15 @@ func TestCloudInitGeneratorRunLXC(t *testing.T) {
// Check whether the generator has altered the rootfs
for _, f := range []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"} {
fullPath := filepath.Join(rootfsDir, "etc", "runlevels", f)
require.Falsef(t, lxd_shared.PathExists(fullPath), "File '%s' exists but shouldn't", fullPath)
require.Falsef(t, lxdShared.PathExists(fullPath), "File '%s' exists but shouldn't", fullPath)
}

for i := 0; i <= 6; i++ {
dir := filepath.Join(rootfsDir, "etc", "rc.d", fmt.Sprintf("rc%d.d", i))

for _, f := range []string{"cloud-init-local", "cloud-config", "cloud-init", "cloud-final"} {
fullPath := filepath.Join(dir, fmt.Sprintf("S99%s", f))
require.Falsef(t, lxd_shared.PathExists(fullPath), "File '%s' exists but shouldn't", fullPath)
require.Falsef(t, lxdShared.PathExists(fullPath), "File '%s' exists but shouldn't", fullPath)
}
}

Expand Down
4 changes: 2 additions & 2 deletions generators/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"

"github.com/canonical/lxd-imagebuilder/image"
"github.com/canonical/lxd-imagebuilder/shared"
Expand Down Expand Up @@ -186,7 +186,7 @@ func (g *copy) copyFile(src, dest string, defFile shared.DefinitionFile) error {
return err
}

if lxd_shared.PathExists(dest) {
if lxdShared.PathExists(dest) {
err = os.Remove(dest)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions generators/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"

"github.com/canonical/lxd-imagebuilder/image"
Expand All @@ -19,7 +19,7 @@ type hostname struct {
// RunLXC creates a hostname template.
func (g *hostname) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLXC) error {
// Skip if the file doesn't exist
if !lxd_shared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
if !lxdShared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
return nil
}

Expand Down Expand Up @@ -49,7 +49,7 @@ func (g *hostname) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLXC
// RunLXD creates a hostname template.
func (g *hostname) RunLXD(img *image.LXDImage, target shared.DefinitionTargetLXD) error {
// Skip if the file doesn't exist
if !lxd_shared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
if !lxdShared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions generators/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"

"github.com/canonical/lxd-imagebuilder/image"
Expand All @@ -20,7 +20,7 @@ type hosts struct {
// RunLXC creates a LXC specific entry in the hosts file.
func (g *hosts) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLXC) error {
// Skip if the file doesn't exist
if !lxd_shared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
if !lxdShared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
return nil
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func (g *hosts) RunLXC(img *image.LXCImage, target shared.DefinitionTargetLXC) e
// RunLXD creates a hosts template.
func (g *hosts) RunLXD(img *image.LXDImage, target shared.DefinitionTargetLXD) error {
// Skip if the file doesn't exist
if !lxd_shared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
if !lxdShared.PathExists(filepath.Join(g.sourceDir, g.defFile.Path)) {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions generators/lxd-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"

"github.com/canonical/lxd-imagebuilder/image"
"github.com/canonical/lxd-imagebuilder/shared"
Expand Down Expand Up @@ -123,7 +123,7 @@ func (g *lxdAgent) Run() error {

func (g *lxdAgent) handleSystemd() error {
systemdPath := filepath.Join("/", "lib", "systemd")
if !lxd_shared.PathExists(filepath.Join(g.sourceDir, systemdPath)) {
if !lxdShared.PathExists(filepath.Join(g.sourceDir, systemdPath)) {
systemdPath = filepath.Join("/", "usr", "lib", "systemd")
}

Expand Down Expand Up @@ -160,7 +160,7 @@ StartLimitBurst=10

udevPath := filepath.Join("/", "lib", "udev", "rules.d")
stat, err := os.Lstat(filepath.Join(g.sourceDir, "lib", "udev"))
if err == nil && stat.Mode()&os.ModeSymlink != 0 || !lxd_shared.PathExists(filepath.Dir(filepath.Join(g.sourceDir, udevPath))) {
if err == nil && stat.Mode()&os.ModeSymlink != 0 || !lxdShared.PathExists(filepath.Dir(filepath.Join(g.sourceDir, udevPath))) {
udevPath = filepath.Join("/", "usr", "lib", "udev", "rules.d")
}

Expand Down
6 changes: 3 additions & 3 deletions image/lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"

"github.com/canonical/lxd-imagebuilder/shared"
)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (l *LXCImage) createMetadata() error {

var excludesUser string

if lxd_shared.PathExists(filepath.Join(l.sourceDir, "dev")) {
if lxdShared.PathExists(filepath.Join(l.sourceDir, "dev")) {
err := filepath.Walk(filepath.Join(l.sourceDir, "dev"),
func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down Expand Up @@ -192,7 +192,7 @@ func (l *LXCImage) packMetadata() error {
files = append(files, filepath.Base(c))
}

if lxd_shared.PathExists(filepath.Join(l.cacheDir, "metadata", "templates")) {
if lxdShared.PathExists(filepath.Join(l.cacheDir, "metadata", "templates")) {
files = append(files, "templates")
}

Expand Down
4 changes: 2 additions & 2 deletions lxd-imagebuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import (
"strings"
"time"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -618,7 +618,7 @@ func getDefinition(fname string, options []string) (*shared.Definition, error) {
// addSystemdGenerator creates a systemd-generator which runs on boot, and does some configuration around the system itself and networking.
func addSystemdGenerator() error {
// Check if container has systemd
if !lxd_shared.PathExists("/etc/systemd") {
if !lxdShared.PathExists("/etc/systemd") {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions lxd-imagebuilder/main_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"

client "github.com/canonical/lxd/client"
lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,7 +44,7 @@ func (c *cmdLXD) commandBuild() *cobra.Command {
`, typeDescription, compressionDescription),
Args: cobra.RangeArgs(1, 2),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !lxd_shared.ValueInSlice(c.flagType, []string{"split", "unified"}) {
if !lxdShared.ValueInSlice(c.flagType, []string{"split", "unified"}) {
return errors.New("--type needs to be one of ['split', 'unified']")
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *cmdLXD) commandPack() *cobra.Command {
`, typeDescription, compressionDescription),
Args: cobra.RangeArgs(2, 3),
PreRunE: func(cmd *cobra.Command, args []string) error {
if !lxd_shared.ValueInSlice(c.flagType, []string{"split", "unified"}) {
if !lxdShared.ValueInSlice(c.flagType, []string{"split", "unified"}) {
return errors.New("--type needs to be one of ['split', 'unified']")
}

Expand Down
18 changes: 9 additions & 9 deletions lxd-imagebuilder/main_repack-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strconv"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"github.com/flosch/pongo2/v4"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {
} else {
supportedVersions := []string{"w11", "w10", "2k19", "2k12", "2k16", "2k22"}

if !lxd_shared.ValueInSlice(c.flagWindowsVersion, supportedVersions) {
if !lxdShared.ValueInSlice(c.flagWindowsVersion, supportedVersions) {
return fmt.Errorf("Version must be one of %v", supportedVersions)
}
}
Expand All @@ -126,7 +126,7 @@ func (c *cmdRepackWindows) preRun(cmd *cobra.Command, args []string) error {
} else {
supportedArchitectures := []string{"amd64", "ARM64"}

if !lxd_shared.ValueInSlice(c.flagWindowsArchitecture, supportedArchitectures) {
if !lxdShared.ValueInSlice(c.flagWindowsArchitecture, supportedArchitectures) {
return fmt.Errorf("Architecture must be one of %v", supportedArchitectures)
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (c *cmdRepackWindows) run(cmd *cobra.Command, args []string, overlayDir str

virtioISOPath = filepath.Join(c.global.flagSourcesDir, "windows", "virtio-win.iso")

if !lxd_shared.PathExists(virtioISOPath) {
if !lxdShared.PathExists(virtioISOPath) {
err := os.MkdirAll(filepath.Dir(virtioISOPath), 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", filepath.Dir(virtioISOPath), err)
Expand All @@ -208,7 +208,7 @@ func (c *cmdRepackWindows) run(cmd *cobra.Command, args []string, overlayDir str

logger.Info("Downloading drivers ISO")

_, err = lxd_shared.DownloadFileHash(c.global.ctx, &client, "", nil, nil, "virtio-win.iso", virtioURL, "", nil, f)
_, err = lxdShared.DownloadFileHash(c.global.ctx, &client, "", nil, nil, "virtio-win.iso", virtioURL, "", nil, f)
if err != nil {
f.Close()
os.Remove(virtioISOPath)
Expand All @@ -219,7 +219,7 @@ func (c *cmdRepackWindows) run(cmd *cobra.Command, args []string, overlayDir str
}
}

if !lxd_shared.PathExists(driverPath) {
if !lxdShared.PathExists(driverPath) {
err := os.MkdirAll(driverPath, 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", driverPath, err)
Expand Down Expand Up @@ -354,7 +354,7 @@ func (c *cmdRepackWindows) modifyWim(path string, index int) error {
wimFile := filepath.Join(path)
wimPath := filepath.Join(c.global.flagCacheDir, "wim")

if !lxd_shared.PathExists(wimPath) {
if !lxdShared.PathExists(wimPath) {
err := os.MkdirAll(wimPath, 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", wimPath, err)
Expand Down Expand Up @@ -542,7 +542,7 @@ func (c *cmdRepackWindows) injectDrivers(dirs map[string]string) error {
sourceDir := filepath.Join(driverPath, driver, c.flagWindowsVersion, c.flagWindowsArchitecture)
targetBasePath := filepath.Join(dirs["filerepository"], info.PackageName)

if !lxd_shared.PathExists(targetBasePath) {
if !lxdShared.PathExists(targetBasePath) {
err := os.MkdirAll(targetBasePath, 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", targetBasePath, err)
Expand All @@ -554,7 +554,7 @@ func (c *cmdRepackWindows) injectDrivers(dirs map[string]string) error {
targetPath := filepath.Join(targetBasePath, filepath.Base(path))

// Copy driver files
if lxd_shared.ValueInSlice(ext, []string{".cat", ".dll", ".inf", ".sys"}) {
if lxdShared.ValueInSlice(ext, []string{".cat", ".dll", ".inf", ".sys"}) {
logger.WithFields(logrus.Fields{"src": path, "dest": targetPath}).Debug("Copying file")

err := shared.Copy(path, targetPath)
Expand Down
14 changes: 7 additions & 7 deletions lxd-imagebuilder/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"
"golang.org/x/sys/unix"

"github.com/canonical/lxd-imagebuilder/shared"
Expand All @@ -29,7 +29,7 @@ func newVM(ctx context.Context, imageFile, rootfsDir, fs string, size uint64) (*
fs = "ext4"
}

if !lxd_shared.ValueInSlice(fs, []string{"btrfs", "ext4"}) {
if !lxdShared.ValueInSlice(fs, []string{"btrfs", "ext4"}) {
return nil, fmt.Errorf("Unsupported fs: %s", fs)
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func (v *vm) mountImage() error {

deviceNumbers := strings.Split(out.String(), "\n")

if !lxd_shared.PathExists(v.getUEFIDevFile()) {
if !lxdShared.PathExists(v.getUEFIDevFile()) {
fields := strings.Split(deviceNumbers[1], ":")

major, err := strconv.Atoi(fields[0])
Expand All @@ -145,7 +145,7 @@ func (v *vm) mountImage() error {
}
}

if !lxd_shared.PathExists(v.getRootfsDevFile()) {
if !lxdShared.PathExists(v.getRootfsDevFile()) {
fields := strings.Split(deviceNumbers[2], ":")

major, err := strconv.Atoi(fields[0])
Expand All @@ -171,7 +171,7 @@ func (v *vm) mountImage() error {

func (v *vm) umountImage() error {
// If loopDevice is empty, the image probably isn't mounted.
if v.loopDevice == "" || !lxd_shared.PathExists(v.loopDevice) {
if v.loopDevice == "" || !lxdShared.PathExists(v.loopDevice) {
return nil
}

Expand All @@ -181,14 +181,14 @@ func (v *vm) umountImage() error {
}

// Make sure that p1 and p2 are also removed.
if lxd_shared.PathExists(v.getUEFIDevFile()) {
if lxdShared.PathExists(v.getUEFIDevFile()) {
err := os.Remove(v.getUEFIDevFile())
if err != nil {
return fmt.Errorf("Failed to remove file %q: %w", v.getUEFIDevFile(), err)
}
}

if lxd_shared.PathExists(v.getRootfsDevFile()) {
if lxdShared.PathExists(v.getRootfsDevFile()) {
err := os.Remove(v.getRootfsDevFile())
if err != nil {
return fmt.Errorf("Failed to remove file %q: %w", v.getRootfsDevFile(), err)
Expand Down
4 changes: 2 additions & 2 deletions managers/anise.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

lxd_shared "github.com/canonical/lxd/shared"
lxdShared "github.com/canonical/lxd/shared"

"github.com/canonical/lxd-imagebuilder/shared"
)
Expand Down Expand Up @@ -66,7 +66,7 @@ func (m *anise) manageRepository(repoAction shared.DefinitionPackagesRepository)
targetFile = filepath.Join("/etc/anise/repos.conf.d", repoAction.Name+".yml")
}

if !lxd_shared.PathExists(filepath.Dir(targetFile)) {
if !lxdShared.PathExists(filepath.Dir(targetFile)) {
err := os.MkdirAll(filepath.Dir(targetFile), 0755)
if err != nil {
return fmt.Errorf("Failed to create directory %q: %w", filepath.Dir(targetFile), err)
Expand Down
Loading
Loading