Merge lp:~thumper/juju-core/container-userdata into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 2049
Proposed branch: lp:~thumper/juju-core/container-userdata
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~thumper/juju-core/container-interface
Diff against target: 187 lines (+82/-63)
2 files modified
container/lxc/lxc.go (+1/-63)
container/userdata.go (+81/-0)
To merge this branch: bzr merge lp:~thumper/juju-core/container-userdata
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+194759@code.launchpad.net

Commit message

Move the writing of the user-data to container.

Writing out the user-data is container agnostic.

https://codereview.appspot.com/24790043/

Description of the change

Move the writing of the userdata to container.

Writing out the userdata is container agnostic.

https://codereview.appspot.com/24790043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Reviewers: mp+194759_code.launchpad.net,

Message:
Please take a look.

Description:
Move the writing of the userdata to container.

Writing out the userdata is container agnostic.

https://code.launchpad.net/~thumper/juju-core/container-userdata/+merge/194759

Requires:
https://code.launchpad.net/~thumper/juju-core/container-interface/+merge/194757

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/24790043/

Affected files (+84, -63 lines):
   A [revision details]
   M container/lxc/lxc.go
   A container/userdata.go

Revision history for this message
Ian Booth (wallyworld) wrote :
Revision history for this message
Go Bot (go-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'container/lxc/lxc.go'
2--- container/lxc/lxc.go 2013-11-12 00:35:51 +0000
3+++ container/lxc/lxc.go 2013-11-12 00:35:51 +0000
4@@ -8,7 +8,6 @@
5 "io/ioutil"
6 "os"
7 "path/filepath"
8- "regexp"
9 "strings"
10
11 "launchpad.net/golxc"
12@@ -18,14 +17,12 @@
13 "launchpad.net/juju-core/environs/cloudinit"
14 "launchpad.net/juju-core/instance"
15 "launchpad.net/juju-core/names"
16- "launchpad.net/juju-core/utils"
17 )
18
19 var logger = loggo.GetLogger("juju.container.lxc")
20
21 var (
22 defaultTemplate = "ubuntu-cloud"
23- aptHTTPProxyRE = regexp.MustCompile(`(?i)^Acquire::HTTP::Proxy\s+"([^"]+)";$`)
24 ContainerDir = "/var/lib/juju/containers"
25 RemovedContainerDir = "/var/lib/juju/removed-containers"
26 LxcContainerDir = "/var/lib/lxc"
27@@ -85,7 +82,7 @@
28 return nil, err
29 }
30 logger.Tracef("write cloud-init")
31- userDataFilename, err := writeUserData(machineConfig, directory)
32+ userDataFilename, err := container.WriteUserData(machineConfig, directory)
33 if err != nil {
34 logger.Errorf("failed to write user data: %v", err)
35 return nil, err
36@@ -248,65 +245,6 @@
37 return configFilename, nil
38 }
39
40-func writeUserData(machineConfig *cloudinit.MachineConfig, directory string) (string, error) {
41- userData, err := cloudInitUserData(machineConfig)
42- if err != nil {
43- logger.Errorf("failed to create user data: %v", err)
44- return "", err
45- }
46- userDataFilename := filepath.Join(directory, "cloud-init")
47- if err := ioutil.WriteFile(userDataFilename, userData, 0644); err != nil {
48- logger.Errorf("failed to write user data: %v", err)
49- return "", err
50- }
51- return userDataFilename, nil
52-}
53-
54-func cloudInitUserData(machineConfig *cloudinit.MachineConfig) ([]byte, error) {
55- machineConfig.DataDir = "/var/lib/juju"
56- cloudConfig, err := cloudinit.New(machineConfig)
57- if err != nil {
58- return nil, err
59- }
60-
61- // Run apt-config to fetch proxy settings from host. If no proxy
62- // settings are configured, then we don't set up any proxy information
63- // on the container.
64- proxyConfig, err := utils.AptConfigProxy()
65- if err != nil {
66- return nil, err
67- }
68- if proxyConfig != "" {
69- var proxyLines []string
70- for _, line := range strings.Split(proxyConfig, "\n") {
71- line = strings.TrimSpace(line)
72- if len(line) > 0 {
73- if m := aptHTTPProxyRE.FindStringSubmatch(line); m != nil {
74- cloudConfig.SetAptProxy(m[1])
75- } else {
76- proxyLines = append(proxyLines, line)
77- }
78- }
79- }
80- if len(proxyLines) > 0 {
81- cloudConfig.AddFile(
82- "/etc/apt/apt.conf.d/99proxy-extra",
83- strings.Join(proxyLines, "\n"),
84- 0644)
85- }
86- }
87-
88- // Run ifconfig to get the addresses of the internal container at least
89- // logged in the host.
90- cloudConfig.AddRunCmd("ifconfig")
91-
92- data, err := cloudConfig.Render()
93- if err != nil {
94- return nil, err
95- }
96- return data, nil
97-}
98-
99 // uniqueDirectory returns "path/name" if that directory doesn't exist. If it
100 // does, the method starts appending .1, .2, etc until a unique name is found.
101 func uniqueDirectory(path, name string) (string, error) {
102
103=== added file 'container/userdata.go'
104--- container/userdata.go 1970-01-01 00:00:00 +0000
105+++ container/userdata.go 2013-11-12 00:35:51 +0000
106@@ -0,0 +1,81 @@
107+// Copyright 2013 Canonical Ltd.
108+// Licensed under the AGPLv3, see LICENCE file for details.
109+
110+package container
111+
112+import (
113+ "io/ioutil"
114+ "path/filepath"
115+ "regexp"
116+ "strings"
117+
118+ "launchpad.net/loggo"
119+
120+ "launchpad.net/juju-core/environs/cloudinit"
121+ "launchpad.net/juju-core/utils"
122+)
123+
124+var (
125+ logger = loggo.GetLogger("juju.container.lxc")
126+ aptHTTPProxyRE = regexp.MustCompile(`(?i)^Acquire::HTTP::Proxy\s+"([^"]+)";$`)
127+)
128+
129+func WriteUserData(machineConfig *cloudinit.MachineConfig, directory string) (string, error) {
130+ userData, err := cloudInitUserData(machineConfig)
131+ if err != nil {
132+ logger.Errorf("failed to create user data: %v", err)
133+ return "", err
134+ }
135+ userDataFilename := filepath.Join(directory, "cloud-init")
136+ if err := ioutil.WriteFile(userDataFilename, userData, 0644); err != nil {
137+ logger.Errorf("failed to write user data: %v", err)
138+ return "", err
139+ }
140+ return userDataFilename, nil
141+}
142+
143+func cloudInitUserData(machineConfig *cloudinit.MachineConfig) ([]byte, error) {
144+ // consider not having this line hardcoded...
145+ machineConfig.DataDir = "/var/lib/juju"
146+ cloudConfig, err := cloudinit.New(machineConfig)
147+ if err != nil {
148+ return nil, err
149+ }
150+
151+ // Run apt-config to fetch proxy settings from host. If no proxy
152+ // settings are configured, then we don't set up any proxy information
153+ // on the container.
154+ proxyConfig, err := utils.AptConfigProxy()
155+ if err != nil {
156+ return nil, err
157+ }
158+ if proxyConfig != "" {
159+ var proxyLines []string
160+ for _, line := range strings.Split(proxyConfig, "\n") {
161+ line = strings.TrimSpace(line)
162+ if len(line) > 0 {
163+ if m := aptHTTPProxyRE.FindStringSubmatch(line); m != nil {
164+ cloudConfig.SetAptProxy(m[1])
165+ } else {
166+ proxyLines = append(proxyLines, line)
167+ }
168+ }
169+ }
170+ if len(proxyLines) > 0 {
171+ cloudConfig.AddFile(
172+ "/etc/apt/apt.conf.d/99proxy-extra",
173+ strings.Join(proxyLines, "\n"),
174+ 0644)
175+ }
176+ }
177+
178+ // Run ifconfig to get the addresses of the internal container at least
179+ // logged in the host.
180+ cloudConfig.AddRunCmd("ifconfig")
181+
182+ data, err := cloudConfig.Render()
183+ if err != nil {
184+ return nil, err
185+ }
186+ return data, nil
187+}

Subscribers

People subscribed via source and target branches

to status/vote changes: