def topology_clack_xml(request, tid, topo): """Creates XML that can be loaded with the Clack Graphical Router. Note that this is different to the XML generated above: it tells Clack how to retrieve the XML generated above, and how to layout the components in the graphical view, etc. Most of the information is retrieved from a template, and formatted by replacing $TOKEN with an authentication token and $AUTH_KEY and $USERNAME with the user's simulation authentication key and username.""" # Get the template try: template = urllib2.urlopen("http://localhost/media/clack/template-%s.xml" % topo.template.name).read() except urllib2.URLError: raise # Generate an authentication token, or use the one we currently have; if we # make a new one, it's valid for 30 seconds try: token = request.GET['token'] except KeyError: token = crypto.create_token(request.user, 30) # Format the XML template = template.replace("$TOKEN", token, 1) template = template.replace("$AUTH_KEY", request.user.get_profile().sim_key, 1) template = template.replace("$USERNAME", request.user.username, 1) template = template.replace("$TOPOLOGY", str(tid), 2) # Return it return HttpResponse(template, "text/xml")
def topology_run_clack(request, tid, topo): """Runs clack from an applet for this topology""" tn = 'vns/clack.html' # Generate an authentication token valid for 30 seconds, or use the one we # currently have try: token = request.GET['token'] except KeyError: token = crypto.create_token(request.user, 30) return direct_to_template(request, tn, {'tid':tid, 'token':token})
def topology_info(request, tid, topo): # Create an authentication token valid for 3 minutes for the user to access # Clack stuff with, or use the current token if there is one try: token = request.GET['token'] except KeyError: token = crypto.create_token(request.user, 180) # See what permissions the user has on this topology can_change = permissions.allowed_topology_access_change(request.user, topo) can_delete = permissions.allowed_topology_access_change(request.user, topo) return direct_to_template(request, 'vns/topology.html', {'t':topo, 'tid':tid, 'token':token, 'change':can_change, 'delete':can_delete})