def __init__(self, loader=None): # Entries in the datastructure of a playbook may # be either a play or an include statement self._entries = [] self._basedir = '.' if loader: self._loader = loader else: self._loader = DataLoader()
def __init__(self, inventory_path=None, loader=None): self._fact_cache = FactCache() self._vars_cache = defaultdict(dict) self._extra_vars = defaultdict(dict) self._host_vars_files = defaultdict(dict) self._group_vars_files = defaultdict(dict) if not loader: self._loader = DataLoader() else: self._loader = loader
def load_data(self, ds, loader=None): ''' walk the input datastructure and assign any values ''' assert ds is not None # the data loader class is used to parse data from strings and files if loader is not None: self._loader = loader else: self._loader = DataLoader() if isinstance(ds, string_types) or isinstance(ds, FileIO): ds = self._loader.load(ds) # call the munge() function to massage the data into something # we can more easily parse, and then call the validation function # on it to ensure there are no incorrect key values ds = self.munge(ds) self._validate_attributes(ds) # Walk all attributes in the class. # # FIXME: we currently don't do anything with private attributes but # may later decide to filter them out of 'ds' here. for (name, attribute) in iteritems(self._get_base_attributes()): # copy the value over unless a _load_field method is defined if name in ds: method = getattr(self, '_load_%s' % name, None) if method: self._attributes[name] = method(name, ds[name]) else: self._attributes[name] = ds[name] # return the constructed object self.validate() return self
def setUp(self): # FIXME: need to add tests that utilize vault_password self._loader = DataLoader()