Misc s/func/certmaster/ replacements
[certmaster.git] / certmaster / minion / modules / netapp / common.py
1 ##
2 ## NetApp Filer 'common' Module
3 ##
4 ## Copyright 2008, Red Hat, Inc
5 ## John Eckersberg <jeckersb@redhat.com>
6 ##
7 ## This software may be freely redistributed under the terms of the GNU
8 ## general public license.
9 ##
10 ## You should have received a copy of the GNU General Public License
11 ## along with this program; if not, write to the Free Software
12 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 ##
14
15 import re
16 import sub_process
17
18 SSH = '/usr/bin/ssh'
19 SSH_USER = 'root'
20 SSH_OPTS = '-o forwardagent=no'
21 class GenericSSHError(Exception): pass
22 class NetappCommandError(Exception): pass
23
24 def ssh(host, cmdargs, input=None, user=SSH_USER):
25 cmdline = [SSH, SSH_OPTS, "%s@%s" % (user, host)]
26 cmdline.extend(cmdargs)
27
28 cmd = sub_process.Popen(cmdline,
29 executable=SSH,
30 stdin=sub_process.PIPE,
31 stdout=sub_process.PIPE,
32 stderr=sub_process.PIPE,
33 shell=False)
34
35 (out, err) = cmd.communicate(input)
36
37 if cmd.wait() != 0:
38 raise GenericSSHError, err
39 else:
40 return out + err
41
42 def check_output(regex, output):
43 #strip newlines
44 output = output.replace('\n', ' ')
45 if re.search(regex, output):
46 return True
47 else:
48 raise NetappCommandError, output
49