updated models a bit and removed service classes
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
Twistd daemon for the nova compute nodes.
|
||||
"""
|
||||
|
||||
from nova import service
|
||||
from nova import twistd
|
||||
from nova.compute import service
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
twistd.serve(__file__)
|
||||
|
||||
if __name__ == '__builtin__':
|
||||
application = service.ComputeService.create() # pylint: disable=C0103
|
||||
application = service.Service.create() # pylint: disable=C0103
|
||||
|
||||
@@ -21,16 +21,12 @@
|
||||
Twistd daemon for the nova network nodes.
|
||||
"""
|
||||
|
||||
from nova import flags
|
||||
from nova import service
|
||||
from nova import twistd
|
||||
|
||||
from nova.network import service
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
twistd.serve(__file__)
|
||||
|
||||
if __name__ == '__builtin__':
|
||||
application = service.NetworkService.create() # pylint: disable-msg=C0103
|
||||
application = service.Service.create() # pylint: disable-msg=C0103
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
Twistd daemon for the nova volume nodes.
|
||||
"""
|
||||
|
||||
from nova import service
|
||||
from nova import twistd
|
||||
from nova.volume import service
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
twistd.serve(__file__)
|
||||
|
||||
if __name__ == '__builtin__':
|
||||
application = service.VolumeService.create() # pylint: disable-msg=C0103
|
||||
application = service.Service.create() # pylint: disable-msg=C0103
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# 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
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Compute service allows rpc calls to the compute manager and reports state
|
||||
to the database.
|
||||
"""
|
||||
|
||||
from nova import service
|
||||
|
||||
|
||||
class ComputeService(service.Service):
|
||||
"""
|
||||
Compute Service automatically passes commands on to the Compute Manager
|
||||
"""
|
||||
pass
|
||||
@@ -20,8 +20,12 @@
|
||||
SQLAlchemy models for nova data
|
||||
"""
|
||||
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
# TODO(vish): clean up these imports
|
||||
from sqlalchemy.orm import relationship, backref, validates, exc
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy import ForeignKey, DateTime, Boolean, Text
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
@@ -42,8 +46,8 @@ class NovaBase(object):
|
||||
__table_args__ = {'mysql_engine': 'InnoDB'}
|
||||
__table_initialized__ = False
|
||||
__prefix__ = 'none'
|
||||
created_at = Column(DateTime)
|
||||
updated_at = Column(DateTime)
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, onupdate=datetime.datetime.now)
|
||||
deleted = Column(Boolean, default=False)
|
||||
|
||||
@classmethod
|
||||
@@ -78,7 +82,8 @@ class NovaBase(object):
|
||||
.filter_by(deleted=False) \
|
||||
.one()
|
||||
except exc.NoResultFound:
|
||||
raise exception.NotFound("No model for id %s" % obj_id)
|
||||
new_exc = exception.NotFound("No model for id %s" % obj_id)
|
||||
raise new_exc.__class__, new_exc, sys.exc_info()[2]
|
||||
else:
|
||||
with managed_session() as sess:
|
||||
return cls.find(obj_id, session=sess)
|
||||
@@ -161,6 +166,7 @@ class Daemon(BASE, NovaBase):
|
||||
id = Column(Integer, primary_key=True)
|
||||
host = Column(String(255), ForeignKey('hosts.id'))
|
||||
binary = Column(String(255))
|
||||
topic = Column(String(255))
|
||||
report_count = Column(Integer, nullable=False, default=0)
|
||||
|
||||
@classmethod
|
||||
@@ -173,8 +179,9 @@ class Daemon(BASE, NovaBase):
|
||||
.filter_by(deleted=False) \
|
||||
.one()
|
||||
except exc.NoResultFound:
|
||||
raise exception.NotFound("No model for %s, %s" % (host,
|
||||
new_exc = exception.NotFound("No model for %s, %s" % (host,
|
||||
binary))
|
||||
raise new_exc.__class__, new_exc, sys.exc_info()[2]
|
||||
else:
|
||||
with managed_session() as sess:
|
||||
return cls.find_by_args(host, binary, session=sess)
|
||||
@@ -344,7 +351,8 @@ class FixedIp(BASE, NovaBase):
|
||||
.filter_by(deleted=False) \
|
||||
.one()
|
||||
except exc.NoResultFound:
|
||||
raise exception.NotFound("No model for address %s" % str_id)
|
||||
new_exc = exception.NotFound("No model for address %s" % str_id)
|
||||
raise new_exc.__class__, new_exc, sys.exc_info()[2]
|
||||
else:
|
||||
with managed_session() as sess:
|
||||
return cls.find_by_str(str_id, session=sess)
|
||||
@@ -374,7 +382,8 @@ class FloatingIp(BASE, NovaBase):
|
||||
.filter_by(deleted=False) \
|
||||
.one()
|
||||
except exc.NoResultFound:
|
||||
raise exception.NotFound("No model for address %s" % str_id)
|
||||
new_exc = exception.NotFound("No model for address %s" % str_id)
|
||||
raise new_exc.__class__, new_exc, sys.exc_info()[2]
|
||||
else:
|
||||
with managed_session() as sess:
|
||||
return cls.find_by_str(str_id, session=sess)
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# 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
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Network service allows rpc calls to the network manager and reports state
|
||||
to the database.
|
||||
"""
|
||||
|
||||
from nova import service
|
||||
|
||||
|
||||
class NetworkService(service.Service):
|
||||
"""
|
||||
Network Service automatically passes commands on to the Network Manager
|
||||
"""
|
||||
pass
|
||||
@@ -44,8 +44,11 @@ flags.DEFINE_integer('report_interval', 10,
|
||||
class Service(object, service.Service):
|
||||
"""Base class for workers that run on hosts."""
|
||||
|
||||
def __init__(self, manager, *args, **kwargs):
|
||||
self.manager = manager
|
||||
def __init__(self, host, binary, topic, manager, *args, **kwargs):
|
||||
self.host = host
|
||||
self.binary = binary
|
||||
self.topic = topic
|
||||
self.manager = utils.import_object(manager)
|
||||
self.model_disconnected = False
|
||||
super(Service, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -57,44 +60,44 @@ class Service(object, service.Service):
|
||||
|
||||
@classmethod
|
||||
def create(cls,
|
||||
report_interval=None,
|
||||
bin_name=None,
|
||||
host=None,
|
||||
binary=None,
|
||||
topic=None,
|
||||
manager=None):
|
||||
manager=None,
|
||||
report_interval=None):
|
||||
"""Instantiates class and passes back application object.
|
||||
|
||||
Args:
|
||||
report_interval, defaults to flag
|
||||
bin_name, defaults to basename of executable
|
||||
host, defaults to FLAGS.host
|
||||
binary, defaults to basename of executable
|
||||
topic, defaults to bin_name - "nova-" part
|
||||
manager, defaults to FLAGS.<topic>_manager
|
||||
report_interval, defaults to FLAGS.report_interval
|
||||
"""
|
||||
if not report_interval:
|
||||
report_interval = FLAGS.report_interval
|
||||
|
||||
# NOTE(vish): magic to automatically determine bin_name and topic
|
||||
if not bin_name:
|
||||
bin_name = os.path.basename(inspect.stack()[-1][1])
|
||||
if not host:
|
||||
host = FLAGS.host
|
||||
if not binary:
|
||||
binary = os.path.basename(inspect.stack()[-1][1])
|
||||
if not topic:
|
||||
topic = bin_name.rpartition("nova-")[2]
|
||||
topic = binary.rpartition("nova-")[2]
|
||||
if not manager:
|
||||
manager = FLAGS.get('%s_manager' % topic, None)
|
||||
manager_ref = utils.import_object(manager)
|
||||
logging.warn("Starting %s node", topic)
|
||||
service_ref = cls(manager_ref)
|
||||
service_obj = cls(FLAGS.host, binary, topic, manager)
|
||||
conn = rpc.Connection.instance()
|
||||
consumer_all = rpc.AdapterConsumer(
|
||||
connection=conn,
|
||||
topic='%s' % topic,
|
||||
proxy=service_ref)
|
||||
proxy=service_obj)
|
||||
consumer_node = rpc.AdapterConsumer(
|
||||
connection=conn,
|
||||
topic='%s.%s' % (topic, FLAGS.host),
|
||||
proxy=service_ref)
|
||||
proxy=service_obj)
|
||||
|
||||
pulse = task.LoopingCall(service_ref.report_state,
|
||||
FLAGS.host,
|
||||
bin_name)
|
||||
pulse = task.LoopingCall(service_obj.report_state)
|
||||
pulse.start(interval=report_interval, now=False)
|
||||
|
||||
consumer_all.attach_to_twisted()
|
||||
@@ -102,21 +105,24 @@ class Service(object, service.Service):
|
||||
|
||||
# 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.
|
||||
application = service.Application(bin_name)
|
||||
service_ref.setServiceParent(application)
|
||||
application = service.Application(binary)
|
||||
service_obj.setServiceParent(application)
|
||||
return application
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def report_state(self, host, binary, context=None):
|
||||
def report_state(self, context=None):
|
||||
"""Update the state of this daemon in the datastore."""
|
||||
try:
|
||||
try:
|
||||
daemon_ref = db.daemon_get_by_args(context, host, binary)
|
||||
daemon_ref = db.daemon_get_by_args(context,
|
||||
self.host,
|
||||
self.binary)
|
||||
daemon_id = daemon_ref['id']
|
||||
except exception.NotFound:
|
||||
daemon_id = db.daemon_create(context, {'host': host,
|
||||
'binary': binary,
|
||||
'report_count': 0})
|
||||
daemon_id = db.daemon_create(context, {'host': self.host,
|
||||
'binary': self.binary,
|
||||
'topic': self.topic,
|
||||
'report_count': 0})
|
||||
daemon_ref = db.daemon_get(context, daemon_id)
|
||||
db.daemon_update(context,
|
||||
daemon_id,
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# 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
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Volume service allows rpc calls to the volume manager and reports state
|
||||
to the database.
|
||||
"""
|
||||
|
||||
from nova import service
|
||||
|
||||
|
||||
class VolumeService(service.Service):
|
||||
"""
|
||||
Volume Service automatically passes commands on to the Volume Manager
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user