- Added Node, Site, Slice, Person, and PLC classes useful for defining a default...
[tests.git] / qaapi / qa / Nodes.py
1 import utils
2 import os
3 from Remote import Remote
4 from Table import Table
5
6
7 class Node(dict, Remote):
8
9     fields = {
10         'plc': None,
11         'hostname': None,               # Node Hostname
12         'host': 'localhost',            # host where node lives
13         'vserver': None,                # vserver where this node lives
14         'type': 'virtual',              # type of node
15         'nodenetworks': [],             # node networks
16         'homedir': '/var/VirtualMachines/',
17         'rootkey': '/home/tmack/.ssh/plc-root' # path to root ssh key
18         }
19
20     def __init__(self, config, fields = {}):
21
22         # XX Filter out fields not specified in fields
23         dict.__init__(self, self.fields)
24         
25         # Merge defined fields with defaults
26         self.update(fields)
27         self.config = config    
28     
29     def create_boot_image(self):
30
31         command = ""
32         if self['host'] and self['host'] not in ['localhost']:
33             command += "ssh -i %s root@%s " % (self['rootkey'], self['host'])
34         
35     def create_disk_image(self, size = '10G'):
36         diskimg_path = self['homedir'] + os.sep + self['hostname'] + os.sep + \
37                         'hda.img'
38         command = ""
39         command += " qemu-img create -f qcow2 %(diskimg_path)s %(size)s " % locals()
40
41         #utils.header(command)
42         (status, output) = self.commands(command, True)
43
44     def boot(self):
45         pass
46
47     def scp(self):
48         pass 
49
50 class Nodes(list, Table):
51
52     def __init__(self, config, nodes):
53         nodelist = [Node(config, node) for node in nodes]
54         list.__init__(self, nodelist)
55         self.config = config
56