コード例 #1
0
ファイル: __init__.py プロジェクト: evankyle/ceph-deploy
def get(hostname, fallback=None):
    """
    Retrieve the module that matches the distribution of a ``hostname``. This
    function will connect to that host and retrieve the distribution
    informaiton, then return the appropriate module and slap a few attributes
    to that module defining the information it found from the hostname.

    For example, if host ``node1.example.com`` is an Ubuntu server, the
    ``debian`` module would be returned and the following would be set::

        module.name = 'ubuntu'
        module.release = '12.04'
        module.codename = 'precise'

    :param hostname: A hostname that is reachable/resolvable over the network
    :param fallback: Optional fallback to use if no supported distro is found
    """
    sudo_conn = pushy.connect(get_transport(hostname))
    (distro, release, codename) = lsb.get_lsb_release(sudo_conn)

    module = _get_distro(distro)
    module.name = distro
    module.release = release
    module.codename = codename
    module.sudo_conn = sudo_conn
    module.init = lsb.choose_init(distro, codename)
    return module
コード例 #2
0
ファイル: jpushy.py プロジェクト: isabella232/pushy
    def connect(self, address, kwargs):
        "Register a host for connecting to."

        assert self.__connection is None
        kwargs = self.__unwrap(None, kwargs)[1]
        import pushy
        self.__connection = pushy.connect(address, **kwargs)
コード例 #3
0
ファイル: jpushy.py プロジェクト: alfredodeza/pushy
    def connect(self, address, kwargs):
        "Register a host for connecting to."

        assert self.__connection is None
        kwargs = self.__unwrap(None, kwargs)[1]
        import pushy
        self.__connection = pushy.connect(address, **kwargs) 
コード例 #4
0
ファイル: __init__.py プロジェクト: rmoe/ceph-deploy
def get(hostname, fallback=None):
    """
    Retrieve the module that matches the distribution of a ``hostname``. This
    function will connect to that host and retrieve the distribution
    informaiton, then return the appropriate module and slap a few attributes
    to that module defining the information it found from the hostname.

    For example, if host ``node1.example.com`` is an Ubuntu server, the
    ``debian`` module would be returned and the following would be set::

        module.name = 'ubuntu'
        module.release = '12.04'
        module.codename = 'precise'

    :param hostname: A hostname that is reachable/resolvable over the network
    :param fallback: Optional fallback to use if no supported distro is found
    """
    sudo_conn = pushy.connect(get_transport(hostname))
    (distro, release, codename) = lsb.get_lsb_release(sudo_conn)

    module = _get_distro(distro)
    module.name = distro
    module.release = release
    module.codename = codename
    module.sudo_conn = sudo_conn
    module.init = lsb.choose_init(distro, codename)
    return module
コード例 #5
0
ファイル: common.py プロジェクト: alfredodeza/pushy
def get_connection():
    (options, args) = parse_args()
    username = options.username
    password = options.password
    python   = options.python
    if options.ask_password:
        if options.password is not None:
            import warnings
            warnings.warn(
                "--ask-password and --password were both specified: " +\
                "ignoring specified password")
        import getpass
        password = getpass.getpass()
    return pushy.connect(args[0], username=username, password=password,
                         python=python)
コード例 #6
0
def remote_import(name, python="python"):
    """
    A Fabric operation for importing and returning a reference to a remote
    Python package.
    """

    if (env.host_string, python) in connections:
        conn = connections[(env.host_string, python)]
    else:
        conn = pushy.connect("fabric:", python=python)
        connections[(env.host_string, python)] = conn
    m = getattr(conn.modules, name)
    if "." in name:
        for p in name.split(".")[1:]:
            m = getattr(m, p)
    return m
コード例 #7
0
ファイル: common.py プロジェクト: isabella232/pushy
def get_connection():
    (options, args) = parse_args()
    username = options.username
    password = options.password
    python = options.python
    if options.ask_password:
        if options.password is not None:
            import warnings
            warnings.warn(
                "--ask-password and --password were both specified: " +\
                "ignoring specified password")
        import getpass
        password = getpass.getpass()
    return pushy.connect(args[0],
                         username=username,
                         password=password,
                         python=python)
コード例 #8
0
def retrieve_machine_info():
    cache_file = "/tmp/supermegazord/machines.json"

    machines = None
    group_aliases = None

    try:
        with pushy.connect("ssh:megazord", username="******") as conn:
            smz_machines = conn.modules.supermegazord.db.machines

            # Bring data locally so we can close the connection
            machines = {}
            for group, group_machines in smz_machines.machines.items():
                machines[group] = list(machine.hostname
                                       for machine in group_machines)

            group_aliases = {}
            for group, aliases in smz_machines.group_aliases().items():
                group_aliases[group] = list(aliases)
    except:
        sys.stderr.write("Failed to retrieve machine list from megazord, trying local cache...\n")
        
        try:
            with open(cache_file) as fp:
                data = json.load(fp)
            
            machines = data['machines'] # must exist
            group_aliases = data.get('group_aliases', None) # may exist
        except:
            sys.stderr.write("Cache load failed, cannot classify node!")
            return None, None
    else:
        create_directory(os.path.dirname(cache_file))

        try:
            with open(cache_file, 'w') as fp:
                json.dump({'machines': machines, 'group_aliases': group_aliases}, fp)
        except Exception as e:
            sys.stderr.write("Failed to update cache: " + str(e) + "n")
        else:
            sys.stderr.write("Updated machine cache.\n")

    return machines, group_aliases
コード例 #9
0
ファイル: __init__.py プロジェクト: vmalloc/asset_tracker
def _initialize_pushy():
    global _pushy_conn
    _pushy_conn = pushy.connect(
        "ssh:127.0.0.1", port=2222, username="******", use_native=False,
        key_filename=os.path.expanduser("~/.vagrant.d/insecure_private_key")
    )
コード例 #10
0
 def setUp(self):
     self.conn = pushy.connect("local:")
コード例 #11
0
ファイル: test_class.py プロジェクト: alfredodeza/pushy
 def setUp(self):
     self.conn = pushy.connect("local:")
コード例 #12
0
                           members=','.join(machine.hostname
                                            for machine in members))

def host_format(name):
    template = """
define host {{
    host_name    {name}
    alias        {alias}
    address      {address}
    use          redelinux-host
}}
"""
    fqdn = name + ".linux.ime.usp.br"
    return template.format(name=name, alias=name, address=fqdn)

with pushy.connect("ssh:megazord", username="******") as conn:
    machines = conn.modules.supermegazord.db.machines

    groups = machines.group_aliases().keys()

    groups_content = ''
    hosts_content = ''
    
    for group in groups:
        group_machines = machines.list(group)

        groups_content += group_format(group, group_machines)
        hosts_content += ''.join(host_format(machine.hostname)
                                 for machine in group_machines) + "\n"

    print groups_content
コード例 #13
0
ファイル: main.py プロジェクト: 5ghz/test
    host_dict = dict(
        (n, v) for n, v in (a.split('=') for a in host_record.split()))
    ssh_host = host_dict.get("host", "127.0.0.1")
    ssh_pass = host_dict.get("password", "qwerty")
    ssh_user = host_dict.get("user", "root")
    ssh_port = host_dict.get("port", 22)
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    #    print ssh_host, ssh_pass, ssh_user, ssh_port
    ssh.connect(ssh_host,
                port=int(ssh_port),
                username=ssh_user,
                password=ssh_pass)
    conn = pushy.connect("ssh:" + ssh_host,
                         username=ssh_user,
                         password=ssh_pass,
                         port=int(ssh_port),
                         missing_host_key_policy="autoadd")
    myarray = {}
    userlist = []
    userhome = []
    sources = {}
    userkey = {}
    sftp_client = ssh.open_sftp()

    remote_file = sftp_client.open('/etc/ssh/sshd_config')
    try:
        for line in remote_file:
            if not (re.findall(r'^#', line)) and not (re.findall(r'^$', line)):
                line = line.rstrip('\n')
                key = re.split(' |\t', line, 1)[0]
コード例 #14
0
ファイル: host.py プロジェクト: vmalloc/asset_tracker
 def _get_connection(self):
     return pushy.connect(self._hostname, **self._pushy_kwargs)
コード例 #15
0
import pushy
import notmuch as notmuch_local
import pushy.protocol.proxy
from ConfigParser import ConfigParser
from time import sleep
import os as os_local

conf = ConfigParser(allow_no_value=True)
conf.read(os_local.path.expanduser('~/.notmuch-pushy-config'))

host = conf.get('remote', 'host')
conn = pushy.connect('ssh:' + host)
notmuch_remote = conn.modules.notmuch
os_remote = conn.modules.os
local_sync_tag = conf.get('tags', 'local') or 'sync-to-server'
remote_sync_tag = conf.get('tags', 'remote') or 'sync-to-laptop'


def get_db_rw(notmuch):
    return notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)


def get_db_rw_retry(notmuch):
    try:
        return get_db_rw(notmuch)
    except notmuch.errors.XapianError:
        sleep(5)
        return get_db_rw(notmuch)


def get_messages_to_sync(db, tag):