4 from Remote import Remote
5 from Table import Table
8 class Node(dict, Remote):
12 'hostname': None, # Node Hostname
13 'host': 'localhost', # host where node lives
14 'redir_ssh_port': '51022', # Port on host where ssh is redirected to virtual node
15 'vserver': None, # vserver where this node lives
16 'type': 'vm', # type of node
18 'nodenetworks': [], # node networks
19 'homedir': '/var/VirtualMachines/',
20 'rootkey': None, # path to root ssh key
24 def __init__(self, config, fields = {}):
26 # XX Filter out fields not specified in fields
27 dict.__init__(self, self.fields)
29 # Merge defined fields with defaults
33 get_host_command = Remote.get_remote_command
35 def get_remote_command(self, command, user = 'root', key = None):
39 options += " -o StrictHostKeyChecking=no "
40 options += " -i %(key)s" % locals()
41 host = self['hostname']
42 if 'type' in self and self['type'] in ['vm']:
43 if 'redir_ssh_port' in self and self['redir_ssh_port']:
44 options += " -p %s " % self['redir_ssh_port']
45 ip_command = "/sbin/ifconfig eth0 | grep -v inet6 | grep inet | awk '{print$2;}'"
46 (status, output) = self.host_commands(ip_command)
47 host = re.findall(r'[0-9\.]+', output)[0]
49 command = "ssh %(options)s %(user)s@%(host)s \'%(command)s\'" % locals()
50 return self.get_host_command(command)
53 def host_popen(self, command, fatal = True):
54 command = self.get_host_command(command)
55 return utils.popen(command, fatal, self.config.verbose)
57 def host_popen3(self, command):
58 command = self.get_host_command(command)
59 return utils.popen3(command, self.config.verbose)
61 def host_commands(self, command, fatal = True):
62 command = self.get_host_command(command)
63 return utils.commands(command, fatal, self.config.verbose)
66 class Nodes(list, Table):
68 def __init__(self, config, nodes):
69 nodelist = [Node(config, node) for node in nodes]
70 list.__init__(self, nodelist)