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: 170 lines (+110/-0)
5 files modified
README.md (+30/-0)
config.yaml (+15/-0)
hooks/nova_compute_hooks.py (+4/-0)
hooks/nova_compute_utils.py (+48/-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
OpenStack Charmers Pending
Antonio Rosales Pending
James Page Pending
Liam Young Pending
Review via email: mp+274149@code.launchpad.net

This proposal supersedes a proposal from 2015-10-12.

Commit message

Adds ability to configure user defined network interfaces.

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.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal

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

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

charm_lint_check #11715 nova-compute-next for jamesbeedy mp274149
    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/12763574/
Build: http://10.245.162.77:8080/job/charm_lint_check/11715/

189. By james beedy

Insert whitespace after ','

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

charm_unit_test #10898 nova-compute-next for jamesbeedy mp274149
    UNIT OK: passed

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

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 : Posted in a previous version of this proposal

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/

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

charm_amulet_test #7282 nova-compute-next for jamesbeedy mp274149
    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/12764515/
Build: http://10.245.162.77:8080/job/charm_amulet_test/7282/

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 14:36:49 +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 14:36:49 +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 14:36:49 +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 14:36:49 +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,48 @@
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+ # Dynamically generate context depending on interface mode
124+ if iface['interface-mode'] in ['dhcp', 'manual']:
125+ net_iface_context = {
126+ 'interface_label': iface['interface-label'],
127+ 'interface_mode': iface['interface-mode'],
128+ }
129+ else:
130+ for key in iface.keys():
131+ net_iface_context[key.replace('-', '_')] = iface[key]
132+ with open(DEFAULT_NETWORK_IFACE_CONF, 'r') as iface_file:
133+ filedata = iface_file.read()
134+ # Check for existing stanzas matching the current interface.
135+ # There are two possibilities that could exist for stanzas of
136+ # a non-primary interface of a juju deployed node depending on
137+ # the provider used. This check ensures affinity for each
138+ # stanza <-> interface, so as we don't end up with multiple
139+ # definitions.
140+ if iface_dhcp_stanza_stale in filedata:
141+ filedata = filedata.replace(iface_dhcp_stanza_stale,
142+ iface_source_stanza_new)
143+ with open(DEFAULT_NETWORK_IFACE_CONF, 'w') as iface_file:
144+ iface_file.write(filedata)
145+ elif iface_source_stanza_all not in filedata:
146+ with open(DEFAULT_NETWORK_IFACE_CONF, 'a') as iface_file:
147+ iface_file.write(iface_source_stanza_new)
148+ # Render iface config file, bring up network interface
149+ # if up-network-interfaces == True
150+ render('ethN', iface_conf, net_iface_context, perms=0o644)
151+ if config('up-network-interfaces'):
152+ check_call(['ifconfig', iface['interface-label'], 'up'])
153
154=== added file 'templates/ethN'
155--- templates/ethN 1970-01-01 00:00:00 +0000
156+++ templates/ethN 2015-10-12 14:36:49 +0000
157@@ -0,0 +1,13 @@
158+auto {{ interface_label }}
159+iface {{ interface_label }} inet {{ interface_mode }}
160+{% if interface_mode == 'static' -%}
161+address {{ interface_address }}
162+netmask {{ interface_netmask }}
163+{% if interface_broadcast -%}
164+broadcast {{ interface_broadcast }}
165+{% endif -%}
166+{% endif -%}
167+up ip l set {{ interface_label }} up
168+down ip l set {{ interface_label }} down
169+post-up ethtool -K {{ interface_label }} gso off gro off || true
170+

Subscribers

People subscribed via source and target branches