def create_tests(self):
        """Apply the tests template and return the generated plays

        :returns: A string with the generated plays for inclusion in a playbook
        """
        tests = self.stack.get('tests')

        if tests is None:
            return ''

        test_play = ''

        for test in tests:
            if self.stack.get('nodes') is None:
                target = 'localhost'
            else:
                target = '{{{{ groups.{}[0] }}}}'.format(test.get('target'))

            test_play += apply_template('tests.yml',
                                        name=test.get('name'),
                                        docker=test.get('docker'),
                                        shell=test.get('shell'),
                                        target=target)

        return test_play
def generate(stack, conf):
    """Generate a Ansible teardown playbook from the stack config file.

    :stack: open file with a stack configuration in it
    :conf: open file with a launcher configuration in it
    :returns: a Ansible teardown playbook for the given configuration
    """
    playbook = '---\n'

    if stack.has('nodes'):
        playbook += apply_template('ec2_teardown.yml',
                                   nodes=stack.get('nodes'),
                                   conf=conf)
    else:
        for service in stack.get('services'):
            playbook += apply_template('stop_container.yml', service=service)

    return playbook
def generate(stack, conf):
    """Generate a Ansible teardown playbook from the stack config file.

    :stack: open file with a stack configuration in it
    :conf: open file with a launcher configuration in it
    :returns: a Ansible teardown playbook for the given configuration
    """
    playbook = '---\n'

    if stack.has('nodes'):
        playbook += apply_template('ec2_teardown.yml',
                                   nodes=stack.get('nodes'),
                                   conf=conf)
    else:
        for service in stack.get('services'):
            playbook += apply_template('stop_container.yml',
                                       service=service)

    return playbook
def run(conf, stack, verbosity=0, python=None):
    """Generate all needed files, run them and remove them again

    :conf: the launcher configuration to use
    :stack: the stack conf to use
    :verbosity: control the amount of output
    :python: the python executable to use locally
    """
    inventory = apply_template('inventory', python=python)
    playbook = generate(stack, conf)
    return exec_playbook(inventory, playbook, verbosity)
def run(conf, stack, verbosity=0, python=None):
    """Generate all needed files, run them and remove them again

    :conf: the launcher configuration to use
    :stack: the stack conf to use
    :verbosity: control the amount of output
    :python: the python executable to use locally
    """
    inventory = apply_template('inventory', python=python)
    playbook = generate(stack, conf)
    return exec_playbook(inventory, playbook, verbosity)
    def create_nodes(self):
        """ return node tasks.

        :returns: string
        """
        nodes = copy.deepcopy(self.stack.get('nodes'))
        node_tasks = ""

        if nodes is None:
            return node_tasks

        if self.stack.get('logging') is True:
            add_logging_to_nodes(nodes)

        node_tasks += apply_template('ec2_header.yml')
        for node in nodes:
            node_tasks += apply_template('node.yml',
                                         node=node,
                                         conf=self.config)
        node_tasks += apply_template('ec2_wait.yml')
        node_tasks += apply_template('ec2_bootstrap.yml')
        node_tasks += apply_template('docker_login.yml', conf=self.config)
        return node_tasks
    def create_security_group(self):
        """ return security group tasks.

        :returns: string
        """
        tasks = ""
        if self.stack.get('security_groups') is None:
            return tasks

        for security_group in self.stack.get('security_groups'):
            tasks += apply_template('security_group.yml',
                                    security_group=security_group,
                                    conf=self.config)
        return tasks
Exemple #8
0
def run(conf, stack, verbosity=0, python=None):
    """Generate all needed files, run them and remove them again

    :conf: the launcher configuration to use
    :stack: the stack conf to use
    :verbosity: control the amount of output
    :python: the python executable to use locally
    """
    inventory = apply_template('inventory', python=python)
    playbook = generate(stack, conf)

    spawn(ansible_vars.GALAXY_INSTALL, verbosity)
    ansible_return = exec_playbook(inventory, playbook, verbosity)

    if ansible_return == 0:
        spawn(ansible_vars.GALAXY_REMOVE, verbosity)
        spawn(["rmdir", "roles"], 0)

    return ansible_return
def run(conf, stack, verbosity=0, python=None):
    """Generate all needed files, run them and remove them again

    :conf: the launcher configuration to use
    :stack: the stack conf to use
    :verbosity: control the amount of output
    :python: the python executable to use locally
    """
    inventory = apply_template('inventory', python=python)
    playbook = generate(stack, conf)

    spawn(ansible_vars.GALAXY_INSTALL, verbosity)
    ansible_return = exec_playbook(inventory, playbook, verbosity)

    if ansible_return == 0:
        spawn(ansible_vars.GALAXY_REMOVE, verbosity)
        spawn(["rmdir", "roles"], 0)

    return ansible_return
    def create_migration(self, service):
        """ return migration tasks.

        :service: a service object
        :returns: string
        """
        migrations = "\n"
        if service.get('migrations').get('cql', None) is not None:
            files = service.get('migrations')['cql']
            if service.get('links'):
                host = "local"
            else:
                host = find_by_attr(self.stack.data['services'],
                                    'name',
                                    'cassandra').get('host') + '[0]'
            migrations += apply_template('cql_migration.yml',
                                         service=service,
                                         files=files,
                                         host=host)
        return migrations
    def create_services(self):
        """ return service tasks.

        :returns: string
        """
        services = self.stack.get('services')
        if self.stack.get('logging') is True:
            services = add_logging_services(services, self.is_remote)

        target = 'ec2' if self.is_remote else 'local'
        linked_services = link_services(services, target)

        services_tasks = ""

        for service in linked_services:
            if service.get('migrations') is not None:
                services_tasks += self.create_migration(service)
            services_tasks += apply_template('service.yml',
                                             service=service,
                                             conf=self.config)
        return services_tasks