import utils
import os
+import re
from Remote import Remote
from Table import Table
'plcs': ['TestPLC'],
'hostname': None, # Node Hostname
'host': 'localhost', # host where node lives
- 'redir_port': None, # Port on host where ssh is redirected to virtual node
+ 'redir_ssh_port': '51022', # Port on host where ssh is redirected to virtual node
'vserver': None, # vserver where this node lives
'type': 'vm', # type of node
'model': '/minhw',
'nodenetworks': [], # node networks
'homedir': '/var/VirtualMachines/',
- 'rootkey': None # path to root ssh key
+ 'rootkey': None, # path to root ssh key
+ 'host_rootkey': None
}
def __init__(self, config, fields = {}):
self.update(fields)
self.config = config
+ get_host_command = Remote.get_remote_command
+
+ def get_remote_command(self, command, user = 'root', key = None):
+ if key is None:
+ key = self['rootkey']
+ options = " -q "
+ options += " -o StrictHostKeyChecking=no "
+ options += " -i %(key)s" % locals()
+ host = self['hostname']
+ if 'type' in self and self['type'] in ['vm']:
+ if 'redir_ssh_port' in self and self['redir_ssh_port']:
+ options += " -p %s " % self['redir_ssh_port']
+ ip_command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
+ (status, output) = self.host_commands(ip_command)
+ host = re.findall(r'[0-9\.]+', output)[0]
+
+ command = "ssh %(options)s %(user)s@%(host)s \'%(command)s\'" % locals()
+ return self.get_host_command(command)
+
+
def host_popen(self, command, fatal = True):
command = self.get_host_command(command)
return utils.popen(command, fatal, self.config.verbose)
def host_commands(self, command, fatal = True):
command = self.get_host_command(command)
return utils.commands(command, fatal, self.config.verbose)
+
class Nodes(list, Table):
return path
def get_command(self, command):
- options = " -o StrictHostKeyChecking=no "
# Chroot if necessary
if 'chroot' in self and self['chroot']:
command = " chroot %s %s" % (self['chroot'], command)
if 'vserver' in self and self['vserver']:
command = " vserver %s exec %s " % (self['vserver'], command)
- # Use root key if necessary
- if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
- if 'rootkey' in self and self['rootkey']:
- options += " -i %s " % self['rootkey']
-
- return (command, options)
-
- def get_host_command(self, command):
- (command, options) = self.get_command(command)
- if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
- command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
return command
def get_remote_command(self, command):
- (command, options) = self.get_command(command)
- if 'type' in self and self['type'] in ['vm']:
- if 'redir_port' in self and self['redir_port']:
- options += " -p %s " % self['redir_port']
-
- # attempt ssh self['host'] is not the machine we are running on or
- # if this is a virtual node
- if 'host' in self and self['host'] not in ['localhost', self.config.hostname] or \
- 'type' in self and self['type'] in ['vm']:
+ (command) = self.get_command(command)
+
+ if 'host' in self and self['host'] not in ['localhost', self.config.hostname, self.config.ip]:
+ options = " -q "
+ options += " -o StrictHostKeyChecking=no "
+ if 'host_rootkey' in self and self['host_rootkey']:
+ options += " -i %s " % self['host_rootkey']
command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
return command