1
1
#!/usr/bin/env python
2
2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2010 United States Government as represented by the
5
# Administrator of the National Aeronautics and Space Administration.
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
12
# http://www.apache.org/licenses/LICENSE-2.0
4
# Copyright [2010] [Anso Labs, LLC]
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
10
# http://www.apache.org/licenses/LICENSE-2.0
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
20
"""Starter script for Nova Compute."""
23
eventlet.monkey_patch()
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.
18
Twistd daemon for the nova compute nodes.
19
Receives messages via AMQP, manages pool of worker threads
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]),
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))
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
37
39
from nova import flags
38
from nova import log as logging
39
from nova import service
40
from nova import utils
41
from nova import twistd
42
from nova.compute import node
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',
54
logging.getLogger().setLevel(logging.DEBUG)
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))
62
conn = rpc.Connection.instance()
63
consumer_all = rpc.AdapterConsumer(
65
topic='%s' % FLAGS.compute_topic,
68
consumer_node = rpc.AdapterConsumer(
70
topic='%s.%s' % (FLAGS.compute_topic, FLAGS.node_name),
73
# heartbeat = task.LoopingCall(n.report_state)
74
# heartbeat.start(interval=FLAGS.node_report_state_interval, now=False)
76
injected = consumer_all.attach_to_twisted()
77
injected = consumer_node.attach_to_twisted()
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)
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()
47
server = service.Service.create(binary='nova-compute')
90
twistd.serve(__file__)
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__':