def prepare(self): ''' Run the preparation sequence required to start a salt master server. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), self.config['cachedir'], os.path.join(self.config['cachedir'], 'jobs'), os.path.join(self.config['cachedir'], 'proc'), self.config['sock_dir'], self.config['token_dir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith( ('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.info('Setting up the Salt Master') if not verify_socket(self.config['interface'], self.config['publish_port'], self.config['ret_port']): self.exit(4, 'The ports are not available to bind\n') self.config['interface'] = ip_bracket(self.config['interface']) migrations.migrate_paths(self.config) # Late import so logging works correctly import bonneville.master self.master = bonneville.master.Master(self.config) self.daemonize_if_required() self.set_pidfile()
def run(self): ''' Execute the salt call! ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) if self.options.local: self.config['file_client'] = 'local' if self.options.master: self.config['master'] = self.options.master # Setup file logging! self.setup_logfile_logger() caller = bonneville.cli.caller.Caller(self.config) if self.options.doc: caller.print_docs() self.exit(0) if self.options.grains_run: caller.print_grains() self.exit(0) caller.run()
def run(self): ''' Execute salt-cp ''' self.parse_args() if self.config['verify_env']: if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) # Setup file logging! self.setup_logfile_logger() cp_ = bonneville.cli.cp.SaltCP(self.config) cp_.run()
def run(self): ''' Execute salt-run ''' self.parse_args() if self.config['verify_env']: verify_env([ self.config['pki_dir'], self.config['cachedir'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) # Setup file logging! self.setup_logfile_logger() runner = bonneville.runner.Runner(self.config) if self.options.doc: runner._print_docs() self.exit(0) # Run this here so SystemExit isn't raised anywhere else when # someone tries to use the runners via the python API try: if check_user(self.config['user']): runner.run() except SaltClientError as exc: raise SystemExit(str(exc))
def prepare(self): ''' Run the preparation sequence required to start a salt syndic minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith( ('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.info('Setting up the Salt Syndic Minion "{0}"'.format( self.config['id'])) # Late import so logging works correctly import bonneville.minion self.daemonize_if_required() self.syndic = bonneville.minion.Syndic(self.config) self.set_pidfile()
def run(self): ''' Execute salt-key ''' self.parse_args() if self.config['verify_env']: verify_env_dirs = [] if not self.config['gen_keys']: verify_env_dirs.extend([ self.config['pki_dir'], os.path.join(self.config['pki_dir'], 'minions'), os.path.join(self.config['pki_dir'], 'minions_pre'), os.path.join(self.config['pki_dir'], 'minions_rejected'), ]) verify_env( verify_env_dirs, self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['key_logfile']], self.config['user'] ) self.setup_logfile_logger() key = bonneville.key.KeyCLI(self.config) if check_user(self.config['user']): key.run()
def run(self): ''' Execute the salt command line ''' self.parse_args() if self.config['verify_env']: if not self.config['log_file'].startswith(('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files( [self.config['log_file']], self.config['user'] ) # Setup file logging! self.setup_logfile_logger() try: local = bonneville.client.LocalClient(self.get_config_file_path()) except SaltClientError as exc: self.exit(2, '{0}\n'.format(exc)) return if self.options.batch: batch = bonneville.cli.batch.Batch(self.config) # Printing the output is already taken care of in run() itself for res in batch.run(): pass else: if self.options.timeout <= 0: self.options.timeout = local.opts['timeout'] kwargs = { 'tgt': self.config['tgt'], 'fun': self.config['fun'], 'arg': self.config['arg'], 'timeout': self.options.timeout, 'show_timeout': self.options.show_timeout} if 'token' in self.config: kwargs['token'] = self.config['token'] if self.selected_target_option: kwargs['expr_form'] = self.selected_target_option else: kwargs['expr_form'] = 'glob' if getattr(self.options, 'return'): kwargs['ret'] = getattr(self.options, 'return') # If using eauth and a token hasn't already been loaded into # kwargs, prompt the user to enter auth credentials if not 'token' in kwargs and self.options.eauth: resolver = bonneville.auth.Resolver(self.config) res = resolver.cli(self.options.eauth) if self.options.mktoken and res: tok = resolver.token_cli( self.options.eauth, res ) if tok: kwargs['token'] = tok.get('token', '') if not res: sys.exit(2) kwargs.update(res) kwargs['eauth'] = self.options.eauth if self.config['async']: jid = local.cmd_async(**kwargs) print('Executed command with job ID: {0}'.format(jid)) return try: # local will be None when there was an error if local: if self.options.subset: cmd_func = local.cmd_subset kwargs['sub'] = self.options.subset kwargs['cli'] = True else: cmd_func = local.cmd_cli if self.options.static: if self.options.verbose: kwargs['verbose'] = True full_ret = local.cmd_full_return(**kwargs) ret, out = self._format_ret(full_ret) self._output_ret(ret, out) elif self.config['fun'] == 'sys.doc': ret = {} out = '' for full_ret in local.cmd_cli(**kwargs): ret_, out = self._format_ret(full_ret) ret.update(ret_) self._output_ret(ret, out) else: if self.options.verbose: kwargs['verbose'] = True for full_ret in cmd_func(**kwargs): ret, out = self._format_ret(full_ret) self._output_ret(ret, out) except (SaltInvocationError, EauthAuthenticationError) as exc: ret = str(exc) out = '' self._output_ret(ret, out)
def prepare(self): ''' Run the preparation sequence required to start a salt minion. If sub-classed, don't **ever** forget to run: super(YourSubClass, self).prepare() ''' self.parse_args() try: if self.config['verify_env']: confd = self.config.get('default_include') if confd: # If 'default_include' is specified in config, then use it if '*' in confd: # Value is of the form "minion.d/*.conf" confd = os.path.dirname(confd) if not os.path.isabs(confd): # If configured 'default_include' is not an absolute # path, consider it relative to folder of 'conf_file' # (/etc/salt by default) confd = os.path.join( os.path.dirname(self.config['conf_file']), confd) else: confd = os.path.join( os.path.dirname(self.config['conf_file']), 'minion.d') verify_env( [ self.config['pki_dir'], self.config['cachedir'], self.config['sock_dir'], self.config['extension_modules'], confd, ], self.config['user'], permissive=self.config['permissive_pki_access'], pki_dir=self.config['pki_dir'], ) logfile = self.config['log_file'] if logfile is not None and not logfile.startswith( ('tcp://', 'udp://', 'file://')): # Logfile is not using Syslog, verify verify_files([logfile], self.config['user']) except OSError as err: sys.exit(err.errno) self.setup_logfile_logger() logger.info('Setting up the Salt Minion "{0}"'.format( self.config['id'])) migrations.migrate_paths(self.config) # Late import so logging works correctly import bonneville.minion # If the minion key has not been accepted, then Salt enters a loop # waiting for it, if we daemonize later then the minion could halt # the boot process waiting for a key to be accepted on the master. # This is the latest safe place to daemonize self.daemonize_if_required() self.set_pidfile() if isinstance(self.config.get('master'), list): self.minion = bonneville.minion.MultiMinion(self.config) else: self.minion = bonneville.minion.Minion(self.config)