示例#1
0
import commands
import random
import md5


class RSHRemoteCommand(RemoteCommand):
    "RSH remote execution class"

    def __init__(self, destination, params):
        self.rshpath = params['rsh_path']
        self.user = params['user']
        RemoteCommand.__init__(self, destination, params)
        self.delim = md5.md5(str(random.random())).hexdigest()

    def _rexec(self, command):
        s = '%s -l %s %s "%s; echo %s \\$?"' % (
            self.rshpath, self.user, self.destination, command, self.delim)
        t1 = time.time()
        ol = commands.getoutput(s).split('\n')
        for linenumber, line in enumerate(ol):
            i = line.find(self.delim)
            if i != -1:
                status = line.split(' ')[1]
                ol.pop(linenumber)
                break
        self.duration = time.time() - t1
        return (int(status), '\n'.join(ol))


registerRemoteCommandPlugin('rsh', RSHRemoteCommand)
示例#2
0
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from lekatnet.remote import registerRemoteCommandPlugin
from lekatnet.remote import RemoteCommand
import time
import commands


class SSHRemoteCommand(RemoteCommand):
    "SSH remote execution class"

    def __init__(self, destination, params):
        self.sshpath = params['ssh_path']
        self.user = params['user']
        RemoteCommand.__init__(self, destination, params)

    def _rexec(self, command):
        s = '%s %s@%s "%s"' % (self.sshpath, self.user, self.destination,
                               command)
        t1 = time.time()
        status, output = commands.getstatusoutput(s)
        self.duration = time.time() - t1
        # shift 8 bits right to strip signal number from status
        return (status >> 8, output)


registerRemoteCommandPlugin('ssh', SSHRemoteCommand)
示例#3
0
			# (e.g., the node is overloaded, sshd is hung, etc.)
			#
			# sock.recv() should return something like:
			#
			#	SSH-2.0-OpenSSH_4.3
			#
			buf = sock.recv(64)
		except socket.error:
			self.duration = time.time() - t1
			return (-1, 'down')

		# SSH to the machine
		ssh_dest = '%s@%s' % (self.user, self.destination)
		try:
			p = pexpect.spawn(self.sshpath, [ssh_dest, command])
			p.expect(pexpect.EOF, self.timeout)
			output = p.before
			status = 0
		except pexpect.TIMEOUT, e:
			output = "Remote command timed out on host %s" % \
				self.destination
			status = 1

		p.close()

		self.duration = time.time() - t1
		return (status >> 8, output)


registerRemoteCommandPlugin('rocks', RocksSSHRemoteCommand)
示例#4
0
			# (e.g., the node is overloaded, sshd is hung, etc.)
			#
			# sock.recv() should return something like:
			#
			#	SSH-2.0-OpenSSH_4.3
			#
			buf = sock.recv(64)
		except socket.error:
			self.duration = time.time() - t1
			return (-1, 'down')

		# SSH to the machine
		ssh_dest = '%s@%s' % (self.user, self.destination)
		try:
			p = pexpect.spawn(self.sshpath, [ssh_dest, command])
			p.expect(pexpect.EOF, self.timeout)
			output = p.before
			status = 0
		except pexpect.TIMEOUT, e:
			output = "Remote command timed out on host %s" % \
				self.destination
			status = 1

		p.close()

		self.duration = time.time() - t1
		return (status >> 8, output)


registerRemoteCommandPlugin('rocks', RocksSSHRemoteCommand)
示例#5
0
文件: rsh.py 项目: jeramirez/base
import commands
import random
try:
	from hashlib import md5
except ImportError:
	from md5 import md5

class RSHRemoteCommand(RemoteCommand):
	"RSH remote execution class"

	def __init__(self, destination, params):
		self.rshpath = params['rsh_path']
		self.user = params['user']
		RemoteCommand.__init__(self, destination, params)
		self.delim = md5.md5(str(random.random())).hexdigest()

	def _rexec(self, command):
		s = '%s -l %s %s "%s; echo %s \\$?"' % (self.rshpath, self.user, self.destination, command,self.delim)
		t1 = time.time()
		ol = commands.getoutput(s).split('\n')
		for linenumber, line in enumerate(ol):
			i = line.find(self.delim)
			if i != -1:
				status = line.split(' ')[1]
				ol.pop(linenumber)
				break
		self.duration = time.time() - t1
		return (int(status), '\n'.join(ol))

registerRemoteCommandPlugin('rsh', RSHRemoteCommand)
示例#6
0
文件: ssh.py 项目: vietjovi/tentakel
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from lekatnet.remote import registerRemoteCommandPlugin
from lekatnet.remote import RemoteCommand
import time
import commands

class SSHRemoteCommand(RemoteCommand):
	"SSH remote execution class"

	def __init__(self, destination, params):
		self.sshpath = params['ssh_path']
		self.user = params['user']
		RemoteCommand.__init__(self, destination, params)

	def _rexec(self, command):
		s = '%s %s@%s "%s"' % (self.sshpath, self.user, self.destination, command)
		t1 = time.time()
		status, output = commands.getstatusoutput(s)
		self.duration = time.time() - t1
		# shift 8 bits right to strip signal number from status
		return (status >> 8, output)

registerRemoteCommandPlugin('ssh', SSHRemoteCommand)