2 ## NetApp Filer 'common' Module
4 ## Copyright 2008, Red Hat, Inc
5 ## John Eckersberg <jeckersb@redhat.com>
7 ## This software may be freely redistributed under the terms of the GNU
8 ## general public license.
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.
20 SSH_OPTS
= '-o forwardagent=no'
21 class GenericSSHError(Exception): pass
22 class NetappCommandError(Exception): pass
24 def ssh(host
, cmdargs
, input=None, user
=SSH_USER
):
25 cmdline
= [SSH
, SSH_OPTS
, "%s@%s" % (user
, host
)]
26 cmdline
.extend(cmdargs
)
28 cmd
= sub_process
.Popen(cmdline
,
30 stdin
=sub_process
.PIPE
,
31 stdout
=sub_process
.PIPE
,
32 stderr
=sub_process
.PIPE
,
35 (out
, err
) = cmd
.communicate(input)
38 raise GenericSSHError
, err
42 def check_output(regex
, output
):
44 output
= output
.replace('\n', ' ')
45 if re
.search(regex
, output
):
48 raise NetappCommandError
, output