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

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        "github.com/juju/juju/cloudconfig/instancecfg"
32
32
        "github.com/juju/juju/container"
33
33
        "github.com/juju/juju/instance"
 
34
        "github.com/juju/juju/status"
34
35
        "github.com/juju/juju/storage/looputil"
35
36
)
36
37
 
90
91
        loopDeviceManager looputil.LoopDeviceManager
91
92
}
92
93
 
93
 
// containerManager implements container.Manager.
94
 
var _ container.Manager = (*containerManager)(nil)
95
 
 
96
94
// NewContainerManager returns a manager object that can start and
97
95
// stop lxc containers. The containers that are created are namespaced
98
96
// by the name parameter inside the given ManagerConfig.
99
 
func NewContainerManager(
 
97
func NewContainerManager(conf container.ManagerConfig, imageURLGetter container.ImageURLGetter) (container.Manager, error) {
 
98
        return newContainerManager(conf, imageURLGetter, looputil.NewLoopDeviceManager())
 
99
}
 
100
 
 
101
func newContainerManager(
100
102
        conf container.ManagerConfig,
101
103
        imageURLGetter container.ImageURLGetter,
102
104
        loopDeviceManager looputil.LoopDeviceManager,
167
169
        series string,
168
170
        networkConfig *container.NetworkConfig,
169
171
        storageConfig *container.StorageConfig,
 
172
        callback container.StatusCallback,
170
173
) (inst instance.Instance, _ *instance.HardwareCharacteristics, err error) {
171
174
        // Check our preconditions
172
175
        if manager == nil {
177
180
                panic("networkConfig is nil")
178
181
        } else if storageConfig == nil {
179
182
                panic("storageConfig is nil")
 
183
        } else if callback == nil {
 
184
                panic("status callback is nil")
180
185
        }
181
186
 
182
187
        // Log how long the start took
215
220
                        instanceConfig.EnableOSUpgrade,
216
221
                        manager.imageURLGetter,
217
222
                        manager.useAUFS,
 
223
                        callback,
218
224
                )
219
225
                if err != nil {
220
226
                        return nil, nil, errors.Annotate(err, "failed to retrieve the template to clone")
248
254
                        return nil, nil, errors.Annotate(err, "failed to reorder network settings")
249
255
                }
250
256
 
 
257
                err = callback(status.StatusProvisioning, "Cloning template container", nil)
 
258
                if err != nil {
 
259
                        logger.Warningf("Cannot set instance status for container: %v", err)
 
260
                }
251
261
                lxcContainer, err = templateContainer.Clone(name, extraCloneArgs, templateParams)
252
262
                if err != nil {
253
263
                        return nil, nil, errors.Wrap(err, instance.NewRetryableCreationError("lxc container cloning failed"))
286
296
                }
287
297
        }
288
298
 
 
299
        callback(status.StatusProvisioning, "Configuring container", nil)
 
300
 
289
301
        if err := autostartContainer(name); err != nil {
290
302
                return nil, nil, errors.Annotate(err, "failed to configure the container for autostart")
291
303
        }
342
354
        consoleFile := filepath.Join(directory, "console.log")
343
355
        lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), golxc.LogDebug)
344
356
        logger.Tracef("start the container")
 
357
        callback(status.StatusProvisioning, "Starting container", nil)
345
358
 
346
359
        // We explicitly don't pass through the config file to the container.Start
347
360
        // method as we have passed it through at container creation time.  This
367
380
                Arch: &arch,
368
381
        }
369
382
 
 
383
        callback(status.StatusRunning, "Container started", nil)
370
384
        return &lxcInstance{lxcContainer, name}, hardware, nil
371
385
}
372
386