Merge lp:~thumper/juju-core/container-interface into lp:~go-bot/juju-core/trunk
- container-interface
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Tim Penhey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2047 |
Proposed branch: | lp:~thumper/juju-core/container-interface |
Merge into: | lp:~go-bot/juju-core/trunk |
Prerequisite: | lp:~thumper/juju-core/fix-add-machine-test |
Diff against target: |
439 lines (+104/-81) 6 files modified
container/interface.go (+31/-0) container/lxc/lxc.go (+21/-61) container/lxc/lxc_test.go (+15/-14) container/network.go (+29/-0) provider/local/environ.go (+4/-3) worker/provisioner/lxc-broker.go (+4/-3) |
To merge this branch: | bzr merge lp:~thumper/juju-core/container-interface |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+194757@code.launchpad.net |
Commit message
Move generic bits to container package.
The ContainerManager and the config type to create
it are common over both LXC and KVM. Also, network
config is similarly generic.
Most of this work is just moving types, changing imports
and parameter types.
Description of the change
Move generic bits to container package.
The ContainerManager and the config type to create
it are common over both LXC and KVM. Also, network
config is similarly generic.
Most of this work is just moving types, changing imports
and parameter types.
Tim Penhey (thumper) wrote : | # |
Ian Booth (wallyworld) wrote : | # |
LGTM. Very pleased to see this factored out.
https:/
File container/
https:/
container/
lxc bridge.
s/lxc/network ?
Tim Penhey (thumper) wrote : | # |
https:/
File container/
https:/
container/
lxc bridge.
On 2013/11/11 22:59:14, wallyworld wrote:
> s/lxc/network ?
Done.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~thumper/juju-core/container-interface into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpa...
Preview Diff
1 | === added file 'container/interface.go' | |||
2 | --- container/interface.go 1970-01-01 00:00:00 +0000 | |||
3 | +++ container/interface.go 2013-11-12 00:35:23 +0000 | |||
4 | @@ -0,0 +1,31 @@ | |||
5 | 1 | // Copyright 2013 Canonical Ltd. | ||
6 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
7 | 3 | |||
8 | 4 | package container | ||
9 | 5 | |||
10 | 6 | import ( | ||
11 | 7 | "launchpad.net/juju-core/environs/cloudinit" | ||
12 | 8 | "launchpad.net/juju-core/instance" | ||
13 | 9 | ) | ||
14 | 10 | |||
15 | 11 | // ManagerConfig contains the initialization parameters for the ContainerManager. | ||
16 | 12 | // The name of the manager is used to namespace the containers on the machine. | ||
17 | 13 | type ManagerConfig struct { | ||
18 | 14 | Name string | ||
19 | 15 | LogDir string | ||
20 | 16 | } | ||
21 | 17 | |||
22 | 18 | // Manager is responsible for starting containers, and stopping and listing | ||
23 | 19 | // containers that it has started. | ||
24 | 20 | type Manager interface { | ||
25 | 21 | // StartContainer creates and starts a new container for the specified machine. | ||
26 | 22 | StartContainer( | ||
27 | 23 | machineConfig *cloudinit.MachineConfig, | ||
28 | 24 | series string, | ||
29 | 25 | network *NetworkConfig) (instance.Instance, error) | ||
30 | 26 | // StopContainer stops and destroyes the container identified by Instance. | ||
31 | 27 | StopContainer(instance.Instance) error | ||
32 | 28 | // ListContainers return a list of containers that have been started by | ||
33 | 29 | // this manager. | ||
34 | 30 | ListContainers() ([]instance.Instance, error) | ||
35 | 31 | } | ||
36 | 0 | 32 | ||
37 | === modified file 'container/lxc/lxc.go' | |||
38 | --- container/lxc/lxc.go 2013-11-11 10:57:06 +0000 | |||
39 | +++ container/lxc/lxc.go 2013-11-12 00:35:23 +0000 | |||
40 | @@ -14,6 +14,7 @@ | |||
41 | 14 | "launchpad.net/golxc" | 14 | "launchpad.net/golxc" |
42 | 15 | "launchpad.net/loggo" | 15 | "launchpad.net/loggo" |
43 | 16 | 16 | ||
44 | 17 | "launchpad.net/juju-core/container" | ||
45 | 17 | "launchpad.net/juju-core/environs/cloudinit" | 18 | "launchpad.net/juju-core/environs/cloudinit" |
46 | 18 | "launchpad.net/juju-core/instance" | 19 | "launchpad.net/juju-core/instance" |
47 | 19 | "launchpad.net/juju-core/names" | 20 | "launchpad.net/juju-core/names" |
48 | @@ -33,58 +34,14 @@ | |||
49 | 33 | ) | 34 | ) |
50 | 34 | 35 | ||
51 | 35 | const ( | 36 | const ( |
52 | 36 | // BridgeNetwork will have the container use the lxc bridge. | ||
53 | 37 | bridgeNetwork = "bridge" | ||
54 | 38 | // PhyscialNetwork will have the container use a specified network device. | ||
55 | 39 | physicalNetwork = "physical" | ||
56 | 40 | // DefaultLxcBridge is the package created container bridge | 37 | // DefaultLxcBridge is the package created container bridge |
57 | 41 | DefaultLxcBridge = "lxcbr0" | 38 | DefaultLxcBridge = "lxcbr0" |
58 | 42 | ) | 39 | ) |
59 | 43 | 40 | ||
60 | 44 | // NetworkConfig defines how the container network will be configured. | ||
61 | 45 | type NetworkConfig struct { | ||
62 | 46 | networkType string | ||
63 | 47 | device string | ||
64 | 48 | } | ||
65 | 49 | |||
66 | 50 | // DefaultNetworkConfig returns a valid NetworkConfig to use the | 41 | // DefaultNetworkConfig returns a valid NetworkConfig to use the |
67 | 51 | // defaultLxcBridge that is created by the lxc package. | 42 | // defaultLxcBridge that is created by the lxc package. |
104 | 52 | func DefaultNetworkConfig() *NetworkConfig { | 43 | func DefaultNetworkConfig() *container.NetworkConfig { |
105 | 53 | return &NetworkConfig{bridgeNetwork, DefaultLxcBridge} | 44 | return container.BridgeNetworkConfig(DefaultLxcBridge) |
70 | 54 | } | ||
71 | 55 | |||
72 | 56 | // BridgeNetworkConfig returns a valid NetworkConfig to use the specified | ||
73 | 57 | // device as a network bridge for the container. | ||
74 | 58 | func BridgeNetworkConfig(device string) *NetworkConfig { | ||
75 | 59 | return &NetworkConfig{bridgeNetwork, device} | ||
76 | 60 | } | ||
77 | 61 | |||
78 | 62 | // PhysicalNetworkConfig returns a valid NetworkConfig to use the specified | ||
79 | 63 | // device as the network device for the container. | ||
80 | 64 | func PhysicalNetworkConfig(device string) *NetworkConfig { | ||
81 | 65 | return &NetworkConfig{physicalNetwork, device} | ||
82 | 66 | } | ||
83 | 67 | |||
84 | 68 | // ManagerConfig contains the initialization parameters for the ContainerManager. | ||
85 | 69 | type ManagerConfig struct { | ||
86 | 70 | Name string | ||
87 | 71 | LogDir string | ||
88 | 72 | } | ||
89 | 73 | |||
90 | 74 | // ContainerManager is responsible for starting containers, and stopping and | ||
91 | 75 | // listing containers that it has started. The name of the manager is used to | ||
92 | 76 | // namespace the lxc containers on the machine. | ||
93 | 77 | type ContainerManager interface { | ||
94 | 78 | // StartContainer creates and starts a new lxc container for the specified machine. | ||
95 | 79 | StartContainer( | ||
96 | 80 | machineConfig *cloudinit.MachineConfig, | ||
97 | 81 | series string, | ||
98 | 82 | network *NetworkConfig) (instance.Instance, error) | ||
99 | 83 | // StopContainer stops and destroyes the lxc container identified by Instance. | ||
100 | 84 | StopContainer(instance.Instance) error | ||
101 | 85 | // ListContainers return a list of containers that have been started by | ||
102 | 86 | // this manager. | ||
103 | 87 | ListContainers() ([]instance.Instance, error) | ||
106 | 88 | } | 45 | } |
107 | 89 | 46 | ||
108 | 90 | type containerManager struct { | 47 | type containerManager struct { |
109 | @@ -92,10 +49,13 @@ | |||
110 | 92 | logdir string | 49 | logdir string |
111 | 93 | } | 50 | } |
112 | 94 | 51 | ||
113 | 52 | // containerManager implements container.Manager. | ||
114 | 53 | var _ container.Manager = (*containerManager)(nil) | ||
115 | 54 | |||
116 | 95 | // NewContainerManager returns a manager object that can start and stop lxc | 55 | // NewContainerManager returns a manager object that can start and stop lxc |
117 | 96 | // containers. The containers that are created are namespaced by the name | 56 | // containers. The containers that are created are namespaced by the name |
118 | 97 | // parameter. | 57 | // parameter. |
120 | 98 | func NewContainerManager(conf ManagerConfig) ContainerManager { | 58 | func NewContainerManager(conf container.ManagerConfig) container.Manager { |
121 | 99 | logdir := "/var/log/juju" | 59 | logdir := "/var/log/juju" |
122 | 100 | if conf.LogDir != "" { | 60 | if conf.LogDir != "" { |
123 | 101 | logdir = conf.LogDir | 61 | logdir = conf.LogDir |
124 | @@ -106,7 +66,7 @@ | |||
125 | 106 | func (manager *containerManager) StartContainer( | 66 | func (manager *containerManager) StartContainer( |
126 | 107 | machineConfig *cloudinit.MachineConfig, | 67 | machineConfig *cloudinit.MachineConfig, |
127 | 108 | series string, | 68 | series string, |
129 | 109 | network *NetworkConfig) (instance.Instance, error) { | 69 | network *container.NetworkConfig) (instance.Instance, error) { |
130 | 110 | 70 | ||
131 | 111 | name := names.MachineTag(machineConfig.MachineId) | 71 | name := names.MachineTag(machineConfig.MachineId) |
132 | 112 | if manager.name != "" { | 72 | if manager.name != "" { |
133 | @@ -115,7 +75,7 @@ | |||
134 | 115 | // Note here that the lxcObjectFacotry only returns a valid container | 75 | // Note here that the lxcObjectFacotry only returns a valid container |
135 | 116 | // object, and doesn't actually construct the underlying lxc container on | 76 | // object, and doesn't actually construct the underlying lxc container on |
136 | 117 | // disk. | 77 | // disk. |
138 | 118 | container := LxcObjectFactory.New(name) | 78 | lxcContainer := LxcObjectFactory.New(name) |
139 | 119 | 79 | ||
140 | 120 | // Create the cloud-init. | 80 | // Create the cloud-init. |
141 | 121 | directory := jujuContainerDirectory(name) | 81 | directory := jujuContainerDirectory(name) |
142 | @@ -144,7 +104,7 @@ | |||
143 | 144 | } | 104 | } |
144 | 145 | // Create the container. | 105 | // Create the container. |
145 | 146 | logger.Tracef("create the container") | 106 | logger.Tracef("create the container") |
147 | 147 | if err := container.Create(configFile, defaultTemplate, templateParams...); err != nil { | 107 | if err := lxcContainer.Create(configFile, defaultTemplate, templateParams...); err != nil { |
148 | 148 | logger.Errorf("lxc container creation failed: %v", err) | 108 | logger.Errorf("lxc container creation failed: %v", err) |
149 | 149 | return nil, err | 109 | return nil, err |
150 | 150 | } | 110 | } |
151 | @@ -165,18 +125,18 @@ | |||
152 | 165 | // Start the lxc container with the appropriate settings for grabbing the | 125 | // Start the lxc container with the appropriate settings for grabbing the |
153 | 166 | // console output and a log file. | 126 | // console output and a log file. |
154 | 167 | consoleFile := filepath.Join(directory, "console.log") | 127 | consoleFile := filepath.Join(directory, "console.log") |
156 | 168 | container.SetLogFile(filepath.Join(directory, "container.log"), golxc.LogDebug) | 128 | lxcContainer.SetLogFile(filepath.Join(directory, "container.log"), golxc.LogDebug) |
157 | 169 | logger.Tracef("start the container") | 129 | logger.Tracef("start the container") |
158 | 170 | // We explicitly don't pass through the config file to the container.Start | 130 | // We explicitly don't pass through the config file to the container.Start |
159 | 171 | // method as we have passed it through at container creation time. This | 131 | // method as we have passed it through at container creation time. This |
160 | 172 | // is necessary to get the appropriate rootfs reference without explicitly | 132 | // is necessary to get the appropriate rootfs reference without explicitly |
161 | 173 | // setting it ourselves. | 133 | // setting it ourselves. |
163 | 174 | if err = container.Start("", consoleFile); err != nil { | 134 | if err = lxcContainer.Start("", consoleFile); err != nil { |
164 | 175 | logger.Errorf("container failed to start: %v", err) | 135 | logger.Errorf("container failed to start: %v", err) |
165 | 176 | return nil, err | 136 | return nil, err |
166 | 177 | } | 137 | } |
167 | 178 | logger.Tracef("container started") | 138 | logger.Tracef("container started") |
169 | 179 | return &lxcInstance{container, name}, nil | 139 | return &lxcInstance{lxcContainer, name}, nil |
170 | 180 | } | 140 | } |
171 | 181 | 141 | ||
172 | 182 | func (manager *containerManager) StopContainer(instance instance.Instance) error { | 142 | func (manager *containerManager) StopContainer(instance instance.Instance) error { |
173 | @@ -262,23 +222,23 @@ | |||
174 | 262 | return fmt.Sprintf(networkTemplate, networkType, networkLink) | 222 | return fmt.Sprintf(networkTemplate, networkType, networkLink) |
175 | 263 | } | 223 | } |
176 | 264 | 224 | ||
178 | 265 | func generateNetworkConfig(network *NetworkConfig) string { | 225 | func generateNetworkConfig(network *container.NetworkConfig) string { |
179 | 266 | if network == nil { | 226 | if network == nil { |
180 | 267 | logger.Warningf("network unspecified, using default networking config") | 227 | logger.Warningf("network unspecified, using default networking config") |
181 | 268 | network = DefaultNetworkConfig() | 228 | network = DefaultNetworkConfig() |
182 | 269 | } | 229 | } |
186 | 270 | switch network.networkType { | 230 | switch network.NetworkType { |
187 | 271 | case physicalNetwork: | 231 | case container.PhysicalNetwork: |
188 | 272 | return networkConfigTemplate("phys", network.device) | 232 | return networkConfigTemplate("phys", network.Device) |
189 | 273 | default: | 233 | default: |
191 | 274 | logger.Warningf("Unknown network config type %q: using bridge", network.networkType) | 234 | logger.Warningf("Unknown network config type %q: using bridge", network.NetworkType) |
192 | 275 | fallthrough | 235 | fallthrough |
195 | 276 | case bridgeNetwork: | 236 | case container.BridgeNetwork: |
196 | 277 | return networkConfigTemplate("veth", network.device) | 237 | return networkConfigTemplate("veth", network.Device) |
197 | 278 | } | 238 | } |
198 | 279 | } | 239 | } |
199 | 280 | 240 | ||
201 | 281 | func writeLxcConfig(network *NetworkConfig, directory, logdir string) (string, error) { | 241 | func writeLxcConfig(network *container.NetworkConfig, directory, logdir string) (string, error) { |
202 | 282 | networkConfig := generateNetworkConfig(network) | 242 | networkConfig := generateNetworkConfig(network) |
203 | 283 | configFilename := filepath.Join(directory, "lxc.conf") | 243 | configFilename := filepath.Join(directory, "lxc.conf") |
204 | 284 | configContent := fmt.Sprintf(localConfig, networkConfig, logdir) | 244 | configContent := fmt.Sprintf(localConfig, networkConfig, logdir) |
205 | 285 | 245 | ||
206 | === modified file 'container/lxc/lxc_test.go' | |||
207 | --- container/lxc/lxc_test.go 2013-11-11 10:57:06 +0000 | |||
208 | +++ container/lxc/lxc_test.go 2013-11-12 00:35:23 +0000 | |||
209 | @@ -15,6 +15,7 @@ | |||
210 | 15 | "launchpad.net/goyaml" | 15 | "launchpad.net/goyaml" |
211 | 16 | "launchpad.net/loggo" | 16 | "launchpad.net/loggo" |
212 | 17 | 17 | ||
213 | 18 | "launchpad.net/juju-core/container" | ||
214 | 18 | "launchpad.net/juju-core/container/lxc" | 19 | "launchpad.net/juju-core/container/lxc" |
215 | 19 | lxctesting "launchpad.net/juju-core/container/lxc/testing" | 20 | lxctesting "launchpad.net/juju-core/container/lxc/testing" |
216 | 20 | "launchpad.net/juju-core/environs" | 21 | "launchpad.net/juju-core/environs" |
217 | @@ -65,7 +66,7 @@ | |||
218 | 65 | aptConfigScript = fmt.Sprintf("#!/bin/sh\n echo '%s\n%s'", configHttpProxy, configProxyExtra) | 66 | aptConfigScript = fmt.Sprintf("#!/bin/sh\n echo '%s\n%s'", configHttpProxy, configProxyExtra) |
219 | 66 | ) | 67 | ) |
220 | 67 | 68 | ||
222 | 68 | func StartContainer(c *gc.C, manager lxc.ContainerManager, machineId string) instance.Instance { | 69 | func StartContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance { |
223 | 69 | stateInfo := jujutesting.FakeStateInfo(machineId) | 70 | stateInfo := jujutesting.FakeStateInfo(machineId) |
224 | 70 | apiInfo := jujutesting.FakeAPIInfo(machineId) | 71 | apiInfo := jujutesting.FakeAPIInfo(machineId) |
225 | 71 | machineConfig := environs.NewMachineConfig(machineId, "fake-nonce", stateInfo, apiInfo) | 72 | machineConfig := environs.NewMachineConfig(machineId, "fake-nonce", stateInfo, apiInfo) |
226 | @@ -75,14 +76,14 @@ | |||
227 | 75 | } | 76 | } |
228 | 76 | 77 | ||
229 | 77 | series := "series" | 78 | series := "series" |
231 | 78 | network := lxc.BridgeNetworkConfig("nic42") | 79 | network := container.BridgeNetworkConfig("nic42") |
232 | 79 | inst, err := manager.StartContainer(machineConfig, series, network) | 80 | inst, err := manager.StartContainer(machineConfig, series, network) |
233 | 80 | c.Assert(err, gc.IsNil) | 81 | c.Assert(err, gc.IsNil) |
234 | 81 | return inst | 82 | return inst |
235 | 82 | } | 83 | } |
236 | 83 | 84 | ||
237 | 84 | func (s *LxcSuite) TestStartContainer(c *gc.C) { | 85 | func (s *LxcSuite) TestStartContainer(c *gc.C) { |
239 | 85 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 86 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
240 | 86 | instance := StartContainer(c, manager, "1/lxc/0") | 87 | instance := StartContainer(c, manager, "1/lxc/0") |
241 | 87 | 88 | ||
242 | 88 | name := string(instance.Id()) | 89 | name := string(instance.Id()) |
243 | @@ -130,7 +131,7 @@ | |||
244 | 130 | } | 131 | } |
245 | 131 | 132 | ||
246 | 132 | func (s *LxcSuite) TestContainerState(c *gc.C) { | 133 | func (s *LxcSuite) TestContainerState(c *gc.C) { |
248 | 133 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 134 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
249 | 134 | instance := StartContainer(c, manager, "1/lxc/0") | 135 | instance := StartContainer(c, manager, "1/lxc/0") |
250 | 135 | 136 | ||
251 | 136 | // The mock container will be immediately "running". | 137 | // The mock container will be immediately "running". |
252 | @@ -144,7 +145,7 @@ | |||
253 | 144 | } | 145 | } |
254 | 145 | 146 | ||
255 | 146 | func (s *LxcSuite) TestStopContainer(c *gc.C) { | 147 | func (s *LxcSuite) TestStopContainer(c *gc.C) { |
257 | 147 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 148 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
258 | 148 | instance := StartContainer(c, manager, "1/lxc/0") | 149 | instance := StartContainer(c, manager, "1/lxc/0") |
259 | 149 | 150 | ||
260 | 150 | err := manager.StopContainer(instance) | 151 | err := manager.StopContainer(instance) |
261 | @@ -158,7 +159,7 @@ | |||
262 | 158 | } | 159 | } |
263 | 159 | 160 | ||
264 | 160 | func (s *LxcSuite) TestStopContainerNameClash(c *gc.C) { | 161 | func (s *LxcSuite) TestStopContainerNameClash(c *gc.C) { |
266 | 161 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 162 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
267 | 162 | instance := StartContainer(c, manager, "1/lxc/0") | 163 | instance := StartContainer(c, manager, "1/lxc/0") |
268 | 163 | 164 | ||
269 | 164 | name := string(instance.Id()) | 165 | name := string(instance.Id()) |
270 | @@ -176,14 +177,14 @@ | |||
271 | 176 | } | 177 | } |
272 | 177 | 178 | ||
273 | 178 | func (s *LxcSuite) TestNamedManagerPrefix(c *gc.C) { | 179 | func (s *LxcSuite) TestNamedManagerPrefix(c *gc.C) { |
275 | 179 | manager := lxc.NewContainerManager(lxc.ManagerConfig{Name: "eric"}) | 180 | manager := lxc.NewContainerManager(container.ManagerConfig{Name: "eric"}) |
276 | 180 | instance := StartContainer(c, manager, "1/lxc/0") | 181 | instance := StartContainer(c, manager, "1/lxc/0") |
277 | 181 | c.Assert(string(instance.Id()), gc.Equals, "eric-machine-1-lxc-0") | 182 | c.Assert(string(instance.Id()), gc.Equals, "eric-machine-1-lxc-0") |
278 | 182 | } | 183 | } |
279 | 183 | 184 | ||
280 | 184 | func (s *LxcSuite) TestListContainers(c *gc.C) { | 185 | func (s *LxcSuite) TestListContainers(c *gc.C) { |
283 | 185 | foo := lxc.NewContainerManager(lxc.ManagerConfig{Name: "foo"}) | 186 | foo := lxc.NewContainerManager(container.ManagerConfig{Name: "foo"}) |
284 | 186 | bar := lxc.NewContainerManager(lxc.ManagerConfig{Name: "bar"}) | 187 | bar := lxc.NewContainerManager(container.ManagerConfig{Name: "bar"}) |
285 | 187 | 188 | ||
286 | 188 | foo1 := StartContainer(c, foo, "1/lxc/0") | 189 | foo1 := StartContainer(c, foo, "1/lxc/0") |
287 | 189 | foo2 := StartContainer(c, foo, "1/lxc/1") | 190 | foo2 := StartContainer(c, foo, "1/lxc/1") |
288 | @@ -202,14 +203,14 @@ | |||
289 | 202 | } | 203 | } |
290 | 203 | 204 | ||
291 | 204 | func (s *LxcSuite) TestStartContainerAutostarts(c *gc.C) { | 205 | func (s *LxcSuite) TestStartContainerAutostarts(c *gc.C) { |
293 | 205 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 206 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
294 | 206 | instance := StartContainer(c, manager, "1/lxc/0") | 207 | instance := StartContainer(c, manager, "1/lxc/0") |
295 | 207 | autostartLink := lxc.RestartSymlink(string(instance.Id())) | 208 | autostartLink := lxc.RestartSymlink(string(instance.Id())) |
296 | 208 | c.Assert(autostartLink, jc.IsSymlink) | 209 | c.Assert(autostartLink, jc.IsSymlink) |
297 | 209 | } | 210 | } |
298 | 210 | 211 | ||
299 | 211 | func (s *LxcSuite) TestStopContainerRemovesAutostartLink(c *gc.C) { | 212 | func (s *LxcSuite) TestStopContainerRemovesAutostartLink(c *gc.C) { |
301 | 212 | manager := lxc.NewContainerManager(lxc.ManagerConfig{}) | 213 | manager := lxc.NewContainerManager(container.ManagerConfig{}) |
302 | 213 | instance := StartContainer(c, manager, "1/lxc/0") | 214 | instance := StartContainer(c, manager, "1/lxc/0") |
303 | 214 | err := manager.StopContainer(instance) | 215 | err := manager.StopContainer(instance) |
304 | 215 | c.Assert(err, gc.IsNil) | 216 | c.Assert(err, gc.IsNil) |
305 | @@ -225,7 +226,7 @@ | |||
306 | 225 | 226 | ||
307 | 226 | func (*NetworkSuite) TestGenerateNetworkConfig(c *gc.C) { | 227 | func (*NetworkSuite) TestGenerateNetworkConfig(c *gc.C) { |
308 | 227 | for _, test := range []struct { | 228 | for _, test := range []struct { |
310 | 228 | config *lxc.NetworkConfig | 229 | config *container.NetworkConfig |
311 | 229 | net string | 230 | net string |
312 | 230 | link string | 231 | link string |
313 | 231 | }{{ | 232 | }{{ |
314 | @@ -237,11 +238,11 @@ | |||
315 | 237 | net: "veth", | 238 | net: "veth", |
316 | 238 | link: "lxcbr0", | 239 | link: "lxcbr0", |
317 | 239 | }, { | 240 | }, { |
319 | 240 | config: lxc.BridgeNetworkConfig("foo"), | 241 | config: container.BridgeNetworkConfig("foo"), |
320 | 241 | net: "veth", | 242 | net: "veth", |
321 | 242 | link: "foo", | 243 | link: "foo", |
322 | 243 | }, { | 244 | }, { |
324 | 244 | config: lxc.PhysicalNetworkConfig("foo"), | 245 | config: container.PhysicalNetworkConfig("foo"), |
325 | 245 | net: "phys", | 246 | net: "phys", |
326 | 246 | link: "foo", | 247 | link: "foo", |
327 | 247 | }} { | 248 | }} { |
328 | 248 | 249 | ||
329 | === added file 'container/network.go' | |||
330 | --- container/network.go 1970-01-01 00:00:00 +0000 | |||
331 | +++ container/network.go 2013-11-12 00:35:23 +0000 | |||
332 | @@ -0,0 +1,29 @@ | |||
333 | 1 | // Copyright 2013 Canonical Ltd. | ||
334 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
335 | 3 | |||
336 | 4 | package container | ||
337 | 5 | |||
338 | 6 | const ( | ||
339 | 7 | // BridgeNetwork will have the container use the network bridge. | ||
340 | 8 | BridgeNetwork = "bridge" | ||
341 | 9 | // PhyscialNetwork will have the container use a specified network device. | ||
342 | 10 | PhysicalNetwork = "physical" | ||
343 | 11 | ) | ||
344 | 12 | |||
345 | 13 | // NetworkConfig defines how the container network will be configured. | ||
346 | 14 | type NetworkConfig struct { | ||
347 | 15 | NetworkType string | ||
348 | 16 | Device string | ||
349 | 17 | } | ||
350 | 18 | |||
351 | 19 | // BridgeNetworkConfig returns a valid NetworkConfig to use the specified | ||
352 | 20 | // device as a network bridge for the container. | ||
353 | 21 | func BridgeNetworkConfig(device string) *NetworkConfig { | ||
354 | 22 | return &NetworkConfig{BridgeNetwork, device} | ||
355 | 23 | } | ||
356 | 24 | |||
357 | 25 | // PhysicalNetworkConfig returns a valid NetworkConfig to use the specified | ||
358 | 26 | // device as the network device for the container. | ||
359 | 27 | func PhysicalNetworkConfig(device string) *NetworkConfig { | ||
360 | 28 | return &NetworkConfig{PhysicalNetwork, device} | ||
361 | 29 | } | ||
362 | 0 | 30 | ||
363 | === modified file 'provider/local/environ.go' | |||
364 | --- provider/local/environ.go 2013-11-07 09:09:55 +0000 | |||
365 | +++ provider/local/environ.go 2013-11-12 00:35:23 +0000 | |||
366 | @@ -16,6 +16,7 @@ | |||
367 | 16 | "launchpad.net/juju-core/agent" | 16 | "launchpad.net/juju-core/agent" |
368 | 17 | agenttools "launchpad.net/juju-core/agent/tools" | 17 | agenttools "launchpad.net/juju-core/agent/tools" |
369 | 18 | "launchpad.net/juju-core/constraints" | 18 | "launchpad.net/juju-core/constraints" |
370 | 19 | "launchpad.net/juju-core/container" | ||
371 | 19 | "launchpad.net/juju-core/container/lxc" | 20 | "launchpad.net/juju-core/container/lxc" |
372 | 20 | "launchpad.net/juju-core/environs" | 21 | "launchpad.net/juju-core/environs" |
373 | 21 | "launchpad.net/juju-core/environs/cloudinit" | 22 | "launchpad.net/juju-core/environs/cloudinit" |
374 | @@ -58,7 +59,7 @@ | |||
375 | 58 | name string | 59 | name string |
376 | 59 | sharedStorageListener net.Listener | 60 | sharedStorageListener net.Listener |
377 | 60 | storageListener net.Listener | 61 | storageListener net.Listener |
379 | 61 | containerManager lxc.ContainerManager | 62 | containerManager container.Manager |
380 | 62 | } | 63 | } |
381 | 63 | 64 | ||
382 | 64 | // GetToolsSources returns a list of sources which are used to search for simplestreams tools metadata. | 65 | // GetToolsSources returns a list of sources which are used to search for simplestreams tools metadata. |
383 | @@ -175,7 +176,7 @@ | |||
384 | 175 | env.name = ecfg.Name() | 176 | env.name = ecfg.Name() |
385 | 176 | 177 | ||
386 | 177 | env.containerManager = lxc.NewContainerManager( | 178 | env.containerManager = lxc.NewContainerManager( |
388 | 178 | lxc.ManagerConfig{ | 179 | container.ManagerConfig{ |
389 | 179 | Name: env.config.namespace(), | 180 | Name: env.config.namespace(), |
390 | 180 | LogDir: env.config.logDir(), | 181 | LogDir: env.config.logDir(), |
391 | 181 | }) | 182 | }) |
392 | @@ -266,7 +267,7 @@ | |||
393 | 266 | machineConfig.Tools = possibleTools[0] | 267 | machineConfig.Tools = possibleTools[0] |
394 | 267 | machineConfig.MachineContainerType = instance.LXC | 268 | machineConfig.MachineContainerType = instance.LXC |
395 | 268 | logger.Debugf("tools: %#v", machineConfig.Tools) | 269 | logger.Debugf("tools: %#v", machineConfig.Tools) |
397 | 269 | network := lxc.BridgeNetworkConfig(env.config.networkBridge()) | 270 | network := container.BridgeNetworkConfig(env.config.networkBridge()) |
398 | 270 | if err := environs.FinishMachineConfig(machineConfig, env.config.Config, cons); err != nil { | 271 | if err := environs.FinishMachineConfig(machineConfig, env.config.Config, cons); err != nil { |
399 | 271 | return nil, nil, err | 272 | return nil, nil, err |
400 | 272 | } | 273 | } |
401 | 273 | 274 | ||
402 | === modified file 'worker/provisioner/lxc-broker.go' | |||
403 | --- worker/provisioner/lxc-broker.go 2013-10-31 21:36:40 +0000 | |||
404 | +++ worker/provisioner/lxc-broker.go 2013-11-12 00:35:23 +0000 | |||
405 | @@ -8,6 +8,7 @@ | |||
406 | 8 | 8 | ||
407 | 9 | "launchpad.net/juju-core/agent" | 9 | "launchpad.net/juju-core/agent" |
408 | 10 | "launchpad.net/juju-core/constraints" | 10 | "launchpad.net/juju-core/constraints" |
409 | 11 | "launchpad.net/juju-core/container" | ||
410 | 11 | "launchpad.net/juju-core/container/lxc" | 12 | "launchpad.net/juju-core/container/lxc" |
411 | 12 | "launchpad.net/juju-core/environs" | 13 | "launchpad.net/juju-core/environs" |
412 | 13 | "launchpad.net/juju-core/environs/cloudinit" | 14 | "launchpad.net/juju-core/environs/cloudinit" |
413 | @@ -27,7 +28,7 @@ | |||
414 | 27 | 28 | ||
415 | 28 | func NewLxcBroker(api APICalls, tools *tools.Tools, agentConfig agent.Config) environs.InstanceBroker { | 29 | func NewLxcBroker(api APICalls, tools *tools.Tools, agentConfig agent.Config) environs.InstanceBroker { |
416 | 29 | return &lxcBroker{ | 30 | return &lxcBroker{ |
418 | 30 | manager: lxc.NewContainerManager(lxc.ManagerConfig{Name: "juju"}), | 31 | manager: lxc.NewContainerManager(container.ManagerConfig{Name: "juju"}), |
419 | 31 | api: api, | 32 | api: api, |
420 | 32 | tools: tools, | 33 | tools: tools, |
421 | 33 | agentConfig: agentConfig, | 34 | agentConfig: agentConfig, |
422 | @@ -35,7 +36,7 @@ | |||
423 | 35 | } | 36 | } |
424 | 36 | 37 | ||
425 | 37 | type lxcBroker struct { | 38 | type lxcBroker struct { |
427 | 38 | manager lxc.ContainerManager | 39 | manager container.Manager |
428 | 39 | api APICalls | 40 | api APICalls |
429 | 40 | tools *tools.Tools | 41 | tools *tools.Tools |
430 | 41 | agentConfig agent.Config | 42 | agentConfig agent.Config |
431 | @@ -57,7 +58,7 @@ | |||
432 | 57 | if bridgeDevice == "" { | 58 | if bridgeDevice == "" { |
433 | 58 | bridgeDevice = lxc.DefaultLxcBridge | 59 | bridgeDevice = lxc.DefaultLxcBridge |
434 | 59 | } | 60 | } |
436 | 60 | network := lxc.BridgeNetworkConfig(bridgeDevice) | 61 | network := container.BridgeNetworkConfig(bridgeDevice) |
437 | 61 | 62 | ||
438 | 62 | series := possibleTools.OneSeries() | 63 | series := possibleTools.OneSeries() |
439 | 63 | machineConfig.MachineContainerType = instance.LXC | 64 | machineConfig.MachineContainerType = instance.LXC |
Reviewers: mp+194757_ code.launchpad. net,
Message:
Please take a look.
Description:
Move generic bits to container package.
The ContainerManager and the config type to create
it are common over both LXC and KVM. Also, network
config is similarly generic.
Most of this work is just moving types, changing imports
and parameter types.
https:/ /code.launchpad .net/~thumper/ juju-core/ container- interface/ +merge/ 194757
Requires: /code.launchpad .net/~thumper/ juju-core/ fix-add- machine- test/+merge/ 194753
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/24780043/
Affected files (+106, -81 lines): interface. go lxc/lxc. go lxc/lxc_ test.go network. go local/environ. go provisioner/ lxc-broker. go
A [revision details]
A container/
M container/
M container/
A container/
M provider/
M worker/