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 '/sdvm_started', 'os_sdvm_started', # http://localhost:8080/sdvm_started GET
57 '/sdvms', 'os_sdvms', # http://localhost:8080/sdvms GET, PUT
58 '/sdvms/(.*)/ip', 'os_sdvm_ip', # http://localhost:8080/sdvms/[VMNAME]/ip GET
59 '/sdvms/(.*)/start', 'os_sdvm_start', # http://localhost:8080/sdvms/[VMNAME]/start GET
60 '/sdvms/(.*)/stop', 'os_sdvm_stop', # http://localhost:8080/sdvms/[VMNAME]/stop GET
61 '/sdvms/(.*)', 'os_sdvm', # http://localhost:8080/sdvms/[VMNAME] GET, DELETE
62 '/vms', 'os_vms', # http://localhost:8080/vms GET
63 '/vms/(.*)', 'os_vm', # http://localhost:8080/vms/[VMNAME] GET
64 '/', 'os_root' # http://localhost:8080/ GET
68 # ------------------------------------------------------------
71 # Global VMManager instance
75 # ------------------------------------------------------------
79 class os_device_change:
80 """OpenSecurity '/device_change' handler"""
83 gvm_mgr.handleDeviceChange()
84 return "os_device_change"
86 class os_sdvm_started:
87 """OpenSecurity '/sdvm_started' handler"""
90 # self.request get address
91 return "os_sdvm_started"
94 """OpenSecurity '/sdvms/[VM]' handler"""
97 return gvm_mgr.getVMInfo(name)
99 def DELETE(self, name):
100 return gvm_mgr.removeVM(name)
104 """OpenSecurity '/sdvms/[VM]/ip' handler"""
107 return gvm_mgr.getHostOnlyIP(name)
111 """OpenSecurity '/sdvms/[VM]/start' handler"""
114 return gvm_mgr.startVM(name)
118 """OpenSecurity '/sdvms/[VM]/stop' handler"""
121 return gvm_mgr.stopVM(name)
125 """OpenSecurity '/sdvms' handler"""
128 """get the list of SDVMs"""
129 return gvm_mgr.listSDVM()
132 """create a new SDVM"""
135 name = gvm_mgr.generateSDVMName()
137 gvm_mgr.createVM(name)
139 raise web.internalerror()
144 """OpenSecurity '/vms/[VM]' handler"""
147 return gvm_mgr.getVMInfo(name)
151 """OpenSecurity '/vms' handler"""
154 return gvm_mgr.listVM()
158 """OpenSecurity '/' handler"""
161 res = "'os_server': { "
162 res += "'version': '" + __version__ + "', "
163 res += "'machine_folder': '" + gvm_mgr.getDefaultMachineFolder() + "' "
169 if __name__ == "__main__":
170 server = web.application(opensecurity_urls, globals())