summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorCerberus <matt.dietz@rackspace.com>2010-09-29 17:24:36 -0500
committerCerberus <matt.dietz@rackspace.com>2010-09-29 17:24:36 -0500
commit0030da605c30bbf3b1424aae86bbdc07ff7c50c2 (patch)
tree5d7498de30ebc00ba43221a07f204a98984dab8e /nova/db
parent35741ff23bec2b4f301b93128fd018e9c8e70945 (diff)
parent5654c7848048ecad0aef020b96001aed3e5c1bdc (diff)
Merge from trunk and networking setup for new instances
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py28
-rw-r--r--nova/db/sqlalchemy/api.py38
-rw-r--r--nova/db/sqlalchemy/models.py11
3 files changed, 59 insertions, 18 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 208720ff9..b68a0fe8f 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -161,10 +161,15 @@ def floating_ip_get_all(context):
def floating_ip_get_all_by_host(context, host):
- """Get all floating ips."""
+ """Get all floating ips by host."""
return IMPL.floating_ip_get_all_by_host(context, host)
+def floating_ip_get_all_by_project(context, project_id):
+ """Get all floating ips by project."""
+ return IMPL.floating_ip_get_all_by_project(context, project_id)
+
+
def floating_ip_get_by_address(context, address):
"""Get a floating ip by address or raise if it doesn't exist."""
return IMPL.floating_ip_get_by_address(context, address)
@@ -255,14 +260,14 @@ def instance_get_all_by_user(context, user_id):
"""Get all instances."""
return IMPL.instance_get_all(context, user_id)
-def instance_get_by_project(context, project_id):
+def instance_get_all_by_project(context, project_id):
"""Get all instance belonging to a project."""
- return IMPL.instance_get_by_project(context, project_id)
+ return IMPL.instance_get_all_by_project(context, project_id)
-def instance_get_by_reservation(context, reservation_id):
+def instance_get_all_by_reservation(context, reservation_id):
"""Get all instance belonging to a reservation."""
- return IMPL.instance_get_by_reservation(context, reservation_id)
+ return IMPL.instance_get_all_by_reservation(context, reservation_id)
def instance_get_fixed_address(context, instance_id):
@@ -396,9 +401,12 @@ def network_index_count(context):
return IMPL.network_index_count(context)
-def network_index_create(context, values):
- """Create a network index from the values dict"""
- return IMPL.network_index_create(context, values)
+def network_index_create_safe(context, values):
+ """Create a network index from the values dict
+
+ The index is not returned. If the create violates the unique
+ constraints because the index already exists, no exception is raised."""
+ return IMPL.network_index_create_safe(context, values)
def network_set_cidr(context, network_id, cidr):
@@ -535,9 +543,9 @@ def volume_get_instance(context, volume_id):
return IMPL.volume_get_instance(context, volume_id)
-def volume_get_by_project(context, project_id):
+def volume_get_all_by_project(context, project_id):
"""Get all volumes belonging to a project."""
- return IMPL.volume_get_by_project(context, project_id)
+ return IMPL.volume_get_all_by_project(context, project_id)
def volume_get_by_ec2_id(context, ec2_id):
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index ab8dc8004..9c3caf9af 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -19,6 +19,8 @@
Implementation of SQLAlchemy backend
"""
+import sys
+
from nova import db
from nova import exception
from nova import flags
@@ -26,6 +28,7 @@ from nova import utils
from nova.db.sqlalchemy import models
from nova.db.sqlalchemy.session import get_session
from sqlalchemy import or_
+from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import joinedload_all
from sqlalchemy.sql import exists, func
@@ -166,6 +169,7 @@ def floating_ip_allocate_address(_context, host, project_id):
floating_ip_ref = session.query(models.FloatingIp
).filter_by(host=host
).filter_by(fixed_ip_id=None
+ ).filter_by(project_id=None
).filter_by(deleted=False
).with_lockmode('update'
).first()
@@ -253,6 +257,14 @@ def floating_ip_get_all_by_host(_context, host):
).filter_by(deleted=False
).all()
+def floating_ip_get_all_by_project(_context, project_id):
+ session = get_session()
+ return session.query(models.FloatingIp
+ ).options(joinedload_all('fixed_ip.instance')
+ ).filter_by(project_id=project_id
+ ).filter_by(deleted=False
+ ).all()
+
def floating_ip_get_by_address(_context, address):
return models.FloatingIp.find_by_str(address)
@@ -328,7 +340,17 @@ def fixed_ip_disassociate(_context, address):
def fixed_ip_get_by_address(_context, address):
- return models.FixedIp.find_by_str(address)
+ session = get_session()
+ with session.begin():
+ try:
+ return session.query(models.FixedIp
+ ).options(joinedload_all('instance')
+ ).filter_by(address=address
+ ).filter_by(deleted=False
+ ).one()
+ except exc.NoResultFound:
+ new_exc = exception.NotFound("No model for address %s" % address)
+ raise new_exc.__class__, new_exc, sys.exc_info()[2]
def fixed_ip_get_instance(_context, address):
@@ -406,7 +428,7 @@ def instance_get_all_by_user(context, user_id):
).filter_by(user_id=user_id
).all()
-def instance_get_by_project(context, project_id):
+def instance_get_all_by_project(context, project_id):
session = get_session()
return session.query(models.Instance
).options(joinedload_all('fixed_ip.floating_ips')
@@ -415,7 +437,7 @@ def instance_get_by_project(context, project_id):
).all()
-def instance_get_by_reservation(_context, reservation_id):
+def instance_get_all_by_reservation(_context, reservation_id):
session = get_session()
return session.query(models.Instance
).options(joinedload_all('fixed_ip.floating_ips')
@@ -600,6 +622,7 @@ def network_get(_context, network_id):
def network_get_associated_fixed_ips(_context, network_id):
session = get_session()
return session.query(models.FixedIp
+ ).options(joinedload_all('instance')
).filter_by(network_id=network_id
).filter(models.FixedIp.instance_id != None
).filter_by(deleted=False
@@ -637,11 +660,14 @@ def network_index_count(_context):
return models.NetworkIndex.count()
-def network_index_create(_context, values):
+def network_index_create_safe(_context, values):
network_index_ref = models.NetworkIndex()
for (key, value) in values.iteritems():
network_index_ref[key] = value
- network_index_ref.save()
+ try:
+ network_index_ref.save()
+ except IntegrityError:
+ pass
def network_set_host(_context, network_id, host_id):
@@ -850,7 +876,7 @@ def volume_get_all(context):
return models.Volume.all(deleted=_deleted(context))
-def volume_get_by_project(context, project_id):
+def volume_get_all_by_project(context, project_id):
session = get_session()
return session.query(models.Volume
).filter_by(project_id=project_id
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 22446fc64..6cb377476 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -241,7 +241,6 @@ class Instance(BASE, NovaBase):
vcpus = Column(Integer)
local_gb = Column(Integer)
-
hostname = Column(String(255))
host = Column(String(255)) # , ForeignKey('hosts.id'))
@@ -255,6 +254,10 @@ class Instance(BASE, NovaBase):
scheduled_at = Column(DateTime)
launched_at = Column(DateTime)
terminated_at = Column(DateTime)
+
+ display_name = Column(String(255))
+ display_description = Column(String(255))
+
# TODO(vish): see Ewan's email about state improvements, probably
# should be in a driver base class or some such
# vmstate_state = running, halted, suspended, paused
@@ -291,6 +294,10 @@ class Volume(BASE, NovaBase):
launched_at = Column(DateTime)
terminated_at = Column(DateTime)
+ display_name = Column(String(255))
+ display_description = Column(String(255))
+
+
class Quota(BASE, NovaBase):
"""Represents quota overrides for a project"""
__tablename__ = 'quotas'
@@ -400,7 +407,7 @@ class NetworkIndex(BASE, NovaBase):
"""
__tablename__ = 'network_indexes'
id = Column(Integer, primary_key=True)
- index = Column(Integer)
+ index = Column(Integer, unique=True)
network_id = Column(Integer, ForeignKey('networks.id'), nullable=True)
network = relationship(Network, backref=backref('network_index',
uselist=False))