2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # the opensecurityd as RESTful server
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
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
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.
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.
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 # ------------------------------------------------------------
32 # ------------------------------------------------------------
41 from vmmanager import VMManager
44 from environment import Environment
47 # ------------------------------------------------------------
53 """All the URLs we know mapping to class handler"""
55 '/device_change', 'os_device_change', # http://localhost:8080/device_change GET
56 '/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT
57 '/sdvms/(.*)', 'os_sdvm', # http://localhost:8080/sdvms GET, DELETE
58 '/vms', 'os_vms', # http://localhost:8080/vms GET
59 '/vms/(.*)', 'os_vm', # http://localhost:8080/vms/[VMNAME] GET
60 '/', 'os_root' # http://localhost:8080/ GET
64 # ------------------------------------------------------------
67 # Global VMManager instance
71 # ------------------------------------------------------------
75 class os_device_change:
76 """OpenSecurity '/device_change' handler"""
79 gvm_mgr.handleDeviceChange()
80 return "os_device_change"
84 """OpenSecurity '/sdvms/[VM]' handler"""
87 return gvm_mgr.getVMInfo(name)
90 def DELETE(self, name):
91 return gvm_mgr.removeVM(name)
95 """OpenSecurity '/sdvms' handler"""
98 """get the list of SDVMs"""
99 return gvm_mgr.listSDVM()
102 """create a new SDVM"""
106 if not "name" in args:
107 raise web.badrequest()
109 return gvm_mgr.createVM(args.name)
112 """OpenSecurity '/vms/[VM]' handler"""
115 return gvm_mgr.getVMInfo(name)
119 """OpenSecurity '/vms' handler"""
122 return gvm_mgr.listVM()
126 """OpenSecurity '/' handler"""
129 res = "'os_server': { "
130 res += "'version': '" + __version__ + "', "
131 res += "'machine_folder': '" + gvm_mgr.getDefaultMachineFolder() + "' "
137 if __name__ == "__main__":
138 server = web.application(opensecurity_urls, globals())