+ # Enable VOMS Authorization
+ print "snf-occi application has been called!"
+
+ req = Request(environ)
+ auth_endpoint = 'snf-auth uri=\'https://'+SERVER_CONFIG['hostname']+':5000/main\''
+
+ if not req.environ.has_key('HTTP_X_AUTH_TOKEN'):
+
+ print "Error: An authentication token has not been provided!"
+ status = '401 Not Authorized'
+ headers = [('Content-Type', 'text/html'),('Www-Authenticate',auth_endpoint)]
+ response(status,headers)
+ return [str(response)]
+
+
+ if ENABLE_VOMS:
+
+ if req.environ.has_key('HTTP_X_AUTH_TOKEN'):
+
+ environ['HTTP_AUTH_TOKEN']= req.environ['HTTP_X_AUTH_TOKEN']
+ compClient = ComputeClient(KAMAKI_CONFIG['compute_url'], environ['HTTP_AUTH_TOKEN'])
+ cyclClient = CycladesClient(KAMAKI_CONFIG['compute_url'], environ['HTTP_AUTH_TOKEN'])
+
+ try:
+ #Up-to-date flavors and images
+ self.refresh_images(compClient,cyclClient)
+ self.refresh_flavors_norecursive(compClient,cyclClient)
+ self.refresh_network_instances(cyclClient)
+ self.refresh_compute_instances(compClient,cyclClient)
+ # token will be represented in self.extras
+ return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)
+ except HTTPError:
+ print "Exception from unauthorized access!"
+ status = '401 Not Authorized'
+ headers = [('Content-Type', 'text/html'),('Www-Authenticate',auth_endpoint)]
+ response(status,headers)
+ return [str(response)]
+
+ else:
+
+ #raise HTTPError(404, "Unauthorized access")
+ status = '401 Not Authorized'
+ headers = [('Content-Type', 'text/html'),('Www-Authenticate',auth_endpoint)]
+ response(status,headers)
+ return [str(response)]
+
+ else: