Commit bc69ad81 by Toshio Kuratomi

Rename munge methods to preprocess_data.

Remove the call to preprocess_loop data from playbook_include as
includes can't be used with loops.
parent 6ba24e9f
...@@ -94,11 +94,11 @@ class Base: ...@@ -94,11 +94,11 @@ class Base:
setattr(Base, name, property(getter, setter, deleter)) setattr(Base, name, property(getter, setter, deleter))
setattr(self, name, value.default) setattr(self, name, value.default)
def munge(self, ds): def preprocess_data(self, ds):
''' infrequently used method to do some pre-processing of legacy terms ''' ''' infrequently used method to do some pre-processing of legacy terms '''
for base_class in self.__class__.mro(): for base_class in self.__class__.mro():
method = getattr(self, "_munge_%s" % base_class.__name__.lower(), None) method = getattr(self, "_preprocess_data_%s" % base_class.__name__.lower(), None)
if method: if method:
return method(ds) return method(ds)
return ds return ds
...@@ -121,10 +121,10 @@ class Base: ...@@ -121,10 +121,10 @@ class Base:
if isinstance(ds, string_types) or isinstance(ds, FileIO): if isinstance(ds, string_types) or isinstance(ds, FileIO):
ds = self._loader.load(ds) ds = self._loader.load(ds)
# call the munge() function to massage the data into something # call the preprocess_data() function to massage the data into
# we can more easily parse, and then call the validation function # something we can more easily parse, and then call the validation
# on it to ensure there are no incorrect key values # function on it to ensure there are no incorrect key values
ds = self.munge(ds) ds = self.preprocess_data(ds)
self._validate_attributes(ds) self._validate_attributes(ds)
# Walk all attributes in the class. # Walk all attributes in the class.
......
...@@ -51,7 +51,13 @@ class Become: ...@@ -51,7 +51,13 @@ class Become:
elif has_sudo and has_su: elif has_sudo and has_su:
raise errors.AnsibleParserError('sudo params ("sudo", "sudo_user") and su params ("su", "su_user") cannot be used together') raise errors.AnsibleParserError('sudo params ("sudo", "sudo_user") and su params ("su", "su_user") cannot be used together')
def _munge_become(self, ds): def _preprocess_data_become(self, ds):
"""Preprocess the playbook data for become attributes
This is called from the Base object's preprocess_data() method which
in turn is called pretty much anytime any sort of playbook object
(plays, tasks, blocks, etc) are created.
"""
self._detect_privilege_escalation_conflict(ds) self._detect_privilege_escalation_conflict(ds)
......
...@@ -66,7 +66,7 @@ class Block(Base, Become, Conditional, Taggable): ...@@ -66,7 +66,7 @@ class Block(Base, Become, Conditional, Taggable):
b = Block(parent_block=parent_block, role=role, task_include=task_include, use_handlers=use_handlers) b = Block(parent_block=parent_block, role=role, task_include=task_include, use_handlers=use_handlers)
return b.load_data(data, variable_manager=variable_manager, loader=loader) return b.load_data(data, variable_manager=variable_manager, loader=loader)
def munge(self, ds): def preprocess_data(self, ds):
''' '''
If a simple task is given, an implicit block for that single task If a simple task is given, an implicit block for that single task
is created, which goes in the main portion of the block is created, which goes in the main portion of the block
...@@ -80,11 +80,11 @@ class Block(Base, Become, Conditional, Taggable): ...@@ -80,11 +80,11 @@ class Block(Base, Become, Conditional, Taggable):
if not is_block: if not is_block:
if isinstance(ds, list): if isinstance(ds, list):
return super(Block, self).munge(dict(block=ds)) return super(Block, self).preprocess_data(dict(block=ds))
else: else:
return super(Block, self).munge(dict(block=[ds])) return super(Block, self).preprocess_data(dict(block=[ds]))
return super(Block, self).munge(ds) return super(Block, self).preprocess_data(ds)
def _load_block(self, attr, ds): def _load_block(self, attr, ds):
return load_list_of_tasks( return load_list_of_tasks(
......
...@@ -102,7 +102,7 @@ class Play(Base, Taggable, Become): ...@@ -102,7 +102,7 @@ class Play(Base, Taggable, Become):
p = Play() p = Play()
return p.load_data(data, variable_manager=variable_manager, loader=loader) return p.load_data(data, variable_manager=variable_manager, loader=loader)
def munge(self, ds): def preprocess_data(self, ds):
''' '''
Adjusts play datastructure to cleanup old/legacy items Adjusts play datastructure to cleanup old/legacy items
''' '''
...@@ -121,7 +121,7 @@ class Play(Base, Taggable, Become): ...@@ -121,7 +121,7 @@ class Play(Base, Taggable, Become):
ds['remote_user'] = ds['user'] ds['remote_user'] = ds['user']
del ds['user'] del ds['user']
return super(Play, self).munge(ds) return super(Play, self).preprocess_data(ds)
def _load_vars(self, attr, ds): def _load_vars(self, attr, ds):
''' '''
......
...@@ -48,7 +48,8 @@ class PlaybookInclude(Base): ...@@ -48,7 +48,8 @@ class PlaybookInclude(Base):
from ansible.playbook import Playbook from ansible.playbook import Playbook
# first, we use the original parent method to correctly load the object # first, we use the original parent method to correctly load the object
# via the munge/load_data system we normally use for other playbook objects # via the load_data/preprocess_data system we normally use for other
# playbook objects
new_obj = super(PlaybookInclude, self).load_data(ds, variable_manager, loader) new_obj = super(PlaybookInclude, self).load_data(ds, variable_manager, loader)
# then we use the object to load a Playbook # then we use the object to load a Playbook
...@@ -67,7 +68,7 @@ class PlaybookInclude(Base): ...@@ -67,7 +68,7 @@ class PlaybookInclude(Base):
return pb return pb
def munge(self, ds): def preprocess_data(self, ds):
''' '''
Regorganizes the data for a PlaybookInclude datastructure to line Regorganizes the data for a PlaybookInclude datastructure to line
up with what we expect the proper attributes to be up with what we expect the proper attributes to be
...@@ -83,9 +84,7 @@ class PlaybookInclude(Base): ...@@ -83,9 +84,7 @@ class PlaybookInclude(Base):
for (k,v) in ds.iteritems(): for (k,v) in ds.iteritems():
if k == 'include': if k == 'include':
self._munge_include(ds, new_ds, k, v) self._preprocess_include(ds, new_ds, k, v)
elif k.replace("with_", "") in lookup_loader:
self._munge_loop(ds, new_ds, k, v)
else: else:
# some basic error checking, to make sure vars are properly # some basic error checking, to make sure vars are properly
# formatted and do not conflict with k=v parameters # formatted and do not conflict with k=v parameters
...@@ -98,9 +97,9 @@ class PlaybookInclude(Base): ...@@ -98,9 +97,9 @@ class PlaybookInclude(Base):
raise AnsibleParserError("vars for include statements must be specified as a dictionary", obj=ds) raise AnsibleParserError("vars for include statements must be specified as a dictionary", obj=ds)
new_ds[k] = v new_ds[k] = v
return super(PlaybookInclude, self).munge(new_ds) return super(PlaybookInclude, self).preprocess_data(new_ds)
def _munge_include(self, ds, new_ds, k, v): def _preprocess_include(self, ds, new_ds, k, v):
''' '''
Splits the include line up into filename and parameters Splits the include line up into filename and parameters
''' '''
......
...@@ -54,12 +54,12 @@ class RoleDefinition(Base, Become, Conditional, Taggable): ...@@ -54,12 +54,12 @@ class RoleDefinition(Base, Become, Conditional, Taggable):
def load(data, variable_manager=None, loader=None): def load(data, variable_manager=None, loader=None):
raise AnsibleError("not implemented") raise AnsibleError("not implemented")
def munge(self, ds): def preprocess_data(self, ds):
assert isinstance(ds, dict) or isinstance(ds, string_types) assert isinstance(ds, dict) or isinstance(ds, string_types)
if isinstance(ds, dict): if isinstance(ds, dict):
ds = super(RoleDefinition, self).munge(ds) ds = super(RoleDefinition, self).preprocess_data(ds)
# we create a new data structure here, using the same # we create a new data structure here, using the same
# object used internally by the YAML parsing code so we # object used internally by the YAML parsing code so we
......
...@@ -61,7 +61,7 @@ class RoleRequirement(RoleDefinition): ...@@ -61,7 +61,7 @@ class RoleRequirement(RoleDefinition):
if isinstance(ds, string_types): if isinstance(ds, string_types):
role_name = ds role_name = ds
else: else:
ds = self._munge_role_spec(ds) ds = self._preprocess_role_spec(ds)
(new_ds, role_params) = self._split_role_params(ds) (new_ds, role_params) = self._split_role_params(ds)
# pull the role name out of the ds # pull the role name out of the ds
...@@ -70,7 +70,7 @@ class RoleRequirement(RoleDefinition): ...@@ -70,7 +70,7 @@ class RoleRequirement(RoleDefinition):
return (new_ds, role_name, role_params) return (new_ds, role_name, role_params)
def _munge_role_spec(self, ds): def _preprocess_role_spec(self, ds):
if 'role' in ds: if 'role' in ds:
# Old style: {role: "galaxy.role,version,name", other_vars: "here" } # Old style: {role: "galaxy.role,version,name", other_vars: "here" }
role_info = self._role_spec_parse(ds['role']) role_info = self._role_spec_parse(ds['role'])
......
...@@ -137,7 +137,7 @@ class Task(Base, Conditional, Taggable, Become): ...@@ -137,7 +137,7 @@ class Task(Base, Conditional, Taggable, Become):
''' returns a human readable representation of the task ''' ''' returns a human readable representation of the task '''
return "TASK: %s" % self.get_name() return "TASK: %s" % self.get_name()
def _munge_loop(self, ds, new_ds, k, v): def _preprocess_loop(self, ds, new_ds, k, v):
''' take a lookup plugin name and store it correctly ''' ''' take a lookup plugin name and store it correctly '''
loop_name = k.replace("with_", "") loop_name = k.replace("with_", "")
...@@ -146,7 +146,7 @@ class Task(Base, Conditional, Taggable, Become): ...@@ -146,7 +146,7 @@ class Task(Base, Conditional, Taggable, Become):
new_ds['loop'] = loop_name new_ds['loop'] = loop_name
new_ds['loop_args'] = v new_ds['loop_args'] = v
def munge(self, ds): def preprocess_data(self, ds):
''' '''
tasks are especially complex arguments so need pre-processing. tasks are especially complex arguments so need pre-processing.
keep it short. keep it short.
...@@ -178,11 +178,11 @@ class Task(Base, Conditional, Taggable, Become): ...@@ -178,11 +178,11 @@ class Task(Base, Conditional, Taggable, Become):
# determined by the ModuleArgsParser() above # determined by the ModuleArgsParser() above
continue continue
elif k.replace("with_", "") in lookup_loader: elif k.replace("with_", "") in lookup_loader:
self._munge_loop(ds, new_ds, k, v) self._preprocess_loop(ds, new_ds, k, v)
else: else:
new_ds[k] = v new_ds[k] = v
return super(Task, self).munge(new_ds) return super(Task, self).preprocess_data(new_ds)
def post_validate(self, all_vars=dict(), fail_on_undefined=True): def post_validate(self, all_vars=dict(), fail_on_undefined=True):
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment