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