10
11
"launchpad.net/loggo"
12
13
"launchpad.net/juju-core/container/lxc"
14
"launchpad.net/juju-core/environs/provider"
15
"launchpad.net/juju-core/instance"
16
"launchpad.net/juju-core/state"
13
17
"launchpad.net/juju-core/utils"
14
18
"launchpad.net/juju-core/utils/fslock"
44
48
// dataDir is the root location where data files are put. It is used to grab
45
49
// the uniter-hook-execution lock so that we don't try run to apt-get at the
46
50
// same time that a hook might want to run it.
47
func EnsureWeHaveLXC(dataDir string) error {
51
func EnsureWeHaveLXC(dataDir, machineTag string) error {
52
// We need to short circuit this in two places:
53
// 1. if we are running a local provider, then the machines are lxc
54
// containers, and if we install lxc on them, it adds an lxc bridge
55
// network device with the same ip address as the hosts bridge. This
56
// screws up all the networking routes.
57
// 2. if the machine is an lxc container, we need to avoid installing lxc
58
// package for exactly the same reasons.
59
// Later, post-precise LTS, when we have updated lxc, we can bring this
60
// back in to have nested lxc, but until then, we have to avoid it.
61
containerType := state.ContainerTypeFromId(state.MachineIdFromTag(machineTag))
62
providerType := os.Getenv("JUJU_PROVIDER_TYPE")
63
if providerType == provider.Local || containerType == instance.LXC {
48
66
manager := lxc.NewContainerManager(lxc.ManagerConfig{Name: "lxc-test"})
49
67
if _, err := manager.ListContainers(); err == nil {
50
68
validationLogger.Debugf("found lxc, not installing")