~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to bin/nova-compute

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
3
 
4
 
# Copyright 2010 United States Government as represented by the
5
 
# Administrator of the National Aeronautics and Space Administration.
6
 
# All Rights Reserved.
7
 
#
8
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
9
 
#    not use this file except in compliance with the License. You may obtain
10
 
#    a copy of the License at
11
 
#
12
 
#         http://www.apache.org/licenses/LICENSE-2.0
13
 
#
 
4
# Copyright [2010] [Anso Labs, LLC]
 
5
 
6
#    Licensed under the Apache License, Version 2.0 (the "License");
 
7
#    you may not use this file except in compliance with the License.
 
8
#    You may obtain a copy of the License at
 
9
 
10
#        http://www.apache.org/licenses/LICENSE-2.0
 
11
14
12
#    Unless required by applicable law or agreed to in writing, software
15
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
 
#    License for the specific language governing permissions and limitations
18
 
#    under the License.
19
 
 
20
 
"""Starter script for Nova Compute."""
21
 
 
22
 
import eventlet
23
 
eventlet.monkey_patch()
24
 
 
 
13
#    distributed under the License is distributed on an "AS IS" BASIS,
 
14
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
#    See the License for the specific language governing permissions and
 
16
#    limitations under the License.
 
17
"""
 
18
  Twistd daemon for the nova compute nodes.
 
19
  Receives messages via AMQP, manages pool of worker threads
 
20
  for async tasks.  
 
21
"""
 
22
 
 
23
import logging
25
24
import os
26
25
import sys
27
26
 
28
 
# If ../nova/__init__.py exists, add ../ to Python search path, so that
29
 
# it will override what happens to be installed in /usr/(local/)lib/python...
30
 
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
31
 
                                   os.pardir,
32
 
                                   os.pardir))
33
 
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
34
 
    sys.path.insert(0, POSSIBLE_TOPDIR)
 
27
# NOTE(termie): kludge so that we can run this from the bin directory in the
 
28
#               checkout without having to screw with paths
 
29
NOVA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'nova')
 
30
if os.path.exists(NOVA_PATH):
 
31
    sys.path.insert(0, os.path.dirname(NOVA_PATH))
35
32
 
 
33
from nova import vendor
 
34
from carrot import connection
 
35
from carrot import messaging
 
36
from twisted.internet import task
 
37
from twisted.application import service
36
38
 
37
39
from nova import flags
38
 
from nova import log as logging
39
 
from nova import service
40
 
from nova import utils
41
 
 
 
40
from nova import rpc
 
41
from nova import twistd
 
42
from nova.compute import node
 
43
 
 
44
 
 
45
FLAGS = flags.FLAGS
 
46
# NOTE(termie): This file will necessarily be re-imported under different
 
47
#               context when the twistd.serve() call is made below so any
 
48
#               flags we define here will have to be conditionally defined,
 
49
#               flags defined by imported modules are safe.
 
50
if 'node_report_state_interval' not in FLAGS:
 
51
    flags.DEFINE_integer('node_report_state_interval', 10,
 
52
                         'seconds between nodes reporting state to cloud',
 
53
                         lower_bound=1)
 
54
logging.getLogger().setLevel(logging.DEBUG)
 
55
 
 
56
def main():
 
57
    logging.warn('Starting compute node')
 
58
    n = node.NetworkNode()
 
59
    d = n.adopt_instances()
 
60
    d.addCallback(lambda x: logging.info('Adopted %d instances', x))
 
61
 
 
62
    conn = rpc.Connection.instance()
 
63
    consumer_all = rpc.AdapterConsumer(
 
64
            connection=conn,
 
65
            topic='%s' % FLAGS.compute_topic,
 
66
            proxy=n)
 
67
 
 
68
    consumer_node = rpc.AdapterConsumer(
 
69
            connection=conn,
 
70
            topic='%s.%s' % (FLAGS.compute_topic, FLAGS.node_name),
 
71
            proxy=n)
 
72
 
 
73
    # heartbeat = task.LoopingCall(n.report_state)
 
74
    # heartbeat.start(interval=FLAGS.node_report_state_interval, now=False)
 
75
 
 
76
    injected = consumer_all.attach_to_twisted()
 
77
    injected = consumer_node.attach_to_twisted()
 
78
 
 
79
    # This is the parent service that twistd will be looking for when it
 
80
    # parses this file, return it so that we can get it into globals below
 
81
    application = service.Application('nova-compute')
 
82
    n.setServiceParent(application)
 
83
    return application
 
84
 
 
85
 
 
86
# NOTE(termie): When this script is executed from the commandline what it will
 
87
#               actually do is tell the twistd application runner that it
 
88
#               should run this file as a twistd application (see below).
42
89
if __name__ == '__main__':
43
 
    utils.default_flagfile()
44
 
    flags.FLAGS(sys.argv)
45
 
    logging.setup()
46
 
    utils.monkey_patch()
47
 
    server = service.Service.create(binary='nova-compute')
48
 
    service.serve(server)
49
 
    service.wait()
 
90
    twistd.serve(__file__)
 
91
 
 
92
# NOTE(termie): When this script is loaded by the twistd application runner
 
93
#               this code path will be executed and twistd will expect a
 
94
#               variable named 'application' to be available, it will then
 
95
#               handle starting it and stopping it.
 
96
if __name__ == '__builtin__':
 
97
    application = main()