Esempio n. 1
0
def shell_command(request):
    """Sends a shell command to a machine over ssh, using fabric.

    .. note:: Used for uptime only.

    """
    try:
        conn = connect(request)
    except:
        return Response('Backend not found', 404)

    machine_id = request.matchdict['machine']
    backend_id = request.matchdict['backend']
    host = request.params.get('host', None)
    ssh_user = request.params.get('ssh_user', None)
    command = request.params.get('command', None)

    if not ssh_user or ssh_user == 'undefined':
        ssh_user = '******'

    try:
        keypairs = request.environ['beaker.session']['keypairs']
    except:
        keypairs = request.registry.settings.get('keypairs', {})

    keypair = get_keypair(keypairs, backend_id, machine_id)

    if keypair:
        private_key = keypair['private']
        public_key = keypair['public']
    else:
        private_key = public_key = None

    ret = run_command(conn, machine_id, host, ssh_user, private_key, command)
    return ret
Esempio n. 2
0
def shell_command(request):
    """Sends a shell command to a machine over ssh, using fabric.

    .. note:: Used for uptime only.

    """
    try:
        conn = connect(request)
    except:
        return Response("Backend not found", 404)

    machine_id = request.matchdict["machine"]
    backend_id = request.matchdict["backend"]
    host = request.params.get("host", None)
    ssh_user = request.params.get("ssh_user", None)
    command = request.params.get("command", None)

    if not ssh_user or ssh_user == "undefined":
        ssh_user = "******"

    try:
        keypairs = request.environ["beaker.session"]["keypairs"]
    except:
        keypairs = request.registry.settings.get("keypairs", {})

    keypair = get_keypair(keypairs, backend_id, machine_id)

    if keypair:
        private_key = keypair["private"]
        public_key = keypair["public"]
    else:
        private_key = public_key = None

    ret = run_command(conn, machine_id, host, ssh_user, private_key, command)
    return ret
Esempio n. 3
0
def shell_command(request):
    """Send a shell command to a machine over ssh, using fabric."""
    try:
        conn = connect(request)
    except:
        return Response('Backend not found', 404)

    machine_id = request.matchdict['machine']
    backend_id = request.matchdict['backend']
    host = request.params.get('host', None)
    ssh_user = request.params.get('ssh_user', None)
    command = request.params.get('command', None)

    if not ssh_user or ssh_user == 'undefined':
        ssh_user = '******'

    try:
        keypairs = request.environ['beaker.session']['keypairs']
    except:
        keypairs = request.registry.settings.get('keypairs', {})

    keypair = get_keypair(keypairs, backend_id, machine_id)

    if keypair:
        private_key = keypair['private']
        public_key = keypair['public']
    else:
        private_key = public_key = None

    return run_command(conn, machine_id, host, ssh_user, private_key, command)