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
=== modified file 'charmhelpers/contrib/openstack/context.py'
--- charmhelpers/contrib/openstack/context.py 2014-01-08 12:11:11 +0000
+++ charmhelpers/contrib/openstack/context.py 2014-01-30 13:37:58 +0000
@@ -67,6 +67,43 @@
67 return True67 return True
6868
6969
70def config_flags_parser(config_flags):
71 if config_flags.find('==') >= 0:
72 log("config_flags is not in expected format (key=value)",
73 level=ERROR)
74 raise OSContextError
75 # strip the following from each value.
76 post_strippers = ' ,'
77 # we strip any leading/trailing '=' or ' ' from the string then
78 # split on '='.
79 split = config_flags.strip(' =').split('=')
80 limit = len(split)
81 flags = {}
82 for i in xrange(0, limit - 1):
83 current = split[i]
84 next = split[i + 1]
85 vindex = next.rfind(',')
86 if (i == limit - 2) or (vindex < 0):
87 value = next
88 else:
89 value = next[:vindex]
90
91 if i == 0:
92 key = current
93 else:
94 # if this not the first entry, expect an embedded key.
95 index = current.rfind(',')
96 if index < 0:
97 log("invalid config value(s) at index %s" % (i),
98 level=ERROR)
99 raise OSContextError
100 key = current[index + 1:]
101
102 # Add to collection.
103 flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
104 return flags
105
106
70class OSContextGenerator(object):107class OSContextGenerator(object):
71 interfaces = []108 interfaces = []
72109
@@ -430,6 +467,11 @@
430 elif self.plugin == 'nvp':467 elif self.plugin == 'nvp':
431 ctxt.update(self.nvp_ctxt())468 ctxt.update(self.nvp_ctxt())
432469
470 alchemy_flags = config('neutron-alchemy-flags')
471 if alchemy_flags:
472 flags = config_flags_parser(alchemy_flags)
473 ctxt['neutron_alchemy_flags'] = flags
474
433 self._save_flag_file()475 self._save_flag_file()
434 return ctxt476 return ctxt
435477
@@ -450,41 +492,7 @@
450 if not config_flags:492 if not config_flags:
451 return {}493 return {}
452494
453 if config_flags.find('==') >= 0:495 flags = config_flags_parser(config_flags)
454 log("config_flags is not in expected format (key=value)",
455 level=ERROR)
456 raise OSContextError
457
458 # strip the following from each value.
459 post_strippers = ' ,'
460 # we strip any leading/trailing '=' or ' ' from the string then
461 # split on '='.
462 split = config_flags.strip(' =').split('=')
463 limit = len(split)
464 flags = {}
465 for i in xrange(0, limit - 1):
466 current = split[i]
467 next = split[i + 1]
468 vindex = next.rfind(',')
469 if (i == limit - 2) or (vindex < 0):
470 value = next
471 else:
472 value = next[:vindex]
473
474 if i == 0:
475 key = current
476 else:
477 # if this not the first entry, expect an embedded key.
478 index = current.rfind(',')
479 if index < 0:
480 log("invalid config value(s) at index %s" % (i),
481 level=ERROR)
482 raise OSContextError
483 key = current[index + 1:]
484
485 # Add to collection.
486 flags[key.strip(post_strippers)] = value.rstrip(post_strippers)
487
488 return {'user_config_flags': flags}496 return {'user_config_flags': flags}
489497
490498

Subscribers

People subscribed via source and target branches