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
=== modified file 'README.md'
--- README.md 2015-04-30 12:09:23 +0000
+++ README.md 2015-10-12 08:18:56 +0000
@@ -119,3 +119,33 @@
119 - {name: nova,119 - {name: nova,
120 repository: 'git://github.com/openstack/nova',120 repository: 'git://github.com/openstack/nova',
121 branch: master}121 branch: master}
122
123Network Interfaces
124=====================
125
126The minimum network-interfaces parameters needed to configure
127additional interfaces are:
128
129 network-interfaces: include-file://network-interfaces.yaml
130
131 network-interfaces.yaml
132 {interfaces:[
133 {interface-label: ethN,
134 interface-mode: dhcp}]}
135
136An example of configuring multiple interfaces might look like:
137
138 network-interfaces: include-file://network-interfaces.yaml
139
140 network-interfaces.yaml
141 {interfaces:[
142 {interface-label: eth1,
143 interface-mode: static,
144 interface-address: 192.168.1.10,
145 interface-netmask: 255.255.255.0},
146 {interface-label: eth2,
147 interface-mode: dhcp},
148 {interface-label: eth3,
149 interface-mode: manual},
150 {interface-label: br-vlan,
151 interface-mode: manual}]}
122152
=== modified file 'config.yaml'
--- config.yaml 2015-10-09 15:02:40 +0000
+++ config.yaml 2015-10-12 08:18:56 +0000
@@ -291,3 +291,18 @@
291 wait for you to execute the openstack-upgrade action for this charm on291 wait for you to execute the openstack-upgrade action for this charm on
292 each unit. If False it will revert to existing behavior of upgrading292 each unit. If False it will revert to existing behavior of upgrading
293 all units on config change.293 all units on config change.
294 network-interfaces:
295 type: string
296 default:
297 description: |
298 String list of network interface dicts comprised of at least an
299 'interface-label', and 'interface-mode'. For interfaces specifying
300 "inerface-mode: static", a minimum of 'interface-address' and
301 'interface-netmask' must also be supplied. Additional optional
302 parameters for 'static' interfaces include:
303 * interface-broadcast
304 For more details see README.md.
305 up-network-interfaces:
306 type: boolean
307 default: False
308 description: Bring up user defined network interfaces.
294309
=== modified file 'hooks/nova_compute_hooks.py'
--- hooks/nova_compute_hooks.py 2015-10-09 15:02:40 +0000
+++ hooks/nova_compute_hooks.py 2015-10-12 08:18:56 +0000
@@ -70,6 +70,7 @@
70 install_hugepages,70 install_hugepages,
71 REQUIRED_INTERFACES,71 REQUIRED_INTERFACES,
72 check_optional_relations,72 check_optional_relations,
73 gen_interfaces,
73)74)
7475
75from charmhelpers.contrib.network.ip import (76from charmhelpers.contrib.network.ip import (
@@ -103,6 +104,9 @@
103104
104 status_set('maintenance', 'Git install')105 status_set('maintenance', 'Git install')
105 git_install(config('openstack-origin-git'))106 git_install(config('openstack-origin-git'))
107 if config('network-interfaces'):
108 status_set('maintenance', 'Configuring network interfaces')
109 gen_interfaces(config('network-interfaces'))
106110
107111
108@hooks.hook('config-changed')112@hooks.hook('config-changed')
109113
=== modified file 'hooks/nova_compute_utils.py'
--- hooks/nova_compute_utils.py 2015-10-06 16:58:22 +0000
+++ hooks/nova_compute_utils.py 2015-10-12 08:18:56 +0000
@@ -2,6 +2,7 @@
2import shutil2import shutil
3import pwd3import pwd
4import subprocess4import subprocess
5import yaml
56
6from base64 import b64decode7from base64 import b64decode
7from copy import deepcopy8from copy import deepcopy
@@ -235,6 +236,8 @@
235 },236 },
236}237}
237238
239DEFAULT_NETWORK_IFACE_CONF = '/etc/network/interfaces'
240NETWORK_IFACE_CONF_DIR = '/etc/network/interfaces.d'
238241
239# Maps virt-type config to a compute package(s).242# Maps virt-type config to a compute package(s).
240VIRT_TYPES = {243VIRT_TYPES = {
@@ -851,3 +854,52 @@
851 return status_get()854 return status_get()
852 else:855 else:
853 return 'unknown', 'No optional relations'856 return 'unknown', 'No optional relations'
857
858
859def gen_interfaces(interfaces):
860 """Generate interface files and replace stale stanzas in
861 /etc/network/interfaces with sourcing of new ethN.cfg file.
862 """
863 ifaces = yaml.load(interfaces)['interfaces']
864 iface_source_stanza_all = 'source /etc/network/interfaces.d/*.cfg'
865 for iface in ifaces:
866 net_iface_context = {}
867 iface_conf = os.path.join(NETWORK_IFACE_CONF_DIR,
868 ('%s.cfg' % iface['interface-label']))
869 iface_source_stanza_new = 'source %s' % iface_conf
870 iface_dhcp_stanza_stale = ('iface %s inet dhcp' %
871 iface['interface-label'])
872
873 # Dynamically generate context depending on interface mode
874 if iface['interface-mode'] in ['dhcp', 'manual']:
875 net_iface_context = {
876 'interface_label': iface['interface-label'],
877 'interface_mode': iface['interface-mode'],
878 }
879 else:
880 for key in iface.keys():
881 net_iface_context[key.replace('-','_')] = iface[key]
882
883 with open(DEFAULT_NETWORK_IFACE_CONF, 'r') as iface_file:
884 filedata = iface_file.read()
885
886 # Check for existing stanzas matching the current interface.
887 # There are two possibilities that could exist for stanzas of
888 # a non-primary interface of a juju deployed node depending on
889 # the provider used. This check ensures affinity for each
890 # stanza <-> interface, so as we don't end up with multiple
891 # definitions.
892 if iface_dhcp_stanza_stale in filedata:
893 filedata = filedata.replace(iface_dhcp_stanza_stale,
894 iface_source_stanza_new)
895 with open(DEFAULT_NETWORK_IFACE_CONF, 'w') as iface_file:
896 iface_file.write(filedata)
897 elif not iface_source_stanza_all in filedata:
898 with open(DEFAULT_NETWORK_IFACE_CONF, 'a') as iface_file:
899 iface_file.write(iface_source_stanza_new)
900
901 # Render iface config file, bring up network interface
902 # if up-network-interfaces == True
903 render('ethN', iface_conf, net_iface_context, perms=0o644)
904 if config('up-network-interfaces'):
905 check_call(['ifconfig', iface['interface-label'], 'up'])
854906
=== added file 'templates/ethN'
--- templates/ethN 1970-01-01 00:00:00 +0000
+++ templates/ethN 2015-10-12 08:18:56 +0000
@@ -0,0 +1,13 @@
1auto {{ interface_label }}
2iface {{ interface_label }} inet {{ interface_mode }}
3{% if interface_mode == 'static' -%}
4address {{ interface_address }}
5netmask {{ interface_netmask }}
6{% if interface_broadcast -%}
7broadcast {{ interface_broadcast }}
8{% endif -%}
9{% endif -%}
10up ip l set {{ interface_label }} up
11down ip l set {{ interface_label }} down
12post-up ethtool -K {{ interface_label }} gso off gro off || true
13

Subscribers

People subscribed via source and target branches