コード例 #1
0
def test_format_and_mount():
    """
    Format, mount and unmount a block device
    """

    from fabtools.disk import ismounted, mkfs, mount

    assert not ismounted('/dev/loop0')

    try:
        # Make a loopback block device
        sudo('dd if=/dev/zero of=bigfile bs=1024 count=30720')
        sudo('losetup /dev/loop0 bigfile')

        # Format the block device
        mkfs('/dev/loop0', 'ext3')

        # Mount the block device
        require_directory('/mnt/loop', use_sudo=True)
        mount('/dev/loop0', '/mnt/loop')
        assert ismounted('/dev/loop0')

        # Unmount the block device
        sudo('umount /dev/loop0')
        assert not ismounted('/dev/loop0')

    finally:
        sudo('umount /dev/loop0', quiet=True)
        sudo('losetup -d /dev/loop0', quiet=True)
        sudo('rm -f bigfile', quiet=True)
コード例 #2
0
def format_and_mount():
    """
    Format, mount and unmount a block device
    """

    from fabric.api import sudo

    from fabtools.require.files import directory as require_directory
    import fabtools

    assert not fabtools.disk.ismounted('/dev/loop0')

    try:
        # Make a loopback block device
        sudo('dd if=/dev/zero of=bigfile bs=1024 count=30720')
        sudo('losetup /dev/loop0 bigfile')

        # Format the block device
        fabtools.disk.mkfs('/dev/loop0', 'ext3')

        # Mount the block device
        require_directory('/mnt/loop', use_sudo=True)
        fabtools.disk.mount('/dev/loop0', '/mnt/loop')
        assert fabtools.disk.ismounted('/dev/loop0')

        # Unmount the block device
        sudo('umount /dev/loop0')
        assert not fabtools.disk.ismounted('/dev/loop0')

    finally:
        sudo('umount /dev/loop0', quiet=True)
        sudo('losetup -d /dev/loop0', quiet=True)
        sudo('rm -f bigfile', quiet=True)
コード例 #3
0
ファイル: oracle_jdk.py プロジェクト: sebastibe/fabtools
def install_from_oracle_site(version=DEFAULT_VERSION):
    """
    Download tarball from Oracle site and install JDK.

    ::

        import fabtools

        # Install Oracle JDK
        fabtools.oracle_jdk.install_from_oracle_site()

    """

    from fabtools.require.files import directory as require_directory

    release, build = version.split("-")
    major, update = release.split("u")
    if len(update) == 1:
        update = "0" + update

    jdk_arch = _required_jdk_arch()

    if major == "6":
        jdk_filename = "jdk-%(release)s-linux-%(jdk_arch)s.bin" % locals()
    else:
        jdk_filename = "jdk-%(release)s-linux-%(jdk_arch)s.tar.gz" % locals()
    jdk_dir = "jdk1.%(major)s.0_%(update)s" % locals()

    jdk_url = "http://download.oracle.com/otn-pub/java/jdk/" + "%(version)s/%(jdk_filename)s" % locals()

    with cd("/tmp"):
        run("rm -rf %s" % jdk_filename)
        run(
            'wget --no-cookies --header="Cookie: gpw_e24=a" '
            + "--progress=dot:mega "
            + "%(jdk_url)s -O /tmp/%(jdk_filename)s" % locals()
        )

    require_directory("/opt", mode="777", use_sudo=True)
    with cd("/opt"):
        if major == "6":
            run("chmod u+x /tmp/%s" % jdk_filename)
            with cd("/tmp"):
                run("./%s" % jdk_filename)
                run("mv %s /opt/" % jdk_dir)
        else:
            run("tar -xzvf /tmp/%s" % jdk_filename)

        if is_link("jdk"):
            run("rm -rf jdk")
        run("ln -s %s jdk" % jdk_dir)

    _create_profile_d_file()
コード例 #4
0
def install_from_oracle_site(version=DEFAULT_VERSION):
    """
    Download tarball from Oracle site and install JDK.

    ::

        import fabtools

        # Install Oracle JDK
        fabtools.oracle_jdk.install_from_oracle_site()

    """

    from fabtools.require.files import directory as require_directory

    release, build = version.split('-')
    major, update = release.split('u')
    if len(update) == 1:
        update = '0' + update

    jdk_arch = _required_jdk_arch()

    if major == '6':
        jdk_filename = 'jdk-%(release)s-linux-%(jdk_arch)s.bin' % locals()
    else:
        jdk_filename = 'jdk-%(release)s-linux-%(jdk_arch)s.tar.gz' % locals()
    jdk_dir = 'jdk1.%(major)s.0_%(update)s' % locals()

    jdk_url = 'http://download.oracle.com/otn-pub/java/jdk/' +\
              '%(version)s/%(jdk_filename)s' % locals()

    with cd('/tmp'):
        run('rm -rf %s' % jdk_filename)
        run('wget --header "Cookie: oraclelicense=accept-securebackup-cookie" ' +
            '--progress=dot:mega ' +
            '%(jdk_url)s -O /tmp/%(jdk_filename)s' % locals())

    require_directory('/opt', mode='777', use_sudo=True)
    with cd('/opt'):
        if major == '6':
            run('chmod u+x /tmp/%s' % jdk_filename)
            with cd('/tmp'):
                run('./%s' % jdk_filename)
                run('mv %s /opt/' % jdk_dir)
        else:
            run('tar -xzvf /tmp/%s' % jdk_filename)

        if is_link('jdk'):
            run('rm -rf jdk')
        run('ln -s %s jdk' % jdk_dir)

    _create_profile_d_file()
コード例 #5
0
ファイル: oracle_jdk.py プロジェクト: wocin/fabtools
def install_from_oracle_site(version=DEFAULT_VERSION):
    """
    Download tarball from Oracle site and install JDK.

    ::

        import fabtools

        # Install Oracle JDK
        fabtools.oracle_jdk.install_from_oracle_site()

    """

    from fabtools.require.files import directory as require_directory

    release, build = version.split('-')
    major, update = release.split('u')
    if len(update) == 1:
        update = '0' + update

    jdk_arch = _required_jdk_arch()

    if major == '6':
        jdk_filename = 'jdk-%(release)s-linux-%(jdk_arch)s.bin' % locals()
    else:
        jdk_filename = 'jdk-%(release)s-linux-%(jdk_arch)s.tar.gz' % locals()
    jdk_dir = 'jdk1.%(major)s.0_%(update)s' % locals()

    jdk_url = 'http://download.oracle.com/otn-pub/java/jdk/' +\
              '%(version)s/%(jdk_filename)s' % locals()

    with cd('/tmp'):
        run('rm -rf %s' % jdk_filename)
        run('wget --no-cookies --no-check-certificate --header="Cookie: gpw_e24=a" ' +
            '--progress=dot:mega ' +
            '%(jdk_url)s -O /tmp/%(jdk_filename)s' % locals())

    require_directory('/opt', mode='777', use_sudo=True)
    with cd('/opt'):
        if major == '6':
            run('chmod u+x /tmp/%s' % jdk_filename)
            with cd('/tmp'):
                run('./%s' % jdk_filename)
                run('mv %s /opt/' % jdk_dir)
        else:
            run('tar -xzvf /tmp/%s' % jdk_filename)

        if is_link('jdk'):
            run('rm -rf jdk')
        run('ln -s %s jdk' % jdk_dir)

    _create_profile_d_file()
コード例 #6
0
ファイル: test_files.py プロジェクト: 26lights/fabtools
def test_permissions():

    from fabtools.files import owner, group, mode
    from fabtools.require.files import directory as require_directory

    try:
        run_as_root('mkdir foo')
        require_directory('bar', use_sudo=True)

        assert owner('foo') == owner('bar')
        assert group('foo') == group('bar')
        assert mode('foo') == mode('bar')

    finally:
        run_as_root('rmdir foo bar')
コード例 #7
0
ファイル: test_files.py プロジェクト: xlqian/fabtools
def test_permissions():

    from fabtools.files import owner, group, mode
    from fabtools.require.files import directory as require_directory

    try:
        run_as_root('mkdir foo')
        require_directory('bar', use_sudo=True)

        assert owner('foo') == owner('bar')
        assert group('foo') == group('bar')
        assert mode('foo') == mode('bar')

    finally:
        run_as_root('rmdir foo bar')
コード例 #8
0
ファイル: oracle_jdk.py プロジェクト: manojlds/fabtools
def install_from_oracle_site(version=DEFAULT_VERSION):
    """
    Download tarball from Oracle site and install JDK.

    ::

        import fabtools

        # Install Oracle JDK
        fabtools.oracle_jdk.install_from_oracle_site()

    """

    release, build = version.split('-')
    major, update = release.split('u')
    if len(update) == 1:
        update = '0' + update

    jdk_arch = _required_jdk_arch()

    jdk_filename = 'jdk-%(release)s-linux-%(jdk_arch)s.tar.gz' % locals()
    jdk_dir = 'jdk1.%(major)s.0_%(update)s' % locals()

    jdk_url = 'http://download.oracle.com/otn-pub/java/jdk/' +\
              '%(version)s/%(jdk_filename)s' % locals()

    with cd('/tmp'):
        run('rm -rf %s' % jdk_filename)
        run('wget --no-cookies --header="Cookie: gpw_e24=a" ' +
            '--progress=dot:mega ' +
            '%(jdk_url)s -O /tmp/%(jdk_filename)s' % locals())

    require_directory('/opt', mode='777', use_sudo=True)
    with cd('/opt'):
        run('tar -xzvf /tmp/%s' % jdk_filename)
        run('ln -s %s jdk' % jdk_dir)

    _create_profile_d_file()
コード例 #9
0
ファイル: test_apache.py プロジェクト: zloy531/fabtools3
def example_site():
    from fabtools.require.apache import site as require_site
    from fabtools.require.files import directory as require_directory
    from fabtools.require.files import file as require_file

    site_name = 'example.com'

    site_dir = posixpath.join('/var/www', site_name)
    require_directory(site_dir, use_sudo=True)

    site_homepage = posixpath.join(site_dir, 'index.html')
    require_file(site_homepage, contents="example page", use_sudo=True)

    site_config_path = '/etc/apache2/sites-available/{0}.conf'.format(
        site_name)
    site_link_path = '/etc/apache2/sites-enabled/{0}.conf'.format(site_name)
    require_file(site_config_path, use_sudo=True)

    require_site(
        site_name,
        template_contents=dedent("""\
            <VirtualHost *:%(port)s>
                ServerName %(hostname)s
                DocumentRoot %(document_root)s
                <Directory %(document_root)s>
                </Directory>
            </VirtualHost>
        """),
        port=80,
        hostname=site_name,
        document_root=site_dir,
    )

    yield site_name

    sudo('rm -rf {0}'.format(quote(site_dir)))
    sudo('rm -f {0}'.format(quote(site_config_path)))
    sudo('rm -f {0}'.format(quote(site_link_path)))
コード例 #10
0
ファイル: test_apache.py プロジェクト: 26lights/fabtools
def example_site():
    from fabtools.require.apache import site as require_site
    from fabtools.require.files import directory as require_directory
    from fabtools.require.files import file as require_file

    site_name = 'example.com'

    site_dir = posixpath.join('/var/www', site_name)
    require_directory(site_dir, use_sudo=True)

    site_homepage = posixpath.join(site_dir, 'index.html')
    require_file(site_homepage, contents="example page", use_sudo=True)

    site_config_path = '/etc/apache2/sites-available/{0}.conf'.format(site_name)
    site_link_path = '/etc/apache2/sites-enabled/{0}.conf'.format(site_name)
    require_file(site_config_path, use_sudo=True)

    require_site(
        site_name,
        template_contents=dedent("""\
            <VirtualHost *:%(port)s>
                ServerName %(hostname)s
                DocumentRoot %(document_root)s
                <Directory %(document_root)s>
                </Directory>
            </VirtualHost>
        """),
        port=80,
        hostname=site_name,
        document_root=site_dir,
    )

    yield site_name

    sudo('rm -rf {0}'.format(quote(site_dir)))
    sudo('rm -f {0}'.format(quote(site_config_path)))
    sudo('rm -f {0}'.format(quote(site_link_path)))
コード例 #11
0
ファイル: tomcat.py プロジェクト: ajeebkp23/fabtools
def install_from_source(path=DEFAULT_INSTALLATION_PATH,
                        version=DEFAULT_VERSION,
                        mirror=DEFAULT_MIRROR,
                        overwrite=False):
    """
    Install Tomcat from source.

    ::

        import fabtools

        # Install Tomcat
        fabtools.tomcat.install_from_source(version='6.0.36')

    """
    from fabtools.require import file as require_file
    from fabtools.require.files import directory as require_directory

    # Tokenize version into parts
    version_tokens = version.split('.')
    version_major = version_tokens[0]

    # Parse the filename and folder
    file_name = 'apache-tomcat-%s.tar.gz' % version
    folder_name = 'apache-tomcat-%s' % version

    # Build the distribution in /tmp
    with cd('/tmp'):
        # Make sure we have the tarball downloaded.
        if not is_file(os.path.join('/tmp/', file_name)):
            # Otherwise, download the tarball based on our mirror and version.
            tomcat_url = '%s/dist/tomcat/tomcat-%s/v%s/bin/%s' % (mirror, version_major, version, file_name)

            # Ensure the file has been downloaded
            require_file(url=tomcat_url)

        # Extract the file
        run('tar -xzf %s' % file_name)

        # Handle possibility of existing path
        if is_dir(path):
            if overwrite is False:
                # Raise exception as we don't want to overwrite
                raise OSError("Path %s already exists and overwrite not set." % path)
            else:
                # Otherwise, backup the tomcat path
                backup_installation_path = path + ".backup"
                if is_dir(backup_installation_path):
                    run_as_root("rm -rf %s" % backup_installation_path)
                run_as_root("mv %s %s" % (path, backup_installation_path))

        """
        After all that, let's ensure we have the installation path setup
        properly and place the install.
        """
        require_directory(path, mode='755', use_sudo=True)
        run_as_root('mv %s/* %s' % (folder_name, path))

        # Now cleanup temp.
        run("rm -rf %s*" % file_name)

    # Finally, configure and start Tomcat
    configure_tomcat(path, overwrite=overwrite)
    start_tomcat()
コード例 #12
0
def install_from_source(path=DEFAULT_INSTALLATION_PATH,
                        version=DEFAULT_VERSION,
                        mirror=DEFAULT_MIRROR,
                        overwrite=False):
    """
    Install Tomcat from source.

    ::

        import fabtools

        # Install Tomcat
        fabtools.tomcat.install_from_source(version='6.0.36')

    """
    from fabtools.require import file as require_file
    from fabtools.require.files import directory as require_directory

    # Tokenize version into parts
    version_tokens = version.split('.')
    version_major = version_tokens[0]

    # Parse the filename and folder
    file_name = 'apache-tomcat-%s.tar.gz' % version
    folder_name = 'apache-tomcat-%s' % version

    # Build the distribution in /tmp
    with cd('/tmp'):
        # Make sure we have the tarball downloaded.
        if not is_file(os.path.join('/tmp/', file_name)):
            # Otherwise, download the tarball based on our mirror and version.
            tomcat_url = '%s/dist/tomcat/tomcat-%s/v%s/bin/%s' % (
                mirror, version_major, version, file_name)

            # Ensure the file has been downloaded
            require_file(url=tomcat_url)

        # Extract the file
        run('tar -xzf %s' % file_name)

        # Handle possibility of existing path
        if is_dir(path):
            if overwrite is False:
                # Raise exception as we don't want to overwrite
                raise OSError("Path %s already exists and overwrite not set." %
                              path)
            else:
                # Otherwise, backup the tomcat path
                backup_installation_path = path + ".backup"
                if is_dir(backup_installation_path):
                    run_as_root("rm -rf %s" % backup_installation_path)
                run_as_root("mv %s %s" % (path, backup_installation_path))
        """
        After all that, let's ensure we have the installation path setup
        properly and place the install.
        """
        require_directory(path, mode='755', use_sudo=True)
        run_as_root('mv %s/* %s' % (folder_name, path))

        # Now cleanup temp.
        run("rm -rf %s*" % file_name)

    # Finally, configure and start Tomcat
    configure_tomcat(path, overwrite=overwrite)
    start_tomcat()