Merge lp:~smoser/maas-images/trunk.centos-curtin-passthrough into lp:maas-images

Proposed by Scott Moser
Status: Merged
Merged at revision: 377
Proposed branch: lp:~smoser/maas-images/trunk.centos-curtin-passthrough
Merge into: lp:maas-images
Diff against target: 160 lines (+103/-2)
2 files modified
curtin/centos6/curtin-hooks.py (+52/-1)
curtin/centos7/curtin-hooks.py (+51/-1)
To merge this branch: bzr merge lp:~smoser/maas-images/trunk.centos-curtin-passthrough
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+328246@code.launchpad.net

Description of the change

Add support to CentOS 6 and 7 for network config and cloudconfig.

This adds the ability for the CentOS curthooks to make use of
the 'centos_apply_network_config' function of new curtin version.

Also adds the ability to handle 'cloudconfig' entries in curtin config
dictionary. It does this by utilizing 'write_files' from curtin.futil.

It also adds a short term legacy-curtin fallback for older curtin
import paths.

To post a comment you must log in.
378. By Scott Moser

fix calling of write_files from handle_cloudconfig

Revision history for this message
Lee Trager (ltrager) wrote :

Thanks for helping with the Curtin hooks. I have two fixes below. If Curtin trunk lands the final names before this we can just use the final names and drop the backwards compatibility.

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

I think we'll plan to merge the curtin updates in https://code.launchpad.net/~smoser/curtin/trunk.renames-for-centos/+merge/328250
and then drop the FIXME sections of this, providing no compatibility for curtin at revno 511-513.

379. By Scott Moser

drop support for curtin at versions 511-513.

Curtin at revno 514 now has the renamed import paths.
This breaks support for maas images using a curtin at
revisions 511-513 by dropping the FIXME fallback import paths.

380. By Scott Moser

do not name the import error as it was anot used

Revision history for this message
Scott Moser (smoser) wrote :

https://code.launchpad.net/~smoser/curtin/trunk.renames-for-centos/+merge/328250
is merged now.
and here i've removed the support for those older curtin revnos (511-513).

Revision history for this message
Lee Trager (ltrager) wrote :

LGTM, thanks again for the help!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/centos6/curtin-hooks.py'
2--- curtin/centos6/curtin-hooks.py 2016-05-11 18:47:46 +0000
3+++ curtin/centos6/curtin-hooks.py 2017-08-01 15:59:28 +0000
4@@ -13,9 +13,28 @@
5
6 from curtin import (
7 block,
8+ config,
9 util,
10 )
11
12+try:
13+ from curtin import FEATURES as curtin_features
14+except ImportError:
15+ curtin_features = []
16+
17+write_files = None
18+try:
19+ from curtin.futil import write_files
20+except ImportError:
21+ pass
22+
23+centos_apply_network_config = None
24+try:
25+ if 'CENTOS_APPLY_NETWORK_CONFIG' in curtin_features:
26+ from curtin.commands.curthooks import centos_apply_network_config
27+except ImportError:
28+ pass
29+
30 """
31 CentOS 6
32
33@@ -309,6 +328,30 @@
34 })
35
36
37+def apply_networking(cfg, target, bootmac):
38+ if 'network' in cfg and centos_apply_network_config:
39+ centos_apply_network_config(cfg, target)
40+ return
41+
42+ if 'network' in cfg:
43+ sys.stderr.write("WARN: network configuration provided, but "
44+ "no support for applying. Using basic config.")
45+ write_network_config(target, bootmac)
46+
47+
48+def handle_cloudconfig(cfg, target):
49+ if not cfg.get('cloudconfig'):
50+ return
51+ if not write_files:
52+ sys.stderr.write(
53+ "WARN: Unable to handle 'cloudconfig' section in config."
54+ "No 'write_files' found from curtin.\n")
55+ return
56+
57+ base_dir = os.path.join(target, 'etc/cloud/cloud.cfg.d')
58+ write_files(cfg['cloudconfig'], base_dir)
59+
60+
61 def main():
62 state = util.load_command_environment()
63 target = state['target']
64@@ -335,7 +378,15 @@
65 grub_install(target, grub_root)
66
67 set_autorelabel(target)
68- write_network_config(target, bootmac)
69+
70+ if state.get('config'):
71+ cfg = config.load_config(state['config'])
72+ else:
73+ cfg = {}
74+
75+ handle_cloudconfig(cfg, target)
76+
77+ apply_networking(cfg, target, bootmac)
78
79
80 if __name__ == "__main__":
81
82=== modified file 'curtin/centos7/curtin-hooks.py'
83--- curtin/centos7/curtin-hooks.py 2017-05-08 00:04:25 +0000
84+++ curtin/centos7/curtin-hooks.py 2017-08-01 15:59:28 +0000
85@@ -13,9 +13,27 @@
86
87 from curtin import (
88 block,
89+ config,
90 util,
91 )
92
93+try:
94+ from curtin import FEATURES as curtin_features
95+except ImportError:
96+ curtin_features = []
97+
98+write_files = None
99+try:
100+ from curtin.futil import write_files
101+except ImportError:
102+ pass
103+
104+centos_apply_network_config = None
105+try:
106+ if 'CENTOS_APPLY_NETWORK_CONFIG' in curtin_features:
107+ from curtin.commands.curthooks import centos_apply_network_config
108+except ImportError:
109+ pass
110
111 """
112 CentOS 7
113@@ -299,6 +317,30 @@
114 })
115
116
117+def apply_networking(cfg, target, bootmac):
118+ if 'network' in cfg and centos_apply_network_config:
119+ centos_apply_network_config(cfg, target)
120+ return
121+
122+ if 'network' in cfg:
123+ sys.stderr.write("WARN: network configuration provided, but "
124+ "no support for applying. Using basic config.")
125+ write_network_config(target, bootmac)
126+
127+
128+def handle_cloudconfig(cfg, target):
129+ if not cfg.get('cloudconfig'):
130+ return
131+ if not write_files:
132+ sys.stderr.write(
133+ "WARN: Unable to handle 'cloudconfig' section in config."
134+ "No 'write_files' found from curtin.\n")
135+ return
136+
137+ base_dir = os.path.join(target, 'etc/cloud/cloud.cfg.d')
138+ write_files(cfg['cloudconfig'], base_dir)
139+
140+
141 def main():
142 state = util.load_command_environment()
143 target = state['target']
144@@ -330,7 +372,15 @@
145 grub2_install(target, dev)
146
147 set_autorelabel(target)
148- write_network_config(target, bootmac)
149+
150+ if state.get('config'):
151+ cfg = config.load_config(state['config'])
152+ else:
153+ cfg = {}
154+
155+ handle_cloudconfig(cfg, target)
156+
157+ apply_networking(cfg, target, bootmac)
158
159
160 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches