Merge lp:~jamesbeedy/charms/trusty/nova-compute/add-iface-support into lp:~openstack-charmers-archive/charms/trusty/nova-compute/next

Proposed by james beedy
Status: Superseded
Proposed branch: lp:~jamesbeedy/charms/trusty/nova-compute/add-iface-support
Merge into: lp:~openstack-charmers-archive/charms/trusty/nova-compute/next
Diff against target: 174 lines (+114/-0)
5 files modified
README.md (+30/-0)
config.yaml (+15/-0)
hooks/nova_compute_hooks.py (+4/-0)
hooks/nova_compute_utils.py (+52/-0)
templates/ethN (+13/-0)
To merge this branch: bzr merge lp:~jamesbeedy/charms/trusty/nova-compute/add-iface-support
Reviewer Review Type Date Requested Status
James Page Pending
OpenStack Charmers Pending
Antonio Rosales Pending
Liam Young Pending
Review via email: mp+274104@code.launchpad.net

This proposal has been superseded by a proposal from 2015-10-12.

Description of the change

Adds ability to configure user defined network interfaces.

Added template for network interface config file in templates called ethN.
Added gen_interfaces() func to nova_compute_utils.py, called from
install hook.
Added import of yaml package to nova_compute_utils.py to facilitate
the parsing of string -> dict in gen_interfaces.
Added 'network-interfaces' and 'up-network-interfaces' parameters to
config.yaml.
Modified README.md to reflect docs on new params.

Partially fixes bug #1505064

To post a comment you must log in.
176. By james beedy

Fix typo.

177. By james beedy

Minor fixes

Removed unneeded double quotes in config.yaml.
Fixed block level indentation in README.md.

178. By james beedy

Corrected indentation.

Removed extra space from beginning of line.

179. By james beedy

Fix variable name.

Modified 'replace_me' to reflect correct name 'replace_iface_stanza'.

180. By james beedy

Fixed typo in variable name.

181. By james beedy

Refactored variable names, fixed spacing, refactored interface stanza
logic to handle the only possible cases.

Removed unneeded configs options from network-interfaces
possible parameters.

182. By james beedy

Modified templates/ethN to reflect available params.

Removed interface-gateway, interface-nameservers, and
interface-dns-search from available params.

183. By james beedy

Modified comment to be more explicit in gen_interfaces.

184. By james beedy

Fix typo

185. By james beedy

Fix line length.

186. By james beedy

Repositioned iface_source_stanza_all outside of for loop.

187. By james beedy

Clearify gen_interfaces() description comment.

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #11712 nova-compute-next for jamesbeedy mp274104
    LINT FAIL: lint-test failed

LINT Results (max last 2 lines):
make: *** [lint] Error 1
ERROR:root:Make target returned non-zero.

Full lint test output: http://paste.ubuntu.com/12763471/
Build: http://10.245.162.77:8080/job/charm_lint_check/11712/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #10895 nova-compute-next for jamesbeedy mp274104
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/10895/

188. By james beedy

Fix python negation syntax

189. By james beedy

Insert whitespace after ','

190. By james beedy

Removed trailing blank line in ethN

191. By james beedy

Removed trailing whitespace

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #7279 nova-compute-next for jamesbeedy mp274104
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12764369/
Build: http://10.245.162.77:8080/job/charm_amulet_test/7279/

Unmerged revisions

191. By james beedy

Removed trailing whitespace

190. By james beedy

Removed trailing blank line in ethN

189. By james beedy

Insert whitespace after ','

188. By james beedy

Fix python negation syntax

187. By james beedy

Clearify gen_interfaces() description comment.

186. By james beedy

Repositioned iface_source_stanza_all outside of for loop.

185. By james beedy

Fix line length.

184. By james beedy

Fix typo

183. By james beedy

Modified comment to be more explicit in gen_interfaces.

182. By james beedy

Modified templates/ethN to reflect available params.

Removed interface-gateway, interface-nameservers, and
interface-dns-search from available params.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2015-04-30 12:09:23 +0000
3+++ README.md 2015-10-12 08:18:56 +0000
4@@ -119,3 +119,33 @@
5 - {name: nova,
6 repository: 'git://github.com/openstack/nova',
7 branch: master}
8+
9+Network Interfaces
10+=====================
11+
12+The minimum network-interfaces parameters needed to configure
13+additional interfaces are:
14+
15+ network-interfaces: include-file://network-interfaces.yaml
16+
17+ network-interfaces.yaml
18+ {interfaces:[
19+ {interface-label: ethN,
20+ interface-mode: dhcp}]}
21+
22+An example of configuring multiple interfaces might look like:
23+
24+ network-interfaces: include-file://network-interfaces.yaml
25+
26+ network-interfaces.yaml
27+ {interfaces:[
28+ {interface-label: eth1,
29+ interface-mode: static,
30+ interface-address: 192.168.1.10,
31+ interface-netmask: 255.255.255.0},
32+ {interface-label: eth2,
33+ interface-mode: dhcp},
34+ {interface-label: eth3,
35+ interface-mode: manual},
36+ {interface-label: br-vlan,
37+ interface-mode: manual}]}
38
39=== modified file 'config.yaml'
40--- config.yaml 2015-10-09 15:02:40 +0000
41+++ config.yaml 2015-10-12 08:18:56 +0000
42@@ -291,3 +291,18 @@
43 wait for you to execute the openstack-upgrade action for this charm on
44 each unit. If False it will revert to existing behavior of upgrading
45 all units on config change.
46+ network-interfaces:
47+ type: string
48+ default:
49+ description: |
50+ String list of network interface dicts comprised of at least an
51+ 'interface-label', and 'interface-mode'. For interfaces specifying
52+ "inerface-mode: static", a minimum of 'interface-address' and
53+ 'interface-netmask' must also be supplied. Additional optional
54+ parameters for 'static' interfaces include:
55+ * interface-broadcast
56+ For more details see README.md.
57+ up-network-interfaces:
58+ type: boolean
59+ default: False
60+ description: Bring up user defined network interfaces.
61
62=== modified file 'hooks/nova_compute_hooks.py'
63--- hooks/nova_compute_hooks.py 2015-10-09 15:02:40 +0000
64+++ hooks/nova_compute_hooks.py 2015-10-12 08:18:56 +0000
65@@ -70,6 +70,7 @@
66 install_hugepages,
67 REQUIRED_INTERFACES,
68 check_optional_relations,
69+ gen_interfaces,
70 )
71
72 from charmhelpers.contrib.network.ip import (
73@@ -103,6 +104,9 @@
74
75 status_set('maintenance', 'Git install')
76 git_install(config('openstack-origin-git'))
77+ if config('network-interfaces'):
78+ status_set('maintenance', 'Configuring network interfaces')
79+ gen_interfaces(config('network-interfaces'))
80
81
82 @hooks.hook('config-changed')
83
84=== modified file 'hooks/nova_compute_utils.py'
85--- hooks/nova_compute_utils.py 2015-10-06 16:58:22 +0000
86+++ hooks/nova_compute_utils.py 2015-10-12 08:18:56 +0000
87@@ -2,6 +2,7 @@
88 import shutil
89 import pwd
90 import subprocess
91+import yaml
92
93 from base64 import b64decode
94 from copy import deepcopy
95@@ -235,6 +236,8 @@
96 },
97 }
98
99+DEFAULT_NETWORK_IFACE_CONF = '/etc/network/interfaces'
100+NETWORK_IFACE_CONF_DIR = '/etc/network/interfaces.d'
101
102 # Maps virt-type config to a compute package(s).
103 VIRT_TYPES = {
104@@ -851,3 +854,52 @@
105 return status_get()
106 else:
107 return 'unknown', 'No optional relations'
108+
109+
110+def gen_interfaces(interfaces):
111+ """Generate interface files and replace stale stanzas in
112+ /etc/network/interfaces with sourcing of new ethN.cfg file.
113+ """
114+ ifaces = yaml.load(interfaces)['interfaces']
115+ iface_source_stanza_all = 'source /etc/network/interfaces.d/*.cfg'
116+ for iface in ifaces:
117+ net_iface_context = {}
118+ iface_conf = os.path.join(NETWORK_IFACE_CONF_DIR,
119+ ('%s.cfg' % iface['interface-label']))
120+ iface_source_stanza_new = 'source %s' % iface_conf
121+ iface_dhcp_stanza_stale = ('iface %s inet dhcp' %
122+ iface['interface-label'])
123+
124+ # Dynamically generate context depending on interface mode
125+ if iface['interface-mode'] in ['dhcp', 'manual']:
126+ net_iface_context = {
127+ 'interface_label': iface['interface-label'],
128+ 'interface_mode': iface['interface-mode'],
129+ }
130+ else:
131+ for key in iface.keys():
132+ net_iface_context[key.replace('-','_')] = iface[key]
133+
134+ with open(DEFAULT_NETWORK_IFACE_CONF, 'r') as iface_file:
135+ filedata = iface_file.read()
136+
137+ # Check for existing stanzas matching the current interface.
138+ # There are two possibilities that could exist for stanzas of
139+ # a non-primary interface of a juju deployed node depending on
140+ # the provider used. This check ensures affinity for each
141+ # stanza <-> interface, so as we don't end up with multiple
142+ # definitions.
143+ if iface_dhcp_stanza_stale in filedata:
144+ filedata = filedata.replace(iface_dhcp_stanza_stale,
145+ iface_source_stanza_new)
146+ with open(DEFAULT_NETWORK_IFACE_CONF, 'w') as iface_file:
147+ iface_file.write(filedata)
148+ elif not iface_source_stanza_all in filedata:
149+ with open(DEFAULT_NETWORK_IFACE_CONF, 'a') as iface_file:
150+ iface_file.write(iface_source_stanza_new)
151+
152+ # Render iface config file, bring up network interface
153+ # if up-network-interfaces == True
154+ render('ethN', iface_conf, net_iface_context, perms=0o644)
155+ if config('up-network-interfaces'):
156+ check_call(['ifconfig', iface['interface-label'], 'up'])
157
158=== added file 'templates/ethN'
159--- templates/ethN 1970-01-01 00:00:00 +0000
160+++ templates/ethN 2015-10-12 08:18:56 +0000
161@@ -0,0 +1,13 @@
162+auto {{ interface_label }}
163+iface {{ interface_label }} inet {{ interface_mode }}
164+{% if interface_mode == 'static' -%}
165+address {{ interface_address }}
166+netmask {{ interface_netmask }}
167+{% if interface_broadcast -%}
168+broadcast {{ interface_broadcast }}
169+{% endif -%}
170+{% endif -%}
171+up ip l set {{ interface_label }} up
172+down ip l set {{ interface_label }} down
173+post-up ethtool -K {{ interface_label }} gso off gro off || true
174+

Subscribers

People subscribed via source and target branches