def __init__(self, template, saltenv='base', sls='', defaults=False, **kwargs): self.template = template self.saltenv = saltenv self.sls = sls self.sls_type = kwargs.get('sls_type', None) self.kwargs = kwargs self.defaults = defaults # Use __opts__ from config module otherwise roots file client will get # stuck using the 'file_roots' for pillars if any pillars are using # yamlscript. config module contains unmodified 'file_roots' opts = __opts__ if self.sls_type in 'pillar': opts = sys.modules['salt.loaded.int.module.config'].__opts__ self.client = salt.fileclient.get_file_client(opts) if isinstance(template, dict): self.state_file_content = YSOrderedDict.convert(template) self.pillars = Schema.pillars() self.pillars['auto'] = False else: # Set sls name in YamlScriptSafeLoader so it can be included when # creating __index__ self.pillars = Schema.pillars() template.seek(0) self.template = template.read() template.seek(0) YamlScriptSafeLoader.template = self.template YamlScriptSafeLoader.sls = self.sls self.state_file_content = self.deserialize_yamlscript_file(template)
def deserialize_yamlscript_file(template): template.seek(0) return yaml_serializer.deserialize(template.read(), **{'Loader': YamlScriptSafeLoader})