Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for line in output:
_, target, type_, data = line.split(',', 3)
# Skip anything not in the limit
if limit is not None and target not in limit:
continue
# For each running container - fetch it's SSH config in a thread - this
# is because Vagrant *really* slow to run each command.
if type_ == 'state' and data == 'running':
targets.append(target)
threads = []
config_queue = Queue()
with progress_spinner(targets) as progress:
for target in targets:
thread = Thread(
target=_get_vagrant_ssh_config,
args=(config_queue, progress, target),
)
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
queue_items = list(config_queue.queue)
lines = []
for output in queue_items:
lines.extend(output)
command = command(*host_args)
greenlet = state.fact_pool.spawn(
host.run_shell_command, state, command,
sudo=sudo, sudo_user=sudo_user,
su_user=su_user, timeout=timeout,
print_output=state.print_fact_output,
)
greenlet_to_host[greenlet] = host
# Wait for all the commands to execute
progress_prefix = 'fact: {0}'.format(name)
if args:
progress_prefix = '{0}{1}'.format(progress_prefix, args)
with progress_spinner(
greenlet_to_host.values(),
prefix_message=progress_prefix,
) as progress:
for greenlet in gevent.iwait(greenlet_to_host.keys()):
host = greenlet_to_host[greenlet]
progress(host)
hostname_facts = {}
failed_hosts = set()
# Collect the facts and any failures
for greenlet, host in six.iteritems(greenlet_to_host):
status = False
stdout = []
try:
else:
# Start with the whole inventory in one batch
batches = [state.inventory]
# If parallel set break up the inventory into a series of batches
if op_meta['parallel']:
parallel = op_meta['parallel']
hosts = list(state.inventory)
batches = [
hosts[i:i + parallel]
for i in range(0, len(hosts), parallel)
]
for batch in batches:
with progress_spinner(batch) as progress:
# Spawn greenlet for each host
greenlet_to_host = {
state.pool.spawn(_run_server_op, state, host, op_hash): host
for host in batch
}
# Trigger CLI progress as hosts complete if provided
for greenlet in gevent.iwait(greenlet_to_host.keys()):
host = greenlet_to_host[greenlet]
progress(host)
# Get all the results
for greenlet, host in six.iteritems(greenlet_to_host):
if not greenlet.get():
failed_hosts.add(host)
def get_vagrant_config(limit=None):
logger.info('Getting Vagrant config...')
if limit and not isinstance(limit, (list, tuple)):
limit = [limit]
with progress_spinner({'vagrant status'}) as progress:
output = local.shell(
'vagrant status --machine-readable',
splitlines=True,
)
progress('vagrant status')
targets = []
for line in output:
_, target, type_, data = line.split(',', 3)
# Skip anything not in the limit
if limit is not None and target not in limit:
continue
# For each running container - fetch it's SSH config in a thread - this
def _run_serial_ops(state):
'''
Run all ops for all servers, one server at a time.
'''
for host in list(state.inventory):
host_operations = product([host], state.get_op_order())
with progress_spinner(host_operations) as progress:
try:
_run_server_ops(
state, host,
progress=progress,
)
except PyinfraError:
state.fail_hosts({host})
if op_meta['run_once']:
op_types.append('run once')
logger.info('{0} {1} {2}'.format(
click.style('--> Starting{0}operation:'.format(
' {0} '.format(', '.join(op_types)) if op_types else ' ',
), 'blue'),
click.style(', '.join(op_meta['names']), bold=True),
tuple(op_meta['args']) if op_meta['args'] else '',
))
failed_hosts = set()
if op_meta['serial']:
with progress_spinner(state.inventory) as progress:
# For each host, run the op
for host in state.inventory:
result = _run_server_op(state, host, op_hash)
progress(host)
if not result:
failed_hosts.add(host)
else:
# Start with the whole inventory in one batch
batches = [state.inventory]
# If parallel set break up the inventory into a series of batches
if op_meta['parallel']:
parallel = op_meta['parallel']
hosts = list(state.inventory)
def _run_no_wait_ops(state):
'''
Run all ops for all servers at once.
'''
hosts_operations = product(state.inventory, state.get_op_order())
with progress_spinner(hosts_operations) as progress:
# Spawn greenlet for each host to run *all* ops
greenlets = [
state.pool.spawn(
_run_server_ops, state, host,
progress=progress,
)
for host in state.inventory
]
gevent.joinall(greenlets)