Commit f226d7ef authored by Leigh Stoller's avatar Leigh Stoller

Another checkpoint before bringing in Tim's latest code.

parent 63792e12
......@@ -12,11 +12,11 @@ UNIFIED = @UNIFIED_BOSS_AND_OPS@
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = sshxmlrpc_client.py client.py
BIN_SCRIPTS = sshxmlrpc_client.py
SBIN_SCRIPTS = sshxmlrpc_server.py
LIB_STUFF = sshxmlrpc.py emulabserver.py emulabclient.py
LIBEXEC_STUFF = webxmlrpc
WWW_STUFF = xmlapi.php3
WWW_STUFF = xmlrpcapi.php3
#
# These are the ones installed on plastic (users, control, etc).
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ from emulabclient import *
##
# The package version number
#
PACKAGE_VERSION = "0.1"
PACKAGE_VERSION = 0.1
# Default server
XMLRPC_SERVER = "@BOSSNODE@"
......@@ -26,6 +26,9 @@ xmlrpc_server = XMLRPC_SERVER
# User supplied login ID to use (overrides env variable USER if exists).
login_id = os.environ["USER"]
# The default RPC module to invoke.
module = "experiment"
# Debugging output.
debug = 0
......@@ -35,17 +38,19 @@ debug = 0
def usage():
print "Make a request to the Emulab XML-RPC (SSH-based) server."
print ("Usage: " + sys.argv[0]
+ " [-hV] [-l login] [-s server] <method> [<args>]")
+ " [-hV] [-l login] [-s server] [-m module] "
+ "<method> [param=value ...]")
print
print "Options:"
print " -h, --help\t\t Display this help message"
print " -V, --version\t\t Show the version number"
print " -s, --server\t\t Set the server hostname"
print " -l, --login\t\t Set the login id (defaults to $USER)"
print " -m, --module\t\t Set the RPC module (defaults to experiment)"
print
print "Required arguments:"
print " method\t\t The method to execute on the server"
print " args\t\t\t The method arguments"
print " params\t\t\t The method arguments in param=value format"
print
print "Example:"
print (" "
......@@ -74,6 +79,9 @@ try:
elif opt in ("-l", "--login"):
login_id = val
pass
elif opt in ("-m", "--module"):
module = val
pass
elif opt in ("-d"):
debug = 1
pass
......@@ -89,19 +97,46 @@ except getopt.error, e:
pass
# Get a handle on the server,
server = SSHServerProxy("ssh://" + login_id + "@" + xmlrpc_server + "/sshxmlrpc")
# Get a handle on the emulab client object, giving it the transport to use.
client = emulabclient(server, debug);
server = SSHServerProxy("ssh://" + login_id + "@" + xmlrpc_server +
"/xmlrpc/" + module)
# Get a pointer to the client side of the function we want to invoke.
meth = getattr(client, req_args[0])
# Get a pointer to the function we want to invoke.
meth = getattr(server, req_args[0])
# The rest of the list is passed as is.
# Pop off the method, and then convert the rest of the arguments. Be sure to
# add the version.
req_args.pop(0)
params = {}
for param in req_args:
plist = string.split(param, "=")
if len(plist) != 2:
print "Parameters are of the form: param=value!"
sys.exit(-1)
params[plist[0]] = plist[1]
pass
meth_args = [ PACKAGE_VERSION, params ]
#
# Make the call. The clientside class will do whatever it needs before
# invoking the equiv method on the server side.
# Make the call.
#
sys.exit(apply(meth, req_args))
response = apply(meth, meth_args)
#
# Parse the Response, which is a Dictionary. See ResponseBlock in the
# emulabclient.py module. The XML standard converts classes to a plain
# Dictionary, hence the code below.
#
if len(response["output"]):
print response["output"]
pass
if response["code"] != RESPONSE_SUCCESS:
if response["value"]:
sys.exit(response["value"])
else:
sys.exit(response["code"])
pass
sys.exit(RESPONSE_SUCCESS)
......@@ -57,32 +57,35 @@ Python is also available that you can use on your desktop to invoke
commands from the shell. For example:
<code><pre>
$ sshxmlrpc_client.py startexp -i -w mypid myeid ~/nsfile.ns</code></pre>
$ sshxmlrpc_client.py startexp batch=false wait=true pid="mypid" eid="myeid" nsfilestr="`cat ~/nsfile.ns`"</code></pre>
which says to create an experiment called "myeid" in the "mypid"
project, swap it in immediately, wait for the exit status (instead of
running asynchronously), using the NS file nsfile.ns in your home dir.
By default, the client will contact the RPC server at
<tt><?php echo $BOSSNODE ?></tt>, but you can override that by using
the <tt>-s hostname</tt> option to sshxmlrpc_client. If your login ID
on the local machine is different then your login ID at Emulab, you
can use the <tt>-l login</tt> option. For example:
which says to create an experiment called "myeid" in the "mypid" project,
swap it in immediately, wait for the exit status (instead of running
asynchronously), passing inline the contents of nsfile.ns in your home dir.
By default, the client will contact the RPC server at <tt><?php echo
$BOSSNODE ?></tt>, but you can override that by using the <tt>-s
hostname</tt> option to sshxmlrpc_client. If your login ID on the local
machine is different then your login ID at Emulab, you can use the <tt>-l
login</tt> option. For example:
<code><pre>
$ sshxmlrpc_client.py -s boss.emulab.net -l rellots startexp ...</code></pre>
which would invoke the RPC server on <tt>boss.emulab.net</tt>, using the login
ID <tt>rellots</tt> (for the purposes of SSH authentication). You will
be prompted for your SSH passphrase, unless you are running an SSH
agent and the key you have uploaded to Emulab has been added to your
local agent.
which would invoke the RPC server on <tt>boss.emulab.net</tt>, using the
login ID <tt>rellots</tt> (for the purposes of SSH authentication). You
will be prompted for your SSH passphrase, unless you are running an SSH
agent and the key you have uploaded to Emulab has been added to your local
agent.
</p>
<p>
The <tt>sshxmlrpc_client</tt> python program is a simple demonstration of
how to use Emulab's RPC server. It converts command lines into RPCs to the
server, and prints out the results that the server sends back, exiting with
whatever status code the server returned. You can use this client program
how to use Emulab's RPC server. If you do not give provide a method
and arguments on the command line, it will enter a command loop where
you can type in commands (method and arguments) and wait for responses
from the server. It converts your command lines into RPCs to the
server, and prints out the results that the server sends back (exiting with
whatever status code the server returned). You can use this client program
as is, or you can write your own client program in whatever language you
like, as long as you speak to the server over an SSH connection. The API
for the server is broken into several different modules that export a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment