def com_containers(driver='openstack', skipping='', com='ls /data'): """ Execute a command on all running containers of your swarm cluster """ # Create machine mach = Dockerizing(driver) skips = [] if skipping.strip() != '': skips = skipping.strip().split(',') print("But skip", skips) # Find machines in list which are based on this driver for node in mach.list(with_driver=driver): _logger.info("Working with node %s" % node) # Clean containers inside those machines mach.prepare(node) for container in mach.ps(filters={'label': 'swarm'}): do = True for skip in skips: if skip in container: do = False _logger.debug("Skip com on %s" % container) break if do: _logger.info("Com on %s" % container) out = mach.exec_com_on_running( container=container, tty=False, execcom=com) print("Obtained:", out) mach.exit() print("DONE")
def containers_reset(driver='openstack', skipswarm=False): """ List all machine with a driver, and clean up their containers """ mach = Dockerizing(driver) # Find machines in list which are based on this driver for node in mach.list(with_driver=driver): # Clean containers inside those machines mach.prepare(node) mach.destroy_all(skipswarm) mach.exit() _logger.info("Completed")
def com_node(driver='openstack', com='ls /var'): """ Execute a command on all running nodes of one driver """ # Create machine mach = Dockerizing(driver) # Find machines in list which are based on this driver for node in mach.list(with_driver=driver): _logger.info("Working with node %s" % node) # Clean containers inside those machines mach.prepare(node) out = mach.do(com) print("obtained", out) mach.exit() print("DONE")