Skip to content

Instantly share code, notes, and snippets.

@lattwood
Created October 30, 2015 16:39
Show Gist options
  • Save lattwood/4c52ba7b8583ae4565eb to your computer and use it in GitHub Desktop.
Save lattwood/4c52ba7b8583ae4565eb to your computer and use it in GitHub Desktop.
Stackstorm SSH Bastion Client Testing
#!/usr/bin/env python
import logging
import pprint
from oslo_config import cfg
from st2actions.runners.ssh.parallel_ssh import ParallelSSHClient
from st2common.logging.formatters import ConsoleLogFormatter
def test_run_command():
hosts = [
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1',
'127.0.0.1!localhost',
'localhost!127.0.0.1'
]
client = ParallelSSHClient(hosts=hosts,
user='stanley',
pkey_file='/home/stanley/.ssh/st2_stanley_key',
connect=True)
result = client.run('pwd', timeout=60)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(result)
if __name__ == '__main__':
opts = [
cfg.StrOpt('system_user', default='stanley')
]
system_user_opts = [
cfg.StrOpt('ssh_key_file', default='/home/stanley/.ssh/st2_stanley_key')
]
log_opts = [
cfg.BoolOpt('mask_secrets', default=False)
]
cfg.CONF.register_opts(opts)
cfg.CONF.register_opts(log_opts, 'log')
console = logging.StreamHandler()
formatter = ConsoleLogFormatter()
console.setFormatter(formatter)
console.setLevel(logging.DEBUG)
logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
logger.addHandler(console)
test_run_command()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment