예제 #1
0
def machine_rm(node="dev", driver='virtualbox'):
    """ A task to remove an existing machine - on virtualbox """
    machine = Dockerizing(driver)

    # Check that the requested node does not already exist
    if node not in machine.list():
        print(colors.warn | "Failed:", colors.bold |
              "Machine '%s' does not exist" % node)
        return

    _logger.info(colors.bold | "Trying to remove '%s'" % node)
    print(machine.remove(node))
    _logger.info(colors.green | "Removed")
예제 #2
0
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")
예제 #3
0
def machine_new(node="dev", driver='virtualbox'):
    """ A task to add a docker machine - on virtualbox """
    machine = Dockerizing(driver)

    # Check that the requested node does not already exist
    if node in machine.list():
        print(colors.warn | "Failed:", colors.bold |
              "Machine '%s' Already exists" % node)
        return
    machine.create(node)

    # Create the machine
    _logger.info("Preparing machine", node)
    print(machine.create(node))
    _logger.info(colors.green | "Created!\n\n")
예제 #4
0
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")
예제 #5
0
def driver_reset(driver='openstack', skip=None):
    """ Remove PERMANENTLY all machine within a driver class """

    mach = Dockerizing(driver)
    import time
    skip_nodes = []
    if skip is not None:
        skip_nodes = skip.split(',')
    # Find machines in list which are based on this driver
    for node in mach.list(with_driver=driver):
        if node in skip_nodes:
            _logger.info("Skipping '%s'" % node)

            continue
        # REMOVE THEM!!
        _logger.warning("Removing machine '%s'!" % node)
        time.sleep(5)
        mach.remove(node)
    _logger.info("Done")
예제 #6
0
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")