cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
serve.py
Go to the documentation of this file.
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3 # @COPYRIGHT_begin
4 #
5 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # @COPYRIGHT_end
20 
21 ##
22 # @package src.ec2
23 #
24 # @copyright Copyright (c) 2012 Institute of Nuclear Physics PAS <http://www.ifj.edu.pl/>
25 # @author Oleksandr Gituliar <gituliar@gmail.com>
26 #
27 
28 import logging
29 import select
30 from socket import gaierror, gethostbyname
31 from wsgiref.simple_server import make_server
32 
33 from ec2.main import CloudManager, application
34 from ec2.settings import XMLRPCSERVER
35 
36 
37 ##
38 # Start EC2 server.
39 def serve(host='localhost', port=8080, verbosity='DEBUG'):
40 
41  logging.basicConfig(level=verbosity)
42 
43  addr = gethostbyname(host)
44  server = make_server(host, port, application)
45  logging.info("Listen %s:%s ..." % (host, port))
46 
47  regions = CloudManager(XMLRPCSERVER).cluster_managers()
48  logging.info("Available CMs: %s" % regions)
49 
50  try:
51  server.serve_forever()
52  except select.error, error:
53  pass
54  except KeyboardInterrupt, error:
55  pass
56 
57 if __name__ == '__main__':
58  serve()
59