Ejemplo n.º 1
0
    :type password: str
    :param password: the password to be used with sudo if required. If not
        set then try to use the defined one in the mico environment as
        ``sudo_password``, if set to empty string, then never use password.
    """
    if password is None:
        return env.get(ENV_KEY_SUDO_PASSWORD, None)
    else:
        if not password:
            del env[ENV_KEY_SUDO_PASSWORD]
        else:
            env[ENV_KEY_SUDO_PASSWORD] = password


mode_sudo = Switcher.from_key(ENV_KEY_SUDO_MODE, True)


def is_sudo():
    """Return true if the current execution mode is sudo-enabled"""
    return mode_sudo.getValue(ENV_KEY_SUDO_MODE)


def sudo(*args, **kwargs):
    """A wrapper to Fabric's run/sudo commands, using the
    mode_sudo global to tell whether the command should be run as
    regular user or sudo.
    """
    with mode_sudo():
        return run(*args, **kwargs)[0]
Ejemplo n.º 2
0
    :type var: dict
    :param var: a dictionary to use as environment for template
    """

    jinja_env = Environment(loader=FileSystemLoader([os.path.dirname(src)]))
    jinja_tpl = jinja_env.get_template(os.path.basename(src))

    local_env = dict([(k, v) for (k, v) in __builtin__.env.items()])
    local_env.update(var)

    content = jinja_tpl.render(**local_env)
    return content


from mico.util.switch import Switcher
mode_local = Switcher.from_key("mode_local", True)


def is_local():
    """Return True if the execution is running in local host."""
    return mode_local.getValue("mode_local")


def is_remote():
    """Return True if the execution is running in remote host."""
    return not is_local()


import subprocess
from fabric import operations
from StringIO import StringIO
Ejemplo n.º 3
0
def sudo_password(password=None):
    """Set the password to be used with sudo

    :type password: str
    :param password: the password to be used with sudo if required. If not
        set then try to use the defined one in the mico environment as
        ``sudo_password``, if set to empty string, then never use password.
    """
    if password is None:
        return env.get(ENV_KEY_SUDO_PASSWORD, None)
    else:
        if not password:
            del env[ENV_KEY_SUDO_PASSWORD]
        else:
            env[ENV_KEY_SUDO_PASSWORD] = password

mode_sudo = Switcher.from_key(ENV_KEY_SUDO_MODE, True)

def is_sudo():
    """Return true if the current execution mode is sudo-enabled"""
    return mode_sudo.getValue(ENV_KEY_SUDO_MODE)

def sudo(*args, **kwargs):
    """A wrapper to Fabric's run/sudo commands, using the
    mode_sudo global to tell whether the command should be run as
    regular user or sudo.
    """
    with mode_sudo():
        return run(*args, **kwargs)[0]