Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(959)

Delta Between Two Patch Sets: container/lxc/lxc.go

Issue 77970043: Container Manager Interface
Left Patch Set: Container Manager Interface Created 11 years ago
Right Patch Set: Container Manager Interface Created 11 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « container/kvm/mock/mock-kvm_test.go ('k') | container/lxc/lxc_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package lxc 4 package lxc
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "io/ioutil" 8 "io/ioutil"
9 "os" 9 "os"
10 "os/exec" 10 "os/exec"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 createWithClone: useClone, 109 createWithClone: useClone,
110 useAUFS: useAUFS, 110 useAUFS: useAUFS,
111 backingFilesystem: backingFS, 111 backingFilesystem: backingFS,
112 }, nil 112 }, nil
113 } 113 }
114 114
115 func (manager *containerManager) StartContainer(instance instance.Instance) erro r { 115 func (manager *containerManager) StartContainer(instance instance.Instance) erro r {
116 name := string(instance.Id()) 116 name := string(instance.Id())
117 lxcContainer := LxcObjectFactory.New(name) 117 lxcContainer := LxcObjectFactory.New(name)
118 // Create the cloud-init. 118 // Create the cloud-init.
119 » directory, err := container.NewDirectory(manager.name) 119 » directory, err := container.NewDirectory(name)
120 if err != nil { 120 if err != nil {
121 return err 121 return err
122 } 122 }
123 // Start the lxc container with the appropriate settings for grabbing th e 123 // Start the lxc container with the appropriate settings for grabbing th e
124 // console output and a log file. 124 // console output and a log file.
125 consoleFile := filepath.Join(directory, "console.log") 125 consoleFile := filepath.Join(directory, "console.log")
126 » //lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), gol xc.LogDebug) 126 » lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), golxc .LogDebug)
127 logger.Tracef("start the container") 127 logger.Tracef("start the container")
128 // We explicitly don't pass through the config file to the container.Sta rt 128 // We explicitly don't pass through the config file to the container.Sta rt
129 // method as we have passed it through at container creation time. This 129 // method as we have passed it through at container creation time. This
130 // is necessary to get the appropriate rootfs reference without explicit ly 130 // is necessary to get the appropriate rootfs reference without explicit ly
131 // setting it ourselves. 131 // setting it ourselves.
132 if err = lxcContainer.Start("", consoleFile); err != nil { 132 if err = lxcContainer.Start("", consoleFile); err != nil {
133 logger.Errorf("container failed to start: %v", err) 133 logger.Errorf("container failed to start: %v", err)
134 return err 134 return err
135 } 135 }
136 return nil 136 return nil
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 logger.Tracef("lxc container created") 229 logger.Tracef("lxc container created")
230 } 230 }
231 if err := autostartContainer(name); err != nil { 231 if err := autostartContainer(name); err != nil {
232 return nil, nil, err 232 return nil, nil, err
233 } 233 }
234 if err := mountHostLogDir(name, manager.logdir); err != nil { 234 if err := mountHostLogDir(name, manager.logdir); err != nil {
235 return nil, nil, err 235 return nil, nil, err
236 } 236 }
237 237
238 » manager.StartContainer(&lxcInstance{lxcContainer, name}) 238 » container := &lxcInstance{lxcContainer, name}
239
240 » manager.StartContainer(container)
239 241
240 arch := version.Current.Arch 242 arch := version.Current.Arch
241 hardware := &instance.HardwareCharacteristics{ 243 hardware := &instance.HardwareCharacteristics{
242 Arch: &arch, 244 Arch: &arch,
243 } 245 }
244 logger.Tracef("container %q started: %v", name, time.Now().Sub(start)) 246 logger.Tracef("container %q started: %v", name, time.Now().Sub(start))
245 » return &lxcInstance{lxcContainer, name}, hardware, nil 247 » return container, hardware, nil
246 } 248 }
247 249
248 func appendToContainerConfig(name, line string) error { 250 func appendToContainerConfig(name, line string) error {
249 file, err := os.OpenFile( 251 file, err := os.OpenFile(
250 containerConfigFilename(name), os.O_RDWR|os.O_APPEND, 0644) 252 containerConfigFilename(name), os.O_RDWR|os.O_APPEND, 0644)
251 if err != nil { 253 if err != nil {
252 return err 254 return err
253 } 255 }
254 defer file.Close() 256 defer file.Close()
255 _, err = file.WriteString(line) 257 _, err = file.WriteString(line)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // Newer versions don't do this, but instead have a config value inside the 395 // Newer versions don't do this, but instead have a config value inside the
394 // lxc.conf file. 396 // lxc.conf file.
395 func useRestartDir() bool { 397 func useRestartDir() bool {
396 if _, err := os.Stat(LxcRestartDir); err != nil { 398 if _, err := os.Stat(LxcRestartDir); err != nil {
397 if os.IsNotExist(err) { 399 if os.IsNotExist(err) {
398 return false 400 return false
399 } 401 }
400 } 402 }
401 return true 403 return true
402 } 404 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b