This website requires JavaScript.
8726fc061b53b361207cb38e88cd5b1d2e401637
nova /bin /nova-compute
103 lines
3.6 KiB
Plaintext
2010年05月27日 23:05:26 -07:00
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2010年06月23日 22:04:16 -07:00
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
2010年06月24日 04:11:55 +01:00
#
2010年06月23日 22:04:16 -07:00
# Copyright 2010 Anso Labs, LLC
2010年06月24日 04:11:55 +01:00
#
2010年06月23日 22:04:16 -07:00
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
2010年06月24日 04:11:55 +01:00
#
2010年05月27日 23:05:26 -07:00
# Unless required by applicable law or agreed to in writing, software
2010年06月23日 22:04:16 -07:00
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
2010年05月27日 23:05:26 -07:00
"""
Twistd daemon for the nova compute nodes.
Receives messages via AMQP, manages pool of worker threads
2010年06月24日 04:11:55 +01:00
for async tasks.
2010年05月27日 23:05:26 -07:00
"""
# NOTE(termie): kludge so that we can run this from the bin directory in the
# checkout without having to screw with paths
NOVA_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'nova')
if os.path.exists(NOVA_PATH):
sys.path.insert(0, os.path.dirname(NOVA_PATH))
from carrot import connection
from carrot import messaging
from twisted.internet import task
from twisted.application import service
from nova.compute import node
# NOTE(termie): This file will necessarily be re-imported under different
# context when the twistd.serve() call is made below so any
# flags we define here will have to be conditionally defined,
# flags defined by imported modules are safe.
if 'node_report_state_interval' not in FLAGS:
flags.DEFINE_integer('node_report_state_interval', 10,
'seconds between nodes reporting state to cloud',
logging.getLogger().setLevel(logging.DEBUG)
logging.warn('Starting compute node')
2010年06月24日 04:11:55 +01:00
n = node.Node()
2010年05月27日 23:05:26 -07:00
d = n.adopt_instances()
d.addCallback(lambda x: logging.info('Adopted %d instances', x))
conn = rpc.Connection.instance()
consumer_all = rpc.AdapterConsumer(
topic='%s' % FLAGS.compute_topic,
consumer_node = rpc.AdapterConsumer(
topic='%s.%s' % (FLAGS.compute_topic, FLAGS.node_name),
# heartbeat = task.LoopingCall(n.report_state)
# heartbeat.start(interval=FLAGS.node_report_state_interval, now=False)
injected = consumer_all.attach_to_twisted()
injected = consumer_node.attach_to_twisted()
# This is the parent service that twistd will be looking for when it
# parses this file, return it so that we can get it into globals below
application = service.Application('nova-compute')
n.setServiceParent(application)
# NOTE(termie): When this script is executed from the commandline what it will
# actually do is tell the twistd application runner that it
# should run this file as a twistd application (see below).
if __name__ == '__main__':
# NOTE(termie): When this script is loaded by the twistd application runner
# this code path will be executed and twistd will expect a
# variable named 'application' to be available, it will then
# handle starting it and stopping it.
if __name__ == '__builtin__':