rename node_name to host

This commit is contained in:
Vishvananda Ishaya
2010-08-31 16:48:41 -07:00
parent 28511c5c6c
commit 0ca11ccc49
4 changed files with 67 additions and 21 deletions

View File

@@ -1,3 +1,23 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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.
"""
DB abstraction for Nova
"""
from nova.db.api import * from nova.db.api import *

View File

@@ -15,11 +15,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
"""
Defines interface for DB access
"""
from nova import exception from nova import exception
from nova import flags from nova import flags
from nova import utils from nova import utils
from nova import validate
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
@@ -33,14 +35,17 @@ _impl = utils.LazyPluggable(FLAGS['db_backend'],
# TODO(vish): where should these exceptions go? # TODO(vish): where should these exceptions go?
class NoMoreAddresses(exception.Error): class NoMoreAddresses(exception.Error):
"""No more available addresses"""
pass pass
class NoMoreBlades(exception.Error): class NoMoreBlades(exception.Error):
"""No more available blades"""
pass pass
class NoMoreNetworks(exception.Error): class NoMoreNetworks(exception.Error):
"""No more available networks"""
pass pass
@@ -52,9 +57,9 @@ def daemon_get(context, daemon_id):
return _impl.daemon_get(context, daemon_id) return _impl.daemon_get(context, daemon_id)
def daemon_get_by_args(context, node_name, binary): def daemon_get_by_args(context, host, binary):
"""Get the state of an daemon by node name and binary.""" """Get the state of an daemon by node name and binary."""
return _impl.daemon_get_by_args(context, node_name, binary) return _impl.daemon_get_by_args(context, host, binary)
def daemon_create(context, values): def daemon_create(context, values):
@@ -74,12 +79,12 @@ def daemon_update(context, daemon_id, values):
################### ###################
def floating_ip_allocate_address(context, node_name, project_id): def floating_ip_allocate_address(context, host, project_id):
"""Allocate free floating ip and return the address. """Allocate free floating ip and return the address.
Raises if one is not available. Raises if one is not available.
""" """
return _impl.floating_ip_allocate_address(context, node_name, project_id) return _impl.floating_ip_allocate_address(context, host, project_id)
def floating_ip_create(context, address, host): def floating_ip_create(context, address, host):

View File

@@ -1,3 +1,24 @@
from models import register_models # vim: tabstop=4 shiftwidth=4 softtabstop=4
register_models() # 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.
"""
SQLAlchemy database backend
"""
from nova.db.sqlalchemy import models
models.register_models()

View File

@@ -33,8 +33,8 @@ def daemon_get(context, daemon_id):
return models.Daemon.find(daemon_id) return models.Daemon.find(daemon_id)
def daemon_get_by_args(context, node_name, binary): def daemon_get_by_args(context, host, binary):
return models.Daemon.find_by_args(node_name, binary) return models.Daemon.find_by_args(host, binary)
def daemon_create(context, values): def daemon_create(context, values):
@@ -55,10 +55,10 @@ def daemon_update(context, daemon_id, values):
################### ###################
def floating_ip_allocate_address(context, node_name, project_id): def floating_ip_allocate_address(context, host, project_id):
with managed_session(autocommit=False) as session: with managed_session(autocommit=False) as session:
floating_ip_ref = session.query(models.FloatingIp) \ floating_ip_ref = session.query(models.FloatingIp) \
.filter_by(node_name=node_name) \ .filter_by(host=host) \
.filter_by(fixed_ip_id=None) \ .filter_by(fixed_ip_id=None) \
.filter_by(deleted=False) \ .filter_by(deleted=False) \
.with_lockmode('update') \ .with_lockmode('update') \
@@ -76,7 +76,7 @@ def floating_ip_allocate_address(context, node_name, project_id):
def floating_ip_create(context, address, host): def floating_ip_create(context, address, host):
floating_ip_ref = models.FloatingIp() floating_ip_ref = models.FloatingIp()
floating_ip_ref['address'] = address floating_ip_ref['address'] = address
floating_ip_ref['node_name'] = host floating_ip_ref['host'] = host
floating_ip_ref.save() floating_ip_ref.save()
return floating_ip_ref return floating_ip_ref
@@ -131,8 +131,8 @@ def floating_ip_get_instance(context, address):
def fixed_ip_allocate(context, network_id): def fixed_ip_allocate(context, network_id):
with managed_session(autocommit=False) as session: with managed_session(autocommit=False) as session:
network_or_none = or_(models.FixedIp.network_id==network_id, network_or_none = or_(models.FixedIp.network_id == network_id,
models.FixedIp.network_id==None) models.FixedIp.network_id == None)
fixed_ip_ref = session.query(models.FixedIp) \ fixed_ip_ref = session.query(models.FixedIp) \
.filter(network_or_none) \ .filter(network_or_none) \
.filter_by(reserved=False) \ .filter_by(reserved=False) \
@@ -270,7 +270,7 @@ def instance_get_floating_address(context, instance_id):
def instance_get_host(context, instance_id): def instance_get_host(context, instance_id):
instance_ref = instance_get(context, instance_id) instance_ref = instance_get(context, instance_id)
return instance_ref['node_name'] return instance_ref['host']
def instance_is_vpn(context, instance_id): def instance_is_vpn(context, instance_id):
@@ -376,7 +376,7 @@ def network_get_by_bridge(context, bridge):
def network_get_host(context, network_id): def network_get_host(context, network_id):
network_ref = network_get(context, network_id) network_ref = network_get(context, network_id)
return network_ref['node_name'] return network_ref['host']
def network_get_index(context, network_id): def network_get_index(context, network_id):
@@ -418,13 +418,13 @@ def network_set_host(context, network_id, host_id):
network_id) network_id)
# NOTE(vish): if with_lockmode isn't supported, as in sqlite, # NOTE(vish): if with_lockmode isn't supported, as in sqlite,
# then this has concurrency issues # then this has concurrency issues
if network.node_name: if network.host:
session.commit() session.commit()
return network['node_name'] return network['host']
network['node_name'] = host_id network['host'] = host_id
session.add(network) session.add(network)
session.commit() session.commit()
return network['node_name'] return network['host']
def network_update(context, network_id, values): def network_update(context, network_id, values):
@@ -549,7 +549,7 @@ def volume_get_by_str(context, str_id):
def volume_get_host(context, volume_id): def volume_get_host(context, volume_id):
volume_ref = volume_get(context, volume_id) volume_ref = volume_get(context, volume_id)
return volume_ref['node_name'] return volume_ref['host']
def volume_get_shelf_and_blade(context, volume_id): def volume_get_shelf_and_blade(context, volume_id):