OpenSecurity/bin/opensecurityd.py
author om
Fri, 06 Dec 2013 12:24:24 +0100
changeset 16 e16d64b5e008
parent 15 2e4cb1ebcbed
parent 13 4457d7071a23
child 17 0b4efa323de3
permissions -rw-r--r--
working on client/server code merge
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # opensecurityd
     6 # 
     7 # the opensecurityd as RESTful server
     8 #
     9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    10 #
    11 # Copyright (C) 2013 AIT Austrian Institute of Technology
    12 # AIT Austrian Institute of Technology GmbH
    13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
    14 # http://www.ait.ac.at
    15 #
    16 # This program is free software; you can redistribute it and/or
    17 # modify it under the terms of the GNU General Public License
    18 # as published by the Free Software Foundation version 2.
    19 # 
    20 # This program is distributed in the hope that it will be useful,
    21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23 # GNU General Public License for more details.
    24 # 
    25 # You should have received a copy of the GNU General Public License
    26 # along with this program; if not, write to the Free Software
    27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    28 # Boston, MA  02110-1301, USA.
    29 # ------------------------------------------------------------
    30 
    31 
    32 # ------------------------------------------------------------
    33 # imports
    34 
    35 import os
    36 import os.path
    37 import subprocess
    38 import sys
    39 import web
    40 from vmmanager.vmmanager import VMManager
    41 
    42 # local
    43 from environment import Environment
    44 
    45 
    46 # ------------------------------------------------------------
    47 # const
    48 
    49 __version__ = "0.1"
    50 
    51 
    52 """All the URLs we know mapping to class handler"""
    53 opensecurity_urls = (
    54     '/device_change',           'os_device_change',
    55     '/sdvms',                   'os_sdvms',
    56     '/vms',                     'os_vms',
    57     '/vms/(.*)',                'os_vm',
    58     '/',                        'os_root'
    59 )
    60 
    61 
    62 # ------------------------------------------------------------
    63 # vars
    64 
    65 # Global VMManager instance
    66 gvm_mgr = VMManager()
    67 
    68 
    69 # ------------------------------------------------------------
    70 # code
    71 
    72 
    73 class os_device_change:
    74     """OpenSecurity '/device_change' handler"""
    75     
    76     def GET(self):
    77         #gvm_mgr.configureHostNetworking()
    78         print 'received device_change'
    79         return "os_device_change"
    80 
    81 
    82 class os_sdvms:
    83     """OpenSecurity '/sdvms' handler"""
    84     
    85     def GET(self):
    86         return gvm_mgr.listSDVM() 
    87             
    88 
    89 class os_vm:
    90     """OpenSecurity '/vms/VM' handler"""
    91     
    92     def GET(self, name):
    93         return gvm_mgr.getVMInfo(name)
    94             
    95 
    96 class os_vms:
    97     """OpenSecurity '/vms' handler"""
    98     
    99     def GET(self):
   100         return gvm_mgr.listVM() 
   101             
   102 
   103 class os_root:
   104     """OpenSecurity '/' handler"""
   105     
   106     def GET(self):
   107         res = "'os_server': { "
   108         res += "'version': '" + __version__ + "', "
   109         res += "'virtualbox_path': '" + gvm_mgr.vBoxPath + "', "
   110         res += "'machine_folder': '" + gvm_mgr.getDefaultMachineFolder() + "' "
   111         res += "}"
   112         return res
   113 
   114 
   115 # start
   116 if __name__ == "__main__":
   117     server = web.application(opensecurity_urls, globals())
   118     server.run()
   119