Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: dbbfea7f49
Fetching contributors…

Cannot retrieve contributors at this time

188 lines (169 sloc) 7.206 kB
"""Configuration details for specific server types.
This module contains functions that help with initializing a Fabric environment
for standard server types.
import os
import subprocess
from fabric.api import env, run, sudo
def _setup_distribution_environment():
"""Setup distribution environment
""""Distribution %s" % env.distribution)
if env.hosts == ["vagrant"]:
elif env.hosts == ["localhost"]:
if env.distribution == "ubuntu":
elif env.distribution == "centos":
elif env.distribution == "scientificlinux":
elif env.distribution == "debian":
raise ValueError("Unexpected distribution %s" % env.distribution)
# allow us to check for packages only available on 64bit machines
machine = run("uname -m")
env.is_64bit = machine.find("_64") > 0
def _configure_sudo(env):
"""Setup env variable and safe_sudo supporting non-privileged users.
if getattr(env, "use_sudo", "true").lower() in ["true", "yes"]:
env.safe_sudo = sudo
env.use_sudo = True
env.safe_sudo = run
env.use_sudo = False
def _cloudman_compatibility(env):
"""Environmental variable naming for compatibility with CloudMan.
env.install_dir = env.system_install
def _validate_target_distribution(dist):
"""Check target matches environment setting (for sanity)
Throws exception on error
env.logger.debug("Checking target distribution " + env.distribution)
if dist in ["debian", "ubuntu"]:
tag = run("cat /proc/version")
if tag.lower().find(dist) == -1:
# hmmm, test issue file
tag2 = run("cat /etc/issue")
if tag2.lower().find(dist) == -1:
raise ValueError("Distribution does not match machine; are you using correct fabconfig for " + dist)
env.logger.debug("Unknown target distro")
def _setup_ubuntu():"Ubuntu setup")
shared_sources = _setup_deb_general()
# package information. This is ubuntu/debian based and could be generalized.
sources = [
"deb %s universe", # unsupported repos
"deb %s multiverse",
"deb %s-updates universe",
"deb %s-updates multiverse",
"deb %s partner", # partner repositories
"deb dist 10gen", # mongodb
"deb %s/", # lastest R versions
"deb maverick-cdh3 contrib", # Hadoop
"deb %s partner", # sun-java
"deb %s main", # Free-NX
"deb %s main", # Free-NX
] + shared_sources
env.std_sources = _add_source_versions(env.dist_name, sources)
def _setup_debian():"Debian setup")
unstable_remap = {"sid": "squeeze"}
shared_sources = _setup_deb_general()
sources = [
"deb dist 10gen", # mongodb
"deb %s/", # lastest R versions
"deb lenny-cdh3 contrib" # Hadoop
] + shared_sources
# fill in %s
dist_name = unstable_remap.get(env.dist_name, env.dist_name)
env.std_sources = _add_source_versions(dist_name, sources)
def _setup_deb_general():
"""Shared settings for different debian based/derived distributions.
env.logger.debug("Debian-shared setup")
env.sources_file = "/etc/apt/sources.list.d/cloudbiolinux.list"
env.global_sources_file = "/etc/apt/sources.list"
env.apt_preferences_file = "/etc/apt/preferences"
env.python_version_ext = ""
env.ruby_version_ext = "1.9.1"
if not env.has_key("java_home"):
# XXX look for a way to find JAVA_HOME automatically
env.java_home = "/usr/lib/jvm/java-6-openjdk"
shared_sources = [
"deb unstable bio-linux", # Bio-Linux
"deb %s contrib", # virtualbox
return shared_sources
def _setup_centos():"CentOS setup")
env.python_version_ext = "2.6"
env.ruby_version_ext = ""
if not env.has_key("java_home"):
env.java_home = "/etc/alternatives/java_sdk"
def _setup_scientificlinux():"ScientificLinux setup")
env.python_version_ext = ""
env.pip_cmd = "pip-python"
if not env.has_key("java_home"):
env.java_home = "/etc/alternatives/java_sdk"
def _setup_nixpkgs():
# for now, Nix packages are only supported in Debian - it can
# easily be done for others - just get Nix installed from the .rpm
nixpkgs = False
if env.has_key("nixpkgs"):
if env.distribution in ["debian", "ubuntu"]:
if env.nixpkgs == "True":
nixpkgs = True
nixpkgs = False
env.logger.warn("NixPkgs are currently not supported for " + env.distribution)
if nixpkgs:"NixPkgs: supported")
env.logger.debug("NixPkgs: Ignored")
env.nixpkgs = nixpkgs
def _setup_local_environment():
"""Setup a localhost environment based on system variables.
""""Get local environment")
if not env.has_key("user"):
env.user = os.environ["USER"]
if not env.has_key("java_home"):
env.java_home = os.environ.get("JAVA_HOME", "/usr/lib/jvm/java-6-openjdk")
def _setup_vagrant_environment():
"""Use vagrant commands to get connection information.
""""Get vagrant environment")
raw_ssh_config = subprocess.Popen(["vagrant", "ssh-config"],
ssh_config = dict([l.strip().split() for l in raw_ssh_config.split("\n") if l])
env.user = ssh_config["User"]
env.hosts = [ssh_config["HostName"]]
env.port = ssh_config["Port"]
env.host_string = "%s@%s:%s" % (env.user, env.hosts[0], env.port)
env.key_filename = ssh_config["IdentityFile"]
env.logger.debug("ssh %s" % env.host_string)
def _add_source_versions(version, sources):
"""Patch package source strings for version, e.g. Debian 'stable'
name = version
env.logger.debug("Source=%s" % name)
final = []
for s in sources:
if s.find("%s") > 0:
s = s % name
return final
Jump to Line
Something went wrong with that request. Please try again.