/
lxd.go
46 lines (34 loc) · 1.06 KB
/
lxd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2019 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package dependency
import (
"fmt"
"github.com/juju/errors"
"github.com/juju/juju/core/base"
"github.com/juju/juju/packaging"
)
var ubuntu = "ubuntu"
// LXD returns a dependency instance for installing lxd support using the
// specified channel preferences (applies to cosmic or later).
func LXD(snapChannel string) packaging.Dependency {
return lxdDependency{
snapChannel: snapChannel,
}
}
type lxdDependency struct {
snapChannel string
}
// PackageList implements packaging.Dependency.
func (dep lxdDependency) PackageList(b base.Base) ([]packaging.Package, error) {
if b.OS != ubuntu {
return nil, errors.NotSupportedf("LXD containers on base %q", b)
}
var pkg packaging.Package
if dep.snapChannel == "" {
return nil, errors.NotValidf("snap channel for lxd dependency")
}
pkg.Name = "lxd"
pkg.InstallOptions = fmt.Sprintf("--classic --channel %s", dep.snapChannel)
pkg.PackageManager = packaging.SnapPackageManager
return []packaging.Package{pkg}, nil
}