summaryrefslogtreecommitdiffstats
path: root/func/minion/modules/netapp/common.py
blob: d041336c798a7f169e20045cb04f7b0ef6c28735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import subprocess 

SSH = '/usr/bin/ssh'

class GenericSSHError(Exception): pass
class NetappCommandError(Exception): pass
class NetappNotImplementedError(Exception): pass

def ssh(user, host, command):
    cmd = subprocess.Popen([SSH, "%s@%s" % (user, host), command], 
                           executable=SSH,
                           stdin=subprocess.PIPE,
                           stdout=subprocess.PIPE, 
                           stderr=subprocess.PIPE,
                           shell=False)

    (out, err) = cmd.communicate()
    if cmd.wait() != 0:
        raise GenericSSHError, err
    else:
        return out