1import os 2 3import salt.cli.caller 4import salt.defaults.exitcodes 5import salt.utils.parsers 6from salt.config import _expand_glob_path 7from salt.utils.verify import verify_log 8 9 10class SaltCall(salt.utils.parsers.SaltCallOptionParser): 11 """ 12 Used to locally execute a salt command 13 """ 14 15 def run(self): 16 """ 17 Execute the salt call! 18 """ 19 self.parse_args() 20 21 if self.options.file_root: 22 # check if the argument is pointing to a file on disk 23 file_root = os.path.abspath(self.options.file_root) 24 self.config["file_roots"] = {"base": _expand_glob_path([file_root])} 25 26 if self.options.pillar_root: 27 # check if the argument is pointing to a file on disk 28 pillar_root = os.path.abspath(self.options.pillar_root) 29 self.config["pillar_roots"] = {"base": _expand_glob_path([pillar_root])} 30 31 if self.options.states_dir: 32 # check if the argument is pointing to a file on disk 33 states_dir = os.path.abspath(self.options.states_dir) 34 self.config["states_dirs"] = [states_dir] 35 36 if self.options.local: 37 self.config["file_client"] = "local" 38 if self.options.master: 39 self.config["master"] = self.options.master 40 41 # Setup file logging! 42 self.setup_logfile_logger() 43 verify_log(self.config) 44 45 caller = salt.cli.caller.Caller.factory(self.config) 46 47 if self.options.doc: 48 caller.print_docs() 49 self.exit(salt.defaults.exitcodes.EX_OK) 50 51 if self.options.grains_run: 52 caller.print_grains() 53 self.exit(salt.defaults.exitcodes.EX_OK) 54 55 caller.run() 56