Merge lp:~hopem/charms/trusty/glance/fix-ssl-inject into lp:~openstack-charmers-archive/charms/trusty/glance/next

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 102
Proposed branch: lp:~hopem/charms/trusty/glance/fix-ssl-inject
Merge into: lp:~openstack-charmers-archive/charms/trusty/glance/next
Diff against target: 243 lines (+160/-2)
4 files modified
hooks/charmhelpers/contrib/openstack/context.py (+59/-1)
hooks/charmhelpers/contrib/openstack/neutron.py (+70/-0)
hooks/charmhelpers/core/hookenv.py (+26/-0)
hooks/charmhelpers/core/host.py (+5/-1)
To merge this branch: bzr merge lp:~hopem/charms/trusty/glance/fix-ssl-inject
Reviewer Review Type Date Requested Status
Billy Olsen Approve
Review via email: mp+253404@code.launchpad.net
To post a comment you must log in.
103. By Edward Hope-Morley

cleanup

Revision history for this message
Billy Olsen (billy-olsen) wrote :

LGTM. Deployments work fine with ssl inject for ha and non-ha.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/charmhelpers/contrib/openstack/context.py'
2--- hooks/charmhelpers/contrib/openstack/context.py 2015-03-13 12:58:26 +0000
3+++ hooks/charmhelpers/contrib/openstack/context.py 2015-03-18 18:35:49 +0000
4@@ -16,6 +16,7 @@
5
6 import json
7 import os
8+import re
9 import time
10 from base64 import b64decode
11 from subprocess import check_call
12@@ -48,6 +49,8 @@
13 from charmhelpers.core.sysctl import create as sysctl_create
14
15 from charmhelpers.core.host import (
16+ list_nics,
17+ get_nic_hwaddr,
18 mkdir,
19 write_file,
20 )
21@@ -65,12 +68,18 @@
22 from charmhelpers.contrib.openstack.neutron import (
23 neutron_plugin_attribute,
24 )
25+from charmhelpers.contrib.openstack.ip import (
26+ resolve_address,
27+ INTERNAL,
28+)
29 from charmhelpers.contrib.network.ip import (
30 get_address_in_network,
31+ get_ipv4_addr,
32 get_ipv6_addr,
33 get_netmask_for_address,
34 format_ipv6_addr,
35 is_address_in_network,
36+ is_bridge_member,
37 )
38 from charmhelpers.contrib.openstack.utils import get_host_ip
39
40@@ -727,7 +736,14 @@
41 'endpoints': [],
42 'ext_ports': []}
43
44- for cn in self.canonical_names():
45+ cns = self.canonical_names()
46+ if cns:
47+ for cn in cns:
48+ self.configure_cert(cn)
49+ else:
50+ # Expect cert/key provided in config (currently assumed that ca
51+ # uses ip for cn)
52+ cn = resolve_address(endpoint_type=INTERNAL)
53 self.configure_cert(cn)
54
55 addresses = self.get_network_addresses()
56@@ -883,6 +899,48 @@
57 return ctxt
58
59
60+class NeutronPortContext(OSContextGenerator):
61+ NIC_PREFIXES = ['eth', 'bond']
62+
63+ def resolve_ports(self, ports):
64+ """Resolve NICs not yet bound to bridge(s)
65+
66+ If hwaddress provided then returns resolved hwaddress otherwise NIC.
67+ """
68+ if not ports:
69+ return None
70+
71+ hwaddr_to_nic = {}
72+ hwaddr_to_ip = {}
73+ for nic in list_nics(self.NIC_PREFIXES):
74+ hwaddr = get_nic_hwaddr(nic)
75+ hwaddr_to_nic[hwaddr] = nic
76+ addresses = get_ipv4_addr(nic, fatal=False)
77+ addresses += get_ipv6_addr(iface=nic, fatal=False)
78+ hwaddr_to_ip[hwaddr] = addresses
79+
80+ resolved = []
81+ mac_regex = re.compile(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', re.I)
82+ for entry in ports:
83+ if re.match(mac_regex, entry):
84+ # NIC is in known NICs and does NOT hace an IP address
85+ if entry in hwaddr_to_nic and not hwaddr_to_ip[entry]:
86+ # If the nic is part of a bridge then don't use it
87+ if is_bridge_member(hwaddr_to_nic[entry]):
88+ continue
89+
90+ # Entry is a MAC address for a valid interface that doesn't
91+ # have an IP address assigned yet.
92+ resolved.append(hwaddr_to_nic[entry])
93+ else:
94+ # If the passed entry is not a MAC address, assume it's a valid
95+ # interface, and that the user put it there on purpose (we can
96+ # trust it to be the real external network).
97+ resolved.append(entry)
98+
99+ return resolved
100+
101+
102 class OSConfigFlagContext(OSContextGenerator):
103 """Provides support for user-defined config flags.
104
105
106=== modified file 'hooks/charmhelpers/contrib/openstack/neutron.py'
107--- hooks/charmhelpers/contrib/openstack/neutron.py 2015-01-26 09:45:23 +0000
108+++ hooks/charmhelpers/contrib/openstack/neutron.py 2015-03-18 18:35:49 +0000
109@@ -16,6 +16,7 @@
110
111 # Various utilies for dealing with Neutron and the renaming from Quantum.
112
113+import six
114 from subprocess import check_output
115
116 from charmhelpers.core.hookenv import (
117@@ -237,3 +238,72 @@
118 else:
119 # ensure accurate naming for all releases post-H
120 return 'neutron'
121+
122+
123+def parse_mappings(mappings):
124+ parsed = {}
125+ if mappings:
126+ mappings = mappings.split(' ')
127+ for m in mappings:
128+ p = m.partition(':')
129+ if p[1] == ':':
130+ parsed[p[0].strip()] = p[2].strip()
131+
132+ return parsed
133+
134+
135+def parse_bridge_mappings(mappings):
136+ """Parse bridge mappings.
137+
138+ Mappings must be a space-delimited list of provider:bridge mappings.
139+
140+ Returns dict of the form {provider:bridge}.
141+ """
142+ return parse_mappings(mappings)
143+
144+
145+def parse_data_port_mappings(mappings, default_bridge='br-data'):
146+ """Parse data port mappings.
147+
148+ Mappings must be a space-delimited list of bridge:port mappings.
149+
150+ Returns dict of the form {bridge:port}.
151+ """
152+ _mappings = parse_mappings(mappings)
153+ if not _mappings:
154+ if not mappings:
155+ return {}
156+
157+ # For backwards-compatibility we need to support port-only provided in
158+ # config.
159+ _mappings = {default_bridge: mappings.split(' ')[0]}
160+
161+ bridges = _mappings.keys()
162+ ports = _mappings.values()
163+ if len(set(bridges)) != len(bridges):
164+ raise Exception("It is not allowed to have more than one port "
165+ "configured on the same bridge")
166+
167+ if len(set(ports)) != len(ports):
168+ raise Exception("It is not allowed to have the same port configured "
169+ "on more than one bridge")
170+
171+ return _mappings
172+
173+
174+def parse_vlan_range_mappings(mappings):
175+ """Parse vlan range mappings.
176+
177+ Mappings must be a space-delimited list of provider:start:end mappings.
178+
179+ Returns dict of the form {provider: (start, end)}.
180+ """
181+ _mappings = parse_mappings(mappings)
182+ if not _mappings:
183+ return {}
184+
185+ mappings = {}
186+ for p, r in six.iteritems(_mappings):
187+ mappings[p] = tuple(r.split(':'))
188+
189+ return mappings
190
191=== modified file 'hooks/charmhelpers/core/hookenv.py'
192--- hooks/charmhelpers/core/hookenv.py 2015-01-26 09:45:23 +0000
193+++ hooks/charmhelpers/core/hookenv.py 2015-03-18 18:35:49 +0000
194@@ -566,3 +566,29 @@
195 def charm_dir():
196 """Return the root directory of the current charm"""
197 return os.environ.get('CHARM_DIR')
198+
199+
200+@cached
201+def action_get(key=None):
202+ """Gets the value of an action parameter, or all key/value param pairs"""
203+ cmd = ['action-get']
204+ if key is not None:
205+ cmd.append(key)
206+ cmd.append('--format=json')
207+ action_data = json.loads(subprocess.check_output(cmd).decode('UTF-8'))
208+ return action_data
209+
210+
211+def action_set(values):
212+ """Sets the values to be returned after the action finishes"""
213+ cmd = ['action-set']
214+ for k, v in list(values.items()):
215+ cmd.append('{}={}'.format(k, v))
216+ subprocess.check_call(cmd)
217+
218+
219+def action_fail(message):
220+ """Sets the action status to failed and sets the error message.
221+
222+ The results set by action_set are preserved."""
223+ subprocess.check_call(['action-fail', message])
224
225=== modified file 'hooks/charmhelpers/core/host.py'
226--- hooks/charmhelpers/core/host.py 2015-03-13 12:58:26 +0000
227+++ hooks/charmhelpers/core/host.py 2015-03-18 18:35:49 +0000
228@@ -339,12 +339,16 @@
229 def pwgen(length=None):
230 """Generate a random pasword."""
231 if length is None:
232+ # A random length is ok to use a weak PRNG
233 length = random.choice(range(35, 45))
234 alphanumeric_chars = [
235 l for l in (string.ascii_letters + string.digits)
236 if l not in 'l0QD1vAEIOUaeiou']
237+ # Use a crypto-friendly PRNG (e.g. /dev/urandom) for making the
238+ # actual password
239+ random_generator = random.SystemRandom()
240 random_chars = [
241- random.choice(alphanumeric_chars) for _ in range(length)]
242+ random_generator.choice(alphanumeric_chars) for _ in range(length)]
243 return(''.join(random_chars))
244
245

Subscribers

People subscribed via source and target branches