def start(hosts, channels, tag=None): if tag is None: tag = 'salt/engine/redis_sentinel' local = salt.client.LocalClient() ips = local.cmd(hosts['matching'], 'network.ip_addrs', [hosts['interface']]).values() client = Listener(host=ips.pop()[0], port=hosts['port'], channels=channels, tag=tag) client.run()
def run(self): """ Run the api """ self.parse_args() try: if self.config["verify_env"]: logfile = self.config["log_file"] if ( logfile is not None and not logfile.startswith("tcp://") and not logfile.startswith("udp://") and not logfile.startswith("file://") ): # Logfile is not using Syslog, verify salt.utils.verify.verify_files([logfile], self.config["user"]) except OSError as err: log.error(err) sys.exit(err.errno) self.setup_logfile_logger() client = salt.client.netapi.NetapiClient(self.config) self.daemonize_if_required() self.set_pidfile() client.run()
def start(hosts, channels, tag=None): if tag is None: tag = "salt/engine/redis_sentinel" with salt.client.LocalClient() as local: ips = local.cmd( hosts["matching"], "network.ip_addrs", [hosts["interface"]] ).values() client = Listener(host=ips.pop()[0], port=hosts["port"], channels=channels, tag=tag) client.run()
def do_propagate_ssh(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( propagate_ssh.name, attempt, stack)) # Update status stack.log_history( 'Propagating ssh try {0} of {1}. This may take a while.'.format( attempt, max_attempts, ) ) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='propagate-ssh', root_dir=root_dir, log_dir=log_dir) as client: results = client.run(target, 'state.sls', arg=['core.stackdio_users'], expr_form='list') if results['failed']: raise StackTaskException( 'SSH key propagation errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join(results['failed_hosts'])) ) if num_hosts != results['num_hosts']: logger.debug('salt did not propagate ssh keys to all hosts') err_msg = 'Salt errored and did not propagate ssh keys to all hosts' raise StackTaskException('Error propagating ssh keys: {0!r}'.format(err_msg))
def do_highstate(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( highstate.name, attempt, stack)) # Update status stack.log_history( 'Executing core provisioning try {0} of {1}. ' 'This may take a while.'.format( attempt, max_attempts, ) ) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='provisioning', root_dir=root_dir, log_dir=log_dir) as client: results = client.run(target, 'state.highstate', expr_form='list') if results['failed']: raise StackTaskException( 'Core provisioning errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join(results['failed_hosts'])) ) if num_hosts != results['num_hosts']: logger.debug('salt did not provision all hosts') err_msg = 'Salt errored and did not provision all the hosts' raise StackTaskException('Error executing core provisioning: {0!r}'.format(err_msg))
def runPost(token=None): ''' Execute salt command with either credentials in post data or token from url or token from X-Auth-Token headertoken ''' if not token: token = bottle.request.get_header('X-Auth-Token') cmds = bottle.request.json if not cmds: bottle.abort(code=400, text='Missing command(s).') if hasattr(cmds, 'get'): #convert to array cmds = [cmds] client = salt.client.api.APIClient(opts) try: results = [client.run(tokenify(cmd, token)) for cmd in cmds] if not results[0]: bottle.response.status = 404 return { 'error': 'Failed to run command: {0} on target: {1}'.format( str(cmds[0]['fun']), str(cmds[0]['tgt'])) } except EauthAuthenticationError as ex: bottle.abort(code=401, text=repr(ex)) except Exception as ex: bottle.abort(code=400, text=repr(ex)) return {"return": results}
def runPost(token = None): ''' Execute salt command with either credentials in post data or token from url or token from X-Auth-Token headertoken ''' if not token: token = bottle.request.get_header('X-Auth-Token') cmds = bottle.request.json if not cmds: bottle.abort(code=400, text='Missing command(s).') if hasattr(cmds, 'get'): #convert to array cmds = [cmds] client = salt.client.api.APIClient(opts) try: results = [client.run(tokenify(cmd, token)) for cmd in cmds] if not results[0]: bottle.response.status = 404 return {'error': 'Failed to run command: {0} on target: {1}'.format(str(cmds[0]['fun']), str(cmds[0]['tgt']))} except EauthAuthenticationError as ex: bottle.abort(code=401, text=repr(ex)) except Exception as ex: bottle.abort(code=400, text=repr(ex)) return {"return": results}
def do_propagate_ssh(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( propagate_ssh.name, attempt, stack)) # Update status stack.log_history( 'Propagating ssh try {0} of {1}. This may take a while.'.format( attempt, max_attempts, )) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='propagate-ssh', root_dir=root_dir, log_dir=log_dir) as client: results = client.run(target, 'state.sls', arg=['core.stackdio_users'], expr_form='list') if results['failed']: raise StackTaskException( 'SSH key propagation errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join( results['failed_hosts']))) if num_hosts != results['num_hosts']: logger.debug('salt did not propagate ssh keys to all hosts') err_msg = 'Salt errored and did not propagate ssh keys to all hosts' raise StackTaskException( 'Error propagating ssh keys: {0!r}'.format(err_msg))
def do_highstate(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( highstate.name, attempt, stack)) # Update status stack.log_history('Executing core provisioning try {0} of {1}. ' 'This may take a while.'.format( attempt, max_attempts, )) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='provisioning', root_dir=root_dir, log_dir=log_dir) as client: results = client.run(target, 'state.highstate', expr_form='list') if results['failed']: raise StackTaskException( 'Core provisioning errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join( results['failed_hosts']))) if num_hosts != results['num_hosts']: logger.debug('salt did not provision all hosts') err_msg = 'Salt errored and did not provision all the hosts' raise StackTaskException( 'Error executing core provisioning: {0!r}'.format(err_msg))
def do_single_sls(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( single_sls.name, attempt, stack, )) # Update status stack.log_history( 'Executing sls {0} try {1} of {2}. This ' 'may take a while.'.format( component, attempt, max_attempts, ) ) with StackdioLocalClient(run_type='single-sls', root_dir=root_dir, log_dir=log_dir) as client: stack.set_component_status(component, ComponentStatus.RUNNING, include_list=included_hostnames) results = client.run( target, 'state.sls', arg=[ component, 'stacks.{0}'.format(stack.pk), ], expr_form=expr_form, ) if results['failed']: raise StackTaskException( 'Single SLS {} errors on hosts: ' '{}. Please see the provisioning errors API ' 'or the log file for more details.'.format( component, ', '.join(results['failed_hosts']), ) ) if results['succeeded_hosts']: stack.set_component_status(component, ComponentStatus.SUCCEEDED, results['succeeded_hosts']) if results['failed_hosts']: stack.set_component_status(component, ComponentStatus.FAILED, results['failed_hosts'])
def do_single_sls(attempt=None): logger.info('Task {0} try #{1} for stack {2!r}'.format( single_sls.name, attempt, stack, )) # Update status stack.log_history('Executing sls {0} try {1} of {2}. This ' 'may take a while.'.format( component, attempt, max_attempts, )) with StackdioLocalClient(run_type='single-sls', root_dir=root_dir, log_dir=log_dir) as client: stack.set_component_status(component, ComponentStatus.RUNNING, include_list=included_hostnames) results = client.run( target, 'state.sls', arg=[ component, 'stacks.{0}'.format(stack.pk), ], expr_form=expr_form, ) if results['failed']: raise StackTaskException( 'Single SLS {} errors on hosts: ' '{}. Please see the provisioning errors API ' 'or the log file for more details.'.format( component, ', '.join(results['failed_hosts']), )) if results['succeeded_hosts']: stack.set_component_status(component, ComponentStatus.SUCCEEDED, results['succeeded_hosts']) if results['failed_hosts']: stack.set_component_status(component, ComponentStatus.FAILED, results['failed_hosts'])
def run(self): ''' Run the api ''' self.parse_args() try: if self.config['verify_env']: logfile = self.config['log_file'] if logfile is not None and not logfile.startswith('tcp://') \ and not logfile.startswith('udp://') \ and not logfile.startswith('file://'): # Logfile is not using Syslog, verify salt.utils.verify.verify_files([logfile], self.config['user']) except OSError as err: log.error(err) sys.exit(err.errno) self.setup_logfile_logger() client = salt.client.netapi.NetapiClient(self.config) self.daemonize_if_required() self.set_pidfile() client.run()
def run(self): ''' Run the api ''' self.parse_args() try: if self.config['verify_env']: logfile = self.config['log_file'] if logfile is not None and not logfile.startswith('tcp://') \ and not logfile.startswith('udp://') \ and not logfile.startswith('file://'): # Logfile is not using Syslog, verify salt.utils.verify.verify_files( [logfile], self.config['user'] ) except OSError as err: log.error(err) sys.exit(err.errno) self.setup_logfile_logger() client = salt.client.netapi.NetapiClient(self.config) self.daemonize_if_required() self.set_pidfile() client.run()
def do_propagate_ssh(attempt=None): logger.info('Task {0} try #{1} for environment {2!r}'.format( propagate_ssh.name, attempt, environment)) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='propagate-ssh', root_dir=root_dir, log_dir=log_dir) as client: results = client.run('env:environments.{}'.format( environment.name), 'state.sls', arg=['core.stackdio_users'], expr_form='grain') if results['failed']: raise EnvironmentTaskException( 'SSH key propagation errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join( results['failed_hosts'])))
def do_propagate_ssh(attempt=None): logger.info('Task {0} try #{1} for environment {2!r}'.format( propagate_ssh.name, attempt, environment)) # Use our fancy context manager that handles logging for us with StackdioLocalClient(run_type='propagate-ssh', root_dir=root_dir, log_dir=log_dir) as client: results = client.run('env:environments.{}'.format(environment.name), 'state.sls', arg=['core.stackdio_users'], expr_form='grain') if results['failed']: raise EnvironmentTaskException( 'SSH key propagation errors on hosts: ' '{0}. Please see the provisioning errors API ' 'or the log file for more details.'.format(', '.join(results['failed_hosts'])) )
def do_single_sls(attempt=None): logger.info('Task {0} try #{1} for environment {2!r}'.format( single_sls.name, attempt, environment, )) with StackdioLocalClient(run_type='single-sls', root_dir=root_dir, log_dir=log_dir) as client: results = client.run( target, 'state.sls', arg=[ component, 'environments.{0}'.format(environment.name), ], expr_form=expr_form, ) if results['failed']: raise EnvironmentTaskException( 'Single SLS {} errors on hosts: ' '{}. Please see the provisioning errors API ' 'or the log file for more details.'.format( component, ', '.join(results['failed_hosts']), )) if results['succeeded_hosts']: environment.set_component_status(component, ComponentStatus.SUCCEEDED, results['succeeded_hosts']) if results['failed_hosts']: environment.set_component_status(component, ComponentStatus.FAILED, results['failed_hosts'])
def do_single_sls(attempt=None): logger.info('Task {0} try #{1} for environment {2!r}'.format( single_sls.name, attempt, environment, )) with StackdioLocalClient(run_type='single-sls', root_dir=root_dir, log_dir=log_dir) as client: results = client.run( target, 'state.sls', arg=[ component, 'environments.{0}'.format(environment.name), ], expr_form=expr_form, ) if results['failed']: raise EnvironmentTaskException( 'Single SLS {} errors on hosts: ' '{}. Please see the provisioning errors API ' 'or the log file for more details.'.format( component, ', '.join(results['failed_hosts']), ) ) if results['succeeded_hosts']: environment.set_component_status(component, ComponentStatus.SUCCEEDED, results['succeeded_hosts']) if results['failed_hosts']: environment.set_component_status(component, ComponentStatus.FAILED, results['failed_hosts'])
def runPost(token = None): ''' Execute salt command with either credentials in post data or token from url or token from X-Auth-Token headertoken ''' if not token: token = bottle.request.get_header('X-Auth-Token') cmds = bottle.request.json if not cmds: bottle.abort(code=400, text='Missing command(s).') if hasattr(cmds, 'get'): #convert to array cmds = [cmds] client = salt.client.api.APIClient() try: results = [client.run(tokenify(cmd, token)) for cmd in cmds] except EauthAuthenticationError as ex: bottle.abort(code=401, text=repr(ex)) except Exception as ex: bottle.abort(code=400, text=repr(ex)) return {"return": results}
def runPost(token = None): ''' Execute salt command with either credentials in post data or token from url or token from X-Auth-Token headertoken ''' if not token: token = bottle.request.get_header('X-Auth-Token') cmds = bottle.request.json if not cmds: bottle.abort(code=400, text='Missing command(s).') if hasattr(cmds, 'get'): #convert to array cmds = [cmds] client = salt.client.api.APIClient(opts) try: results = [client.run(tokenify(cmd, token)) for cmd in cmds] except EauthAuthenticationError as ex: bottle.abort(code=401, text=repr(ex)) except Exception as ex: bottle.abort(code=400, text=repr(ex)) return {"return": results}