Esempio n. 1
0
def diff(directory=None):
    """
    Show configuration file diffs.
    """
    for conffiles in iter_conffiles(directory):
        status("Computing template diffs for '{environment}' and '{role}'",
               environment=conffiles.environment,
               role=conffiles.role)

        conffiles.diff(directory)
Esempio n. 2
0
def push(directory=None):
    """
    Push configuration files.
    """
    for conffiles in iter_conffiles(directory):
        status("Pushing templates for '{environment}' and '{role}'",
               environment=conffiles.environment,
               role=conffiles.role)

        conffiles.push()
Esempio n. 3
0
def generate(directory=None):
    """
    Generate configuration files.
    """
    for conffiles in iter_conffiles(directory):
        status("Generating templates for '{environment}' and '{role}'",
               environment=conffiles.environment,
               role=conffiles.role)

        conffiles.generate()
Esempio n. 4
0
def pull(directory=None):
    """
    Pull remote configuration files.
    """
    for conffiles in iter_conffiles(directory):
        status("Pulling remote templates for '{environment}' and '{role}'",
               environment=conffiles.environment,
               role=conffiles.role)

        conffiles.pull()
Esempio n. 5
0
def generate(directory=None):
    """
    Generate configuration files.
    """
    for conffiles in iter_conffiles(directory):
        status("Generating templates for '{environment}' and '{role}'",
               environment=conffiles.environment,
               role=conffiles.role)

        conffiles.generate()
Esempio n. 6
0
def setup_database():
    """
    Initialize Elephant Database.
    """
    status("Initializing Elephant database")

    dbdata = load_component_data("mysql-server-conf")["database"]

    initialize_database(dbdata["name"],
                        dbdata["host"],
                        dbdata["admin"]["username"],
                        dbdata["admin"]["password"],
                        dbdata["username"],
                        dbdata["password"],
                        target_hostnames=dbdata["grant_hosts"])
Esempio n. 7
0
    def diff(self, generated_dir, remotes_dir, output=False):
        """
        Compute the diff between the generated and remote files.

        If output is enabled, show the diffs nicely.
        """
        generated_file_name = join(generated_dir, self.name)
        assert_may_be_created(generated_file_name)

        remote_file_name = join(remotes_dir, self.name)
        assert_may_be_created(remote_file_name)

        status('Computing diff for {file_name}', file_name=self.remote)

        return ConfFileDiff(remote_file_name, generated_file_name, self.remote)
Esempio n. 8
0
    def generate(self, directory):
        """
        Write the configuration file.
        """
        generated_file_name = join(directory, self.name)
        assert_may_be_created(generated_file_name)

        status('Generating {file_name}', file_name=self.remote)

        # ensure that destination directory exists
        _ensure_dir(directory)

        if self.should_render():
            self._write_template(generated_file_name)
        else:
            self._write_verbatim(generated_file_name)
Esempio n. 9
0
    def push(self, directory):
        """
        Push the generated configuration file to the remote host.
        """
        generated_file_name = join(directory, self.name)
        assert_may_be_created(generated_file_name)
        remote_dir = dirname(self.remote)

        status('Pushing {file_name} to {host}',
               file_name=self.remote,
               host=self.host)

        sudo('mkdir -p {dir_name}'.format(dir_name=remote_dir))

        put(generated_file_name,
            self.remote,
            use_sudo=True,
            mirror_local_mode=True)
Esempio n. 10
0
    def pull(self, directory):
        """
        Pull remote configuration file to local file.
        """
        local_file_name = join(directory, self.name)
        assert_may_be_created(local_file_name)

        status('Pulling {file_name} from {host}',
               file_name=self.remote,
               host=self.host)

        _ensure_dir(directory)
        _clear_file(local_file_name)

        if exists_remote(self.remote, use_sudo=True):
            get(self.remote, local_file_name)
        else:
            status('Not found: {file_name}',
                   file_name=self.remote)