~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/container/lxd/lxd.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
        defer func() {
98
98
                if err != nil {
99
 
                        callback(status.StatusProvisioningError, fmt.Sprintf("Creating container: %v", err), nil)
 
99
                        callback(status.ProvisioningError, fmt.Sprintf("Creating container: %v", err), nil)
100
100
                }
101
101
        }()
102
102
 
111
111
        err = manager.client.EnsureImageExists(series,
112
112
                lxdclient.DefaultImageSources,
113
113
                func(progress string) {
114
 
                        callback(status.StatusProvisioning, progress, nil)
 
114
                        callback(status.Provisioning, progress, nil)
115
115
                })
116
116
        if err != nil {
117
117
                err = errors.Annotatef(err, "failed to ensure LXD image")
123
123
                return nil, nil, errors.Trace(err)
124
124
        }
125
125
 
126
 
        userData, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
 
126
        // Do not pass networkConfig, as we want to directly inject our own ENI
 
127
        // rather than using cloud-init.
 
128
        userData, err := containerinit.CloudInitUserData(instanceConfig, nil)
127
129
        if err != nil {
128
130
                return
129
131
        }
143
145
                return
144
146
        }
145
147
 
 
148
        // TODO(macgreagoir) This might be dead code. Do we always get
 
149
        // len(nics) > 0?
146
150
        profiles := []string{}
147
151
 
148
152
        if len(nics) == 0 {
152
156
                logger.Infof("instance %q configured with %v network devices", name, nics)
153
157
        }
154
158
 
 
159
        // Push the required /etc/network/interfaces file to the container.
 
160
        // By pushing this file (which happens after LXD init, and before LXD
 
161
        // start) we ensure that we get Juju's version of ENI, as opposed to
 
162
        // the default LXD version, which may assume it can do DHCP over eth0.
 
163
        // Especially on a multi-nic host, it is possible for MAAS to provide
 
164
        // DHCP on a different space to that which the container eth0 interface
 
165
        // will be bridged, or not provide DHCP at all.
 
166
        eni, err := containerinit.GenerateNetworkConfig(networkConfig)
 
167
        if err != nil {
 
168
                err = errors.Annotatef(err, "failed to generate /etc/network/interfaces content")
 
169
                return
 
170
        }
 
171
 
155
172
        spec := lxdclient.InstanceSpec{
156
173
                Name:     name,
157
174
                Image:    manager.client.ImageNameForSeries(series),
158
175
                Metadata: metadata,
159
176
                Devices:  nics,
160
177
                Profiles: profiles,
 
178
                Files: lxdclient.Files{
 
179
                        lxdclient.File{
 
180
                                Content: []byte(eni),
 
181
                                Path:    "/etc/network/interfaces",
 
182
                                GID:     0,
 
183
                                UID:     0,
 
184
                                Mode:    0644,
 
185
                        },
 
186
                },
161
187
        }
162
188
 
163
189
        logger.Infof("starting instance %q (image %q)...", spec.Name, spec.Image)
164
 
        callback(status.StatusProvisioning, "Starting container", nil)
 
190
        callback(status.Provisioning, "Starting container", nil)
165
191
        _, err = manager.client.AddInstance(spec)
166
192
        if err != nil {
167
193
                return
168
194
        }
169
195
 
170
 
        callback(status.StatusRunning, "Container started", nil)
 
196
        callback(status.Running, "Container started", nil)
171
197
        inst = &lxdInstance{name, manager.client}
172
198
        return
173
199
}