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

Side by Side Diff: container/lxc/lxc.go

Issue 77970043: Container Manager Interface
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:
View unified diff | Download patch
OLDNEW
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 conf.WarnAboutUnused() 105 conf.WarnAboutUnused()
106 return &containerManager{ 106 return &containerManager{
107 name: name, 107 name: name,
108 logdir: logDir, 108 logdir: logDir,
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 {
116 name := string(instance.Id())
117 lxcContainer := LxcObjectFactory.New(name)
118 // Create the cloud-init.
119 directory, err := container.NewDirectory(manager.name)
thumper 2014/03/26 02:25:57 wrong name... should just be "name"
120 if err != nil {
121 return err
122 }
123 // Start the lxc container with the appropriate settings for grabbing th e
124 // console output and a log file.
125 consoleFile := filepath.Join(directory, "console.log")
126 //lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), gol xc.LogDebug)
thumper 2014/03/26 02:25:57 why did you comment this out?
127 logger.Tracef("start the container")
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
130 // is necessary to get the appropriate rootfs reference without explicit ly
131 // setting it ourselves.
132 if err = lxcContainer.Start("", consoleFile); err != nil {
133 logger.Errorf("container failed to start: %v", err)
134 return err
135 }
136 return nil
137 }
138
139 func (manager *containerManager) StopContainer(instance instance.Instance) error {
140 name := string(instance.Id())
141 lxcContainer := LxcObjectFactory.New(name)
142 return lxcContainer.Stop()
143 }
144
115 func (manager *containerManager) CreateContainer( 145 func (manager *containerManager) CreateContainer(
116 machineConfig *cloudinit.MachineConfig, 146 machineConfig *cloudinit.MachineConfig,
117 series string, 147 series string,
118 network *container.NetworkConfig, 148 network *container.NetworkConfig,
119 ) (instance.Instance, *instance.HardwareCharacteristics, error) { 149 ) (instance.Instance, *instance.HardwareCharacteristics, error) {
120 start := time.Now() 150 start := time.Now()
121 name := names.MachineTag(machineConfig.MachineId) 151 name := names.MachineTag(machineConfig.MachineId)
122 if manager.name != "" { 152 if manager.name != "" {
123 name = fmt.Sprintf("%s-%s", manager.name, name) 153 name = fmt.Sprintf("%s-%s", manager.name, name)
124 } 154 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return nil, nil, err 227 return nil, nil, err
198 } 228 }
199 logger.Tracef("lxc container created") 229 logger.Tracef("lxc container created")
200 } 230 }
201 if err := autostartContainer(name); err != nil { 231 if err := autostartContainer(name); err != nil {
202 return nil, nil, err 232 return nil, nil, err
203 } 233 }
204 if err := mountHostLogDir(name, manager.logdir); err != nil { 234 if err := mountHostLogDir(name, manager.logdir); err != nil {
205 return nil, nil, err 235 return nil, nil, err
206 } 236 }
207 » // Start the lxc container with the appropriate settings for grabbing th e 237
208 » // console output and a log file. 238 » manager.StartContainer(&lxcInstance{lxcContainer, name})
thumper 2014/03/26 02:25:57 don't create a new instance here for the parameter
209 » consoleFile := filepath.Join(directory, "console.log") 239
210 » lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), golxc .LogDebug)
211 » logger.Tracef("start the container")
212 » // We explicitly don't pass through the config file to the container.Sta rt
213 » // method as we have passed it through at container creation time. This
214 » // is necessary to get the appropriate rootfs reference without explicit ly
215 » // setting it ourselves.
216 » if err = lxcContainer.Start("", consoleFile); err != nil {
217 » » logger.Errorf("container failed to start: %v", err)
218 » » return nil, nil, err
219 » }
220 arch := version.Current.Arch 240 arch := version.Current.Arch
221 hardware := &instance.HardwareCharacteristics{ 241 hardware := &instance.HardwareCharacteristics{
222 Arch: &arch, 242 Arch: &arch,
223 } 243 }
224 logger.Tracef("container %q started: %v", name, time.Now().Sub(start)) 244 logger.Tracef("container %q started: %v", name, time.Now().Sub(start))
225 return &lxcInstance{lxcContainer, name}, hardware, nil 245 return &lxcInstance{lxcContainer, name}, hardware, nil
226 } 246 }
227 247
228 func appendToContainerConfig(name, line string) error { 248 func appendToContainerConfig(name, line string) error {
229 file, err := os.OpenFile( 249 file, err := os.OpenFile(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // Newer versions don't do this, but instead have a config value inside the 393 // Newer versions don't do this, but instead have a config value inside the
374 // lxc.conf file. 394 // lxc.conf file.
375 func useRestartDir() bool { 395 func useRestartDir() bool {
376 if _, err := os.Stat(LxcRestartDir); err != nil { 396 if _, err := os.Stat(LxcRestartDir); err != nil {
377 if os.IsNotExist(err) { 397 if os.IsNotExist(err) {
378 return false 398 return false
379 } 399 }
380 } 400 }
381 return true 401 return true
382 } 402 }
OLDNEW

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