~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to cmd/jujud/upgradevalidation.go

[r=thumper] Conditionally install lxc

There are two primary situations where we don't want
the machine agent to install lxc:
 1. when the machine agent is inside an lxc container
    as known by state
 2. when the machine has been provisioned by the local
    provider (because it is an lxc container)

When lxc is installed inside a container, it adds a
bridge network device with the same defaults as the
host. This kills any routing in or out of the container.

Upstart provides support for setting environment variables
as part of the config, and we use this to pass the provider
type through.

https://codereview.appspot.com/11330043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package main
5
5
 
6
6
import (
 
7
        "os"
7
8
        "path/filepath"
8
9
        "time"
9
10
 
10
11
        "launchpad.net/loggo"
11
12
 
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"
15
19
)
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 {
 
64
                return nil
 
65
        }
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")