--- /dev/null
+import utils
+import os
+from Remote import Remote
+from Table import Table
+
+
+class Node(dict, Remote):
+
+ fields = {
+ 'plc': None,
+ 'hostname': None, # Node Hostname
+ 'host': 'localhost', # host where node lives
+ 'vserver': None, # vserver where this node lives
+ 'type': 'virtual', # type of node
+ 'nodenetworks': [], # node networks
+ 'homedir': '/var/VirtualMachines/',
+ 'rootkey': '/home/tmack/.ssh/plc-root' # path to root ssh key
+ }
+
+ def __init__(self, config, fields = {}):
+
+ # XX Filter out fields not specified in fields
+ dict.__init__(self, self.fields)
+
+ # Merge defined fields with defaults
+ self.update(fields)
+ self.config = config
+
+ def create_boot_image(self):
+
+ command = ""
+ if self['host'] and self['host'] not in ['localhost']:
+ command += "ssh -i %s root@%s " % (self['rootkey'], self['host'])
+
+ def create_disk_image(self, size = '10G'):
+ diskimg_path = self['homedir'] + os.sep + self['hostname'] + os.sep + \
+ 'hda.img'
+ command = ""
+ command += " qemu-img create -f qcow2 %(diskimg_path)s %(size)s " % locals()
+
+ #utils.header(command)
+ (status, output) = self.commands(command, True)
+
+ def boot(self):
+ pass
+
+ def scp(self):
+ pass
+
+class Nodes(list, Table):
+
+ def __init__(self, config, nodes):
+ nodelist = [Node(config, node) for node in nodes]
+ list.__init__(self, nodelist)
+ self.config = config
+
--- /dev/null
+import os
+import copy
+from Remote import Remote
+from Table import Table
+
+class PLC(dict, Remote):
+ fields = {
+ 'name': 'TestPLC', # PLC Name
+ 'host': 'localhost', # Node Hostname
+ 'ip': '127.0.0.1', # IP
+ 'chroot': None,
+ 'vserver': None, # Vserver where this PLC lives
+ 'rootkey': '/home/tmack/.ssh/plc-root', # Root Key
+ 'api_path': '/PLCAPI/', # PLCAPI path
+ 'port': '443' # PLCAPI port
+
+ }
+
+ def __init__(self, config, fields = {}):
+ # XX Filter out fields not specified in fields
+ dict.__init__(self, self.fields)
+
+ # Merge defined fields with defaults
+ self.update(fields)
+
+ # init config
+ self.config = config
+ self.config.update_api(self)
+
+class PLCs(list, Table):
+
+ def __init__(self, config, plcs):
+ plclist = [PLC(config, plc) for plc in plcs]
+ list.__init__(self, plclist)
--- /dev/null
+import os
+from Table import Table
+
+class Person(dict):
+
+ fields = {
+ 'plc': None,
+ 'first_name': None,
+ 'last_name': None,
+ 'password': None,
+ 'email': None,
+ }
+
+ def __init__(self, fields = {}):
+
+ dict.__init__(self, self.fields)
+
+ self.update(fields)
+
+class Persons(list, Table):
+ def __init__(self, persons):
+ personlist = [Person(person) for person in persons]
+ list.__init__(self, personlist)
--- /dev/null
+import utils
+
+class Remote:
+
+ def get_remote_command(self, command):
+ 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)
+ if 'host' in self and self['host'] not in ['localhost']:
+ options = ""
+ if 'rootkey' in self and self['rootkey']:
+ options = "-i %s " % self['rootkey']
+ command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
+
+ return command
+
+ def popen(self, command, fatal = True):
+ command = self.get_remote_command(command)
+ #utils.header(command)
+ return utils.popen(command, fatal)
+
+ def commands(self, command, fatal = True):
+ command = self.get_remote_command(command)
+ #utils.header(command)
+ return utils.commands(command, fatal)
+
+ def scp(self, src, dest):
+ options = ""
+ if 'rootkey' in self and self['rootkey'] is not None:
+ options += " -i %s " % (self['rootkey'])
+ path = ""
+ if 'chroot' in self and self['chroot'] is not None:
+ path += "/plc/root/"
+ if 'vserver' in self and self['vserver'] is not None:
+ path += '/vservers/%s/' % self['vserver']
+
+ src_cmd = ""
+ src_parts = src.split(":")
+ dest_cmd = ""
+ dest_parts = dest.split(":")
+ command = "scp "
+ if len(src_parts) == 1:
+ src_cmd = src
+ elif src_parts[0].find('localhost') != -1:
+ src_cmd = src_parts[1]
+ else:
+ host, file = src_parts[0], src_parts[1]
+ src_cmd = 'root@%(host)s:%(path)s%(file)s ' % locals()
+
+ if len(dest_parts) == 1:
+ dest_cmd = dest
+ elif dest_parts[0].find('localhost') != -1:
+ dest_cmd = dest_parts[1]
+ else:
+ host, file = dest_parts[0], dest_parts[1]
+ dest_cmd = 'root@%(host)s:%(path)s%(file)s' % locals()
+
+ print dest_parts
+ command = 'scp %(options)s %(src_cmd)s %(dest_cmd)s' % locals()
+ utils.header(command)
+ return utils.commands(command)
+
--- /dev/null
+import os
+from Table import Table
+
+class Site(dict):
+
+ fields = {
+ 'plc': 'TestPLC',
+ 'name': None,
+ 'login_base': None,
+ 'enabled': True,
+ 'abbreviated_name': None,
+ 'max_slices': 100,
+ 'is_public': True,
+ 'url': None
+ }
+
+ def __init__(self, fields = {}):
+
+ dict.__init__(self, self.fields)
+
+ self.update(fields)
+
+class Sites(list, Table):
+ def __init__(self, sites):
+ sitelist = [Site(site) for site in sites]
+ list.__init__(self, sitelist)
--- /dev/null
+import os
+from Table import Table
+
+class Slice(dict):
+
+ fields = {
+ 'plc': None,
+ 'name': None,
+ 'instantiation': 'plc-instantiated',
+ 'max_nodes': 1000,
+ 'description': 'blank',
+ 'url': None
+ }
+
+ def __init__(self, fields = {}):
+
+ dict.__init__(self, self.fields)
+
+ self.update(fields)
+
+class Slices(list, Table):
+ def __init__(self, slices):
+ slicelist = [Slice(slice) for slice in slices]
+ list.__init__(self, slicelist)
--- /dev/null
+
+class Table:
+ def dict(self, key_field):
+ """
+ Return ourself as a dict keyed on key_fields
+ """
+ return dict([(obj[key_field], obj) for obj in self])