summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-02 11:33:06 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-09-02 11:33:06 -0700
commite55234bd86b96aa3f05b06eb1efbb1baa61a93f1 (patch)
tree23ca551fd42ffa5e0f9df8267dd60f0de689b322
parent7edff9298f7f01e158f90c93432384903d71e033 (diff)
parentbb69664ba0bc52a196dd3d465997966e52b0a92a (diff)
merged orm branch
-rwxr-xr-xbin/nova-compute4
-rwxr-xr-xbin/nova-network8
-rwxr-xr-xbin/nova-volume4
-rw-r--r--nova/compute/service.py31
-rw-r--r--nova/db/sqlalchemy/api.py56
-rw-r--r--nova/db/sqlalchemy/models.py21
-rw-r--r--nova/network/service.py31
-rw-r--r--nova/service.py56
-rw-r--r--nova/volume/service.py31
9 files changed, 80 insertions, 162 deletions
diff --git a/bin/nova-compute b/bin/nova-compute
index cf9de9bbf..cc4c9e2ff 100755
--- a/bin/nova-compute
+++ b/bin/nova-compute
@@ -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
diff --git a/bin/nova-network b/bin/nova-network
index 6434b6ec3..040b35e04 100755
--- a/bin/nova-network
+++ b/bin/nova-network
@@ -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
diff --git a/bin/nova-volume b/bin/nova-volume
index 25b5871a3..fac4b5d01 100755
--- a/bin/nova-volume
+++ b/bin/nova-volume
@@ -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
diff --git a/nova/compute/service.py b/nova/compute/service.py
deleted file mode 100644
index 4df7e7171..000000000
--- a/nova/compute/service.py
+++ /dev/null
@@ -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
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index aabd74984..07b0a43ff 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -82,8 +82,8 @@ def daemon_create(_context, values):
return daemon_ref.id
-def daemon_update(_context, daemon_id, values):
- daemon_ref = daemon_get(_context, daemon_id)
+def daemon_update(context, daemon_id, values):
+ daemon_ref = daemon_get(context, daemon_id)
for (key, value) in values.iteritems():
daemon_ref[key] = value
daemon_ref.save()
@@ -212,8 +212,8 @@ def fixed_ip_get_network(_context, address):
return models.FixedIp.find_by_str(address, session=session).network
-def fixed_ip_deallocate(_context, address):
- fixed_ip_ref = fixed_ip_get_by_address(_context, address)
+def fixed_ip_deallocate(context, address):
+ fixed_ip_ref = fixed_ip_get_by_address(context, address)
fixed_ip_ref['allocated'] = False
fixed_ip_ref.save()
@@ -235,8 +235,8 @@ def fixed_ip_instance_disassociate(_context, address):
session.commit()
-def fixed_ip_update(_context, address, values):
- fixed_ip_ref = fixed_ip_get_by_address(_context, address)
+def fixed_ip_update(context, address, values):
+ fixed_ip_ref = fixed_ip_get_by_address(context, address)
for (key, value) in values.iteritems():
fixed_ip_ref[key] = value
fixed_ip_ref.save()
@@ -253,8 +253,8 @@ def instance_create(_context, values):
return instance_ref.id
-def instance_destroy(_context, instance_id):
- instance_ref = instance_get(_context, instance_id)
+def instance_destroy(context, instance_id):
+ instance_ref = instance_get(context, instance_id)
instance_ref.delete()
@@ -305,23 +305,23 @@ def instance_get_floating_address(_context, instance_id):
return instance_ref.fixed_ip.floating_ips[0]['address']
-def instance_get_host(_context, instance_id):
- instance_ref = instance_get(_context, instance_id)
+def instance_get_host(context, instance_id):
+ instance_ref = instance_get(context, instance_id)
return instance_ref['host']
-def instance_is_vpn(_context, instance_id):
- instance_ref = instance_get(_context, instance_id)
+def instance_is_vpn(context, instance_id):
+ instance_ref = instance_get(context, instance_id)
return instance_ref['image_id'] == FLAGS.vpn_image_id
-def instance_state(_context, instance_id, state, description=None):
- instance_ref = instance_get(_context, instance_id)
+def instance_state(context, instance_id, state, description=None):
+ instance_ref = instance_get(context, instance_id)
instance_ref.set_state(state, description)
-def instance_update(_context, instance_id, values):
- instance_ref = instance_get(_context, instance_id)
+def instance_update(context, instance_id, values):
+ instance_ref = instance_get(context, instance_id)
for (key, value) in values.iteritems():
instance_ref[key] = value
instance_ref.save()
@@ -413,8 +413,8 @@ def network_get_by_bridge(_context, bridge):
return rv
-def network_get_host(_context, network_id):
- network_ref = network_get(_context, network_id)
+def network_get_host(context, network_id):
+ network_ref = network_get(context, network_id)
return network_ref['host']
@@ -466,8 +466,8 @@ def network_set_host(_context, network_id, host_id):
return network['host']
-def network_update(_context, network_id, values):
- network_ref = network_get(_context, network_id)
+def network_update(context, network_id, values):
+ network_ref = network_get(context, network_id)
for (key, value) in values.iteritems():
network_ref[key] = value
network_ref.save()
@@ -529,8 +529,8 @@ def volume_allocate_shelf_and_blade(_context, volume_id):
return (export_device.shelf_id, export_device.blade_id)
-def volume_attached(_context, volume_id, instance_id, mountpoint):
- volume_ref = volume_get(_context, volume_id)
+def volume_attached(context, volume_id, instance_id, mountpoint):
+ volume_ref = volume_get(context, volume_id)
volume_ref.instance_id = instance_id
volume_ref['status'] = 'in-use'
volume_ref['mountpoint'] = mountpoint
@@ -557,8 +557,8 @@ def volume_destroy(_context, volume_id):
session.commit()
-def volume_detached(_context, volume_id):
- volume_ref = volume_get(_context, volume_id)
+def volume_detached(context, volume_id):
+ volume_ref = volume_get(context, volume_id)
volume_ref['instance_id'] = None
volume_ref['mountpoint'] = None
volume_ref['status'] = 'available'
@@ -586,8 +586,8 @@ def volume_get_by_str(_context, str_id):
return models.Volume.find_by_str(str_id)
-def volume_get_host(_context, volume_id):
- volume_ref = volume_get(_context, volume_id)
+def volume_get_host(context, volume_id):
+ volume_ref = volume_get(context, volume_id)
return volume_ref['host']
@@ -601,8 +601,8 @@ def volume_get_shelf_and_blade(_context, volume_id):
return (export_device.shelf_id, export_device.blade_id)
-def volume_update(_context, volume_id, values):
- volume_ref = volume_get(_context, volume_id)
+def volume_update(context, volume_id, values):
+ volume_ref = volume_get(context, volume_id)
for (key, value) in values.iteritems():
volume_ref[key] = value
volume_ref.save()
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 9e15614f7..8ba252a76 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -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)
diff --git a/nova/network/service.py b/nova/network/service.py
deleted file mode 100644
index 28f017a27..000000000
--- a/nova/network/service.py
+++ /dev/null
@@ -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
diff --git a/nova/service.py b/nova/service.py
index a6df7335b..e3104fbaa 100644
--- a/nova/service.py
+++ b/nova/service.py
@@ -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,
diff --git a/nova/volume/service.py b/nova/volume/service.py
deleted file mode 100644
index f1b1d8695..000000000
--- a/nova/volume/service.py
+++ /dev/null
@@ -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