OpenSecurity/bin/opensecurityd.py
changeset 13 4457d7071a23
child 16 e16d64b5e008
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/OpenSecurity/bin/opensecurityd.py	Fri Dec 06 10:51:15 2013 +0100
     1.3 @@ -0,0 +1,119 @@
     1.4 +#!/bin/env python
     1.5 +# -*- coding: utf-8 -*-
     1.6 +
     1.7 +# ------------------------------------------------------------
     1.8 +# opensecurityd
     1.9 +# 
    1.10 +# the opensecurityd as RESTful server
    1.11 +#
    1.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    1.13 +#
    1.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    1.15 +# AIT Austrian Institute of Technology GmbH
    1.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    1.17 +# http://www.ait.ac.at
    1.18 +#
    1.19 +# This program is free software; you can redistribute it and/or
    1.20 +# modify it under the terms of the GNU General Public License
    1.21 +# as published by the Free Software Foundation version 2.
    1.22 +# 
    1.23 +# This program is distributed in the hope that it will be useful,
    1.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 +# GNU General Public License for more details.
    1.27 +# 
    1.28 +# You should have received a copy of the GNU General Public License
    1.29 +# along with this program; if not, write to the Free Software
    1.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    1.31 +# Boston, MA  02110-1301, USA.
    1.32 +# ------------------------------------------------------------
    1.33 +
    1.34 +
    1.35 +# ------------------------------------------------------------
    1.36 +# imports
    1.37 +
    1.38 +import os
    1.39 +import os.path
    1.40 +import subprocess
    1.41 +import sys
    1.42 +import web
    1.43 +from vmmanager.vmmanager import VMManager
    1.44 +
    1.45 +# local
    1.46 +from environment import Environment
    1.47 +
    1.48 +
    1.49 +# ------------------------------------------------------------
    1.50 +# const
    1.51 +
    1.52 +__version__ = "0.1"
    1.53 +
    1.54 +
    1.55 +"""All the URLs we know mapping to class handler"""
    1.56 +opensecurity_urls = (
    1.57 +    '/device_change',           'os_device_change',
    1.58 +    '/sdvms',                   'os_sdvms',
    1.59 +    '/vms',                     'os_vms',
    1.60 +    '/vms/(.*)',                'os_vm',
    1.61 +    '/',                        'os_root'
    1.62 +)
    1.63 +
    1.64 +
    1.65 +# ------------------------------------------------------------
    1.66 +# vars
    1.67 +
    1.68 +# Global VMManager instance
    1.69 +gvm_mgr = VMManager()
    1.70 +
    1.71 +
    1.72 +# ------------------------------------------------------------
    1.73 +# code
    1.74 +
    1.75 +
    1.76 +class os_device_change:
    1.77 +    """OpenSecurity '/device_change' handler"""
    1.78 +    
    1.79 +    def GET(self):
    1.80 +        #gvm_mgr.configureHostNetworking()
    1.81 +        print 'received device_change'
    1.82 +        return "os_device_change"
    1.83 +
    1.84 +
    1.85 +class os_sdvms:
    1.86 +    """OpenSecurity '/sdvms' handler"""
    1.87 +    
    1.88 +    def GET(self):
    1.89 +        return gvm_mgr.listSDVM() 
    1.90 +            
    1.91 +
    1.92 +class os_vm:
    1.93 +    """OpenSecurity '/vms/VM' handler"""
    1.94 +    
    1.95 +    def GET(self, name):
    1.96 +        return gvm_mgr.getVMInfo(name)
    1.97 +            
    1.98 +
    1.99 +class os_vms:
   1.100 +    """OpenSecurity '/vms' handler"""
   1.101 +    
   1.102 +    def GET(self):
   1.103 +        return gvm_mgr.listVM() 
   1.104 +            
   1.105 +
   1.106 +class os_root:
   1.107 +    """OpenSecurity '/' handler"""
   1.108 +    
   1.109 +    def GET(self):
   1.110 +        res = "'os_server': { "
   1.111 +        res += "'version': '" + __version__ + "', "
   1.112 +        res += "'virtualbox_path': '" + gvm_mgr.vBoxPath + "', "
   1.113 +        res += "'machine_folder': '" + gvm_mgr.getDefaultMachineFolder() + "' "
   1.114 +        res += "}"
   1.115 +        return res
   1.116 +
   1.117 +
   1.118 +# start
   1.119 +if __name__ == "__main__":
   1.120 +    server = web.application(opensecurity_urls, globals())
   1.121 +    server.run()
   1.122 +