From 2646ab2636647a60809c50bbfabbc1386dd17b5e Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Fri, 29 Feb 2008 19:27:55 +0000 Subject: [PATCH] Added stuff for the NM API. --- doc/NMAPI.xml | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/doc/NMAPI.xml b/doc/NMAPI.xml index da6e7eb..454650d 100644 --- a/doc/NMAPI.xml +++ b/doc/NMAPI.xml @@ -23,6 +23,10 @@ 'nm-controller', the target slice must be listed delegated and as controlled by the calling slice. + +
+ Delegation + None
Connection @@ -47,9 +51,9 @@ controller_slice_id = api.AddSlices(plauth, controller_slice_fields) After this, the controller owner, should both add users and nodes to - this slice. As well, becasue this account is created using the standard - NM mechanism, you should wait at least 15 minutes for the controller slice - to be instantiated on all the nodes you'd like to access it. + this slice. As well, the controller slice is created using the standard + PlanetLab and NM mechanism. So, wait at least 15 minutes before attempting + to access the controller slice on any node. Subsequently, slices that will be delegated to this controller will be registered at PLC. An example follows. @@ -68,7 +72,7 @@ ticket = api.GetSliceTicket(plauth, "princetondsl_solteszdelegated") After the slice is registered with PLC, and your application has the Ticket, the last step is to redeem the ticket by presenting it to the NM - through the nm-controller account. THe following code formats the message + through the nm-controller account. The following code formats the message correctly. @@ -102,6 +106,45 @@ p.stdin.close() print xmlrpclib.loads(p.stdout.read()) p.wait() + + The following is a stub to use as you would use the current + xmlrpclib.Server() object, but redirects the connection of SSH. + + +"""XML-RPC over SSH. + + To use, create an XmlRpcOverSsh object like so: + >>> api = XmlRpcOverSsh('princeton_deisenst@planetlab-1.cs.princeton.edu') + and call methods as with the normal xmlrpclib.ServerProxy interface. +""" + +from subprocess import PIPE, Popen +from xmlrpclib import Fault, dumps, loads + +__all__ = ['XmlRpcOverSsh'] + + +class XmlRpcOverSsh: + def __init__(self, userAtHost): + self.userAtHost = userAtHost + + def __getattr__(self, method): + return _Method(self.userAtHost, method) + + +class _Method: + def __init__(self, userAtHost, method): + self.userAtHost = userAtHost + self.method = method + + def __call__(self, *args): + p = Popen(['ssh', self.userAtHost], stdin=PIPE, stdout=PIPE) + stdout, stderr = p.communicate(dumps(args, self.method)) + if stderr: + raise Fault(1, stderr) + else: + return loads(stdout) +
-- 2.47.0