Merge lp:~ivoks/charm-helpers/neutron-alchemy into lp:charm-helpers

Proposed by Ante Karamatić
Status: Merged
Merged at revision: 114
Proposed branch: lp:~ivoks/charm-helpers/neutron-alchemy
Merge into: lp:charm-helpers
Diff against target: 100 lines (+43/-35)
1 file modified
charmhelpers/contrib/openstack/context.py (+43/-35)
To merge this branch: bzr merge lp:~ivoks/charm-helpers/neutron-alchemy
Reviewer Review Type Date Requested Status
Marco Ceppi Approve
OpenStack Charmers Pending
charmers Pending
Review via email: mp+203962@code.launchpad.net

Description of the change

Adds support for customizing Neutron/Quantum alchemy variables

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/openstack/context.py'
2--- charmhelpers/contrib/openstack/context.py 2014-01-08 12:11:11 +0000
3+++ charmhelpers/contrib/openstack/context.py 2014-01-30 13:37:58 +0000
4@@ -67,6 +67,43 @@
5 return True
6
7
8+def config_flags_parser(config_flags):
9+ if config_flags.find('==') >= 0:
10+ log("config_flags is not in expected format (key=value)",
11+ level=ERROR)
12+ raise OSContextError
13+ # strip the following from each value.
14+ post_strippers = ' ,'
15+ # we strip any leading/trailing '=' or ' ' from the string then
16+ # split on '='.
17+ split = config_flags.strip(' =').split('=')
18+ limit = len(split)
19+ flags = {}
20+ for i in xrange(0, limit - 1):
21+ current = split[i]
22+ next = split[i + 1]
23+ vindex = next.rfind(',')
24+ if (i == limit - 2) or (vindex < 0):
25+ value = next
26+ else:
27+ value = next[:vindex]
28+
29+ if i == 0:
30+ key = current
31+ else:
32+ # if this not the first entry, expect an embedded key.
33+ index = current.rfind(',')
34+ if index < 0:
35+ log("invalid config value(s) at index %s" % (i),
36+ level=ERROR)
37+ raise OSContextError
38+ key = current[index + 1:]
39+
40+ # Add to collection.
41+ flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
42+ return flags
43+
44+
45 class OSContextGenerator(object):
46 interfaces = []
47
48@@ -430,6 +467,11 @@
49 elif self.plugin == 'nvp':
50 ctxt.update(self.nvp_ctxt())
51
52+ alchemy_flags = config('neutron-alchemy-flags')
53+ if alchemy_flags:
54+ flags = config_flags_parser(alchemy_flags)
55+ ctxt['neutron_alchemy_flags'] = flags
56+
57 self._save_flag_file()
58 return ctxt
59
60@@ -450,41 +492,7 @@
61 if not config_flags:
62 return {}
63
64- if config_flags.find('==') >= 0:
65- log("config_flags is not in expected format (key=value)",
66- level=ERROR)
67- raise OSContextError
68-
69- # strip the following from each value.
70- post_strippers = ' ,'
71- # we strip any leading/trailing '=' or ' ' from the string then
72- # split on '='.
73- split = config_flags.strip(' =').split('=')
74- limit = len(split)
75- flags = {}
76- for i in xrange(0, limit - 1):
77- current = split[i]
78- next = split[i + 1]
79- vindex = next.rfind(',')
80- if (i == limit - 2) or (vindex < 0):
81- value = next
82- else:
83- value = next[:vindex]
84-
85- if i == 0:
86- key = current
87- else:
88- # if this not the first entry, expect an embedded key.
89- index = current.rfind(',')
90- if index < 0:
91- log("invalid config value(s) at index %s" % (i),
92- level=ERROR)
93- raise OSContextError
94- key = current[index + 1:]
95-
96- # Add to collection.
97- flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
98-
99+ flags = config_flags_parser(config_flags)
100 return {'user_config_flags': flags}
101
102

Subscribers

People subscribed via source and target branches