sshxmlrpc_server.py.in 1.95 KB
Newer Older
1
#!/usr/local/bin/python
2 3
#
# Copyright (c) 2004 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24
#
import sys
25
import getopt
26
sys.path.append("@prefix@/lib")
27 28
import socket
import sshxmlrpc
29 30
from emulabserver import *

31 32 33 34 35 36
#
# By default, run a wrapper class that includes all off the modules.
# The client can invoke methods of the form experiment.swapexp when
# the server is invoked in this manner.
# 
DEFAULT_MODULE = "EmulabServer"
37
module         = DEFAULT_MODULE
38 39 40 41 42 43 44 45 46
ReadOnly       = 0;

#
# Optional argument indicating read-only privs.
#
if len(sys.argv) > 1 and sys.argv[1] == "-ro":
    ReadOnly = 1;
    sys.argv = sys.argv[1:]
    pass
47 48

#
49 50
# Optional argument indicates the specific module the server wants to use.
# This form should be deprecated, I think. 
51 52 53 54
#
if len(sys.argv) > 1:
    module = sys.argv[1]
    pass
55 56

#
57 58 59 60
# This is invoked inside an SSH, typically from the paperbag shell.
# We use stdin/stdout to read/write the request/response. We handle
# just a single request this way, and then exit. 
# 
61
# Construct and wrap our object.
62
server  = eval(module + "(readonly=" + str(ReadOnly) + ")")
63
wrapper = sshxmlrpc.SSHServerWrapper(server, module)
64
# Handle the request on stdin and send the response to stdout.
65
wrapper.serve_stdio_forever()
66
sys.exit(0)