Apache VCL is a cloud computing platform that NC State uses to provide on-demand access to specific software or environments. It’s neat because you can quickly and easily get a virtual machine to try things out with, or a cluster to experiment with networking. The remote API for VCL is provided via an XML-RPC interface. Python has a nice XML-RPC library called xmlrpclib that makes building clients comically easy.
For instance, here’s a short example, with in-line comments explaining the four lines that need any explanation:
import xmlrpclib
import getpass
# We're connecting over SSL so subclass SafeTransport
class AuthenticatedTransport(xmlrpclib.SafeTransport):
def __init__(self, username, password):
xmlrpclib.SafeTransport.__init__(self)
self.password = password
self.username = username
def send_content(self, connection, request_body):
# X- headers are user-defined in HTTP
# These next few are used by VCL
connection.putheader("X-User", self.username)
connection.putheader("X-Pass", self.password)
connection.putheader("X-APIVERSION: 2")
# That's the end of the VCL-specific headers
xmlrpclib.SafeTransport.send_content(self, connection, request_body)
username = raw_input("Username: ")
password = getpass.getpass("Password: ")
auth_transport = AuthenticatedTransport(username, password)
server = xmlrpclib.Server("https://vcl.ncsu.edu/scheduling/index.php?mode=xmlrpccall", transport=auth_transport)
try:
result = server.XMLRPCtest("foo")
except xmlrpclib.ProtocolError as e:
print "URL: {}".format(e.url)
print "Headers: {}".format(e.headers)
print "Error code: {}".format(e.errcode)
print "Error message: {}".format(e.errmsg)
except xmlrpclib.Fault as f:
print "Fault Code: {}".format(f.faultCode)
print "Fault: {}".format(f.faultString)
print "Args: {}".format(f.args)
print "Message: {}".format(f.message)
else:
print result
If all goes well, then you should receive a response of the form:
{'status': 'success', 'message': 'RPC call worked successfully', 'string': 'foo'}
Then you can use the API reference to construct a program that will, for instance, spin up a small cluster of instances, run a student’s code, and then grade it.