summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authormasumotok <masumotok@nttdata.co.jp>2010-12-31 04:03:37 +0900
committermasumotok <masumotok@nttdata.co.jp>2010-12-31 04:03:37 +0900
commitbf7bc8725fcc26cc5074ea1628bcba6ac6093768 (patch)
treedd845322f758c2353f295afa44d4e6455564ffff /nova/db
parent85acbbe916df8b2d18f0dc3a0b8cad9fcfdd6907 (diff)
parentbd6a3cb1acb68ac2252c1bafc531b3b12f9746d8 (diff)
merge recent revision(version of 2010/12/28)
Change: 1. Use greenthread instead of defer at nova.virt.libvirt_conn.live_migration. 2. Move nova.scheduler.manager.live_migration to nova.scheduler.driver 3. Move nova.scheduler.manager.has_enough_resource to nova.scheduler.driver 4. Any check routine in nova-manage.instance.live_migration is moved to nova.scheduler.driver.schedule_live_migration.
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py55
-rw-r--r--nova/db/sqlalchemy/api.py188
-rw-r--r--nova/db/sqlalchemy/models.py41
3 files changed, 241 insertions, 43 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 71e8151e7..e0f48d07e 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -130,6 +130,45 @@ def service_update(context, service_id, values):
###################
+def certificate_create(context, values):
+ """Create a certificate from the values dictionary."""
+ return IMPL.certificate_create(context, values)
+
+
+def certificate_destroy(context, certificate_id):
+ """Destroy the certificate or raise if it does not exist."""
+ return IMPL.certificate_destroy(context, certificate_id)
+
+
+def certificate_get_all_by_project(context, project_id):
+ """Get all certificates for a project."""
+ return IMPL.certificate_get_all_by_project(context, project_id)
+
+
+def certificate_get_all_by_user(context, user_id):
+ """Get all certificates for a user."""
+ return IMPL.certificate_get_all_by_user(context, user_id)
+
+
+def certificate_get_all_by_user_and_project(context, user_id, project_id):
+ """Get all certificates for a user and project."""
+ return IMPL.certificate_get_all_by_user_and_project(context,
+ user_id,
+ project_id)
+
+
+def certificate_update(context, certificate_id, values):
+ """Set the given properties on an certificate and update it.
+
+ Raises NotFound if service does not exist.
+
+ """
+ return IMPL.service_update(context, certificate_id, values)
+
+
+###################
+
+
def floating_ip_allocate_address(context, host, project_id):
"""Allocate free floating ip and return the address.
@@ -308,6 +347,11 @@ def instance_get_floating_address(context, instance_id):
return IMPL.instance_get_floating_address(context, instance_id)
+def instance_get_project_vpn(context, project_id):
+ """Get a vpn instance by project or return None."""
+ return IMPL.instance_get_project_vpn(context, project_id)
+
+
def instance_get_by_internal_id(context, internal_id):
"""Get an instance by internal id."""
return IMPL.instance_get_by_internal_id(context, internal_id)
@@ -364,6 +408,11 @@ def instance_get_disk_sum_by_host_and_project(context, hostname, proj_id):
proj_id)
+def instance_action_create(context, values):
+ """Create an instance action from the values dictionary."""
+ return IMPL.instance_action_create(context, values)
+
+
###################
@@ -498,12 +547,14 @@ def network_update(context, network_id, values):
###################
-def project_get_network(context, project_id):
+def project_get_network(context, project_id, associate=True):
"""Return the network associated with the project.
- Raises NotFound if no such network can be found.
+ If associate is true, it will attempt to associate a new
+ network if one is not found, otherwise it returns None.
"""
+
return IMPL.project_get_network(context, project_id)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index e4792fe23..64af223c4 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -41,7 +41,7 @@ FLAGS = flags.FLAGS
def is_admin_context(context):
"""Indicates if the request context is an administrator."""
if not context:
- warnings.warn('Use of empty request context is deprecated',
+ warnings.warn(_('Use of empty request context is deprecated'),
DeprecationWarning)
raise Exception('die')
return context.is_admin
@@ -130,7 +130,7 @@ def service_get(context, service_id, session=None):
first()
if not result:
- raise exception.NotFound('No service for id %s' % service_id)
+ raise exception.NotFound(_('No service for id %s') % service_id)
return result
@@ -227,7 +227,7 @@ def service_get_by_args(context, host, binary):
filter_by(deleted=can_read_deleted(context)).\
first()
if not result:
- raise exception.NotFound('No service for %s, %s' % (host, binary))
+ raise exception.NotFound(_('No service for %s, %s') % (host, binary))
return result
@@ -252,6 +252,84 @@ def service_update(context, service_id, values):
###################
+@require_admin_context
+def certificate_get(context, certificate_id, session=None):
+ if not session:
+ session = get_session()
+
+ result = session.query(models.Certificate).\
+ filter_by(id=certificate_id).\
+ filter_by(deleted=can_read_deleted(context)).\
+ first()
+
+ if not result:
+ raise exception.NotFound('No certificate for id %s' % certificate_id)
+
+ return result
+
+
+@require_admin_context
+def certificate_create(context, values):
+ certificate_ref = models.Certificate()
+ for (key, value) in values.iteritems():
+ certificate_ref[key] = value
+ certificate_ref.save()
+ return certificate_ref
+
+
+@require_admin_context
+def certificate_destroy(context, certificate_id):
+ session = get_session()
+ with session.begin():
+ certificate_ref = certificate_get(context,
+ certificate_id,
+ session=session)
+ certificate_ref.delete(session=session)
+
+
+@require_admin_context
+def certificate_get_all_by_project(context, project_id):
+ session = get_session()
+ return session.query(models.Certificate).\
+ filter_by(project_id=project_id).\
+ filter_by(deleted=False).\
+ all()
+
+
+@require_admin_context
+def certificate_get_all_by_user(context, user_id):
+ session = get_session()
+ return session.query(models.Certificate).\
+ filter_by(user_id=user_id).\
+ filter_by(deleted=False).\
+ all()
+
+
+@require_admin_context
+def certificate_get_all_by_user_and_project(_context, user_id, project_id):
+ session = get_session()
+ return session.query(models.Certificate).\
+ filter_by(user_id=user_id).\
+ filter_by(project_id=project_id).\
+ filter_by(deleted=False).\
+ all()
+
+
+@require_admin_context
+def certificate_update(context, certificate_id, values):
+ session = get_session()
+ with session.begin():
+ certificate_ref = certificate_get(context,
+ certificate_id,
+ session=session)
+ for (key, value) in values.iteritems():
+ certificate_ref[key] = value
+ certificate_ref.save(session=session)
+
+
+###################
+
+
@require_context
def floating_ip_allocate_address(context, host, project_id):
authorize_project_context(context, project_id)
@@ -385,6 +463,7 @@ def floating_ip_get_by_address(context, address, session=None):
session = get_session()
result = session.query(models.FloatingIp).\
+ options(joinedload_all('fixed_ip.network')).\
filter_by(address=address).\
filter_by(deleted=can_read_deleted(context)).\
first()
@@ -501,7 +580,7 @@ def fixed_ip_get_by_address(context, address, session=None):
options(joinedload('instance')).\
first()
if not result:
- raise exception.NotFound('No floating ip for address %s' % address)
+ raise exception.NotFound(_('No floating ip for address %s') % address)
if is_user_context(context):
authorize_project_context(context, result.instance.project_id)
@@ -538,6 +617,8 @@ def fixed_ip_update(context, address, values):
#TODO(gundlach): instance_create and volume_create are nearly identical
#and should be refactored. I expect there are other copy-and-paste
#functions between the two of them as well.
+
+
@require_context
def instance_create(context, values):
"""Create a new Instance record in the database.
@@ -553,7 +634,7 @@ def instance_create(context, values):
with session.begin():
while instance_ref.internal_id == None:
# Instances have integer internal ids.
- internal_id = random.randint(0, 2 ** 32 - 1)
+ internal_id = random.randint(0, 2 ** 31 - 1)
if not instance_internal_id_exists(context, internal_id,
session=session):
instance_ref.internal_id = internal_id
@@ -589,19 +670,23 @@ def instance_get(context, instance_id, session=None):
if is_admin_context(context):
result = session.query(models.Instance).\
+ options(joinedload_all('fixed_ip.floating_ips')).\
options(joinedload('security_groups')).\
+ options(joinedload('volumes')).\
filter_by(id=instance_id).\
filter_by(deleted=can_read_deleted(context)).\
first()
elif is_user_context(context):
result = session.query(models.Instance).\
+ options(joinedload_all('fixed_ip.floating_ips')).\
options(joinedload('security_groups')).\
+ options(joinedload('volumes')).\
filter_by(project_id=context.project_id).\
filter_by(id=instance_id).\
filter_by(deleted=False).\
first()
if not result:
- raise exception.NotFound('No instance for id %s' % instance_id)
+ raise exception.NotFound(_('No instance for id %s') % instance_id)
return result
@@ -661,6 +746,18 @@ def instance_get_all_by_reservation(context, reservation_id):
all()
+@require_admin_context
+def instance_get_project_vpn(context, project_id):
+ session = get_session()
+ return session.query(models.Instance).\
+ options(joinedload_all('fixed_ip.floating_ips')).\
+ options(joinedload('security_groups')).\
+ filter_by(project_id=project_id).\
+ filter_by(image_id=FLAGS.vpn_image_id).\
+ filter_by(deleted=can_read_deleted(context)).\
+ first()
+
+
@require_context
def instance_get_by_internal_id(context, internal_id):
session = get_session()
@@ -679,7 +776,7 @@ def instance_get_by_internal_id(context, internal_id):
filter_by(deleted=False).\
first()
if not result:
- raise exception.NotFound('Instance %s not found' % (internal_id))
+ raise exception.NotFound(_('Instance %s not found') % (internal_id))
return result
@@ -742,6 +839,7 @@ def instance_update(context, instance_id, values):
instance_ref = instance_get(context, instance_id, session=session)
instance_ref.update(values)
instance_ref.save(session=session)
+ return instance_ref
@require_context
@@ -802,6 +900,17 @@ def instance_get_memory_sum_by_host_and_project(context, hostname, proj_id):
def instance_get_disk_sum_by_host_and_project(context, hostname, proj_id):
return _instance_get_sum_by_host_and_project(context, 'local_gb',
hostname, proj_id)
+@require_context
+def instance_action_create(context, values):
+ """Create an instance action from the values dictionary."""
+ action_ref = models.InstanceActions()
+ action_ref.update(values)
+
+ session = get_session()
+ with session.begin():
+ action_ref.save(session=session)
+ return action_ref
+
###################
@@ -846,7 +955,7 @@ def key_pair_get(context, user_id, name, session=None):
filter_by(deleted=can_read_deleted(context)).\
first()
if not result:
- raise exception.NotFound('no keypair for user %s, name %s' %
+ raise exception.NotFound(_('no keypair for user %s, name %s') %
(user_id, name))
return result
@@ -961,7 +1070,7 @@ def network_get(context, network_id, session=None):
filter_by(deleted=False).\
first()
if not result:
- raise exception.NotFound('No network for id %s' % network_id)
+ raise exception.NotFound(_('No network for id %s') % network_id)
return result
@@ -969,6 +1078,8 @@ def network_get(context, network_id, session=None):
# NOTE(vish): pylint complains because of the long method name, but
# it fits with the names of the rest of the methods
# pylint: disable-msg=C0103
+
+
@require_admin_context
def network_get_associated_fixed_ips(context, network_id):
session = get_session()
@@ -989,7 +1100,7 @@ def network_get_by_bridge(context, bridge):
first()
if not result:
- raise exception.NotFound('No network for bridge %s' % bridge)
+ raise exception.NotFound(_('No network for bridge %s') % bridge)
return result
@@ -1003,7 +1114,7 @@ def network_get_by_instance(_context, instance_id):
filter_by(deleted=False).\
first()
if not rv:
- raise exception.NotFound('No network for instance %s' % instance_id)
+ raise exception.NotFound(_('No network for instance %s') % instance_id)
return rv
@@ -1017,7 +1128,7 @@ def network_set_host(context, network_id, host_id):
with_lockmode('update').\
first()
if not network_ref:
- raise exception.NotFound('No network for id %s' % network_id)
+ raise exception.NotFound(_('No network for id %s') % network_id)
# NOTE(vish): if with_lockmode isn't supported, as in sqlite,
# then this has concurrency issues
@@ -1041,24 +1152,26 @@ def network_update(context, network_id, values):
@require_context
-def project_get_network(context, project_id):
+def project_get_network(context, project_id, associate=True):
session = get_session()
- rv = session.query(models.Network).\
- filter_by(project_id=project_id).\
- filter_by(deleted=False).\
- first()
- if not rv:
+ result = session.query(models.Network).\
+ filter_by(project_id=project_id).\
+ filter_by(deleted=False).\
+ first()
+ if not result:
+ if not associate:
+ return None
try:
return network_associate(context, project_id)
except IntegrityError:
# NOTE(vish): We hit this if there is a race and two
# processes are attempting to allocate the
# network at the same time
- rv = session.query(models.Network).\
- filter_by(project_id=project_id).\
- filter_by(deleted=False).\
- first()
- return rv
+ result = session.query(models.Network).\
+ filter_by(project_id=project_id).\
+ filter_by(deleted=False).\
+ first()
+ return result
###################
@@ -1118,21 +1231,24 @@ def iscsi_target_create_safe(context, values):
###################
+@require_admin_context
def auth_destroy_token(_context, token):
session = get_session()
session.delete(token)
+@require_admin_context
def auth_get_token(_context, token_hash):
session = get_session()
tk = session.query(models.AuthToken).\
filter_by(token_hash=token_hash).\
first()
if not tk:
- raise exception.NotFound('Token %s does not exist' % token_hash)
+ raise exception.NotFound(_('Token %s does not exist') % token_hash)
return tk
+@require_admin_context
def auth_create_token(_context, token):
tk = models.AuthToken()
tk.update(token)
@@ -1153,7 +1269,7 @@ def quota_get(context, project_id, session=None):
filter_by(deleted=can_read_deleted(context)).\
first()
if not result:
- raise exception.NotFound('No quota for project_id %s' % project_id)
+ raise exception.NotFound(_('No quota for project_id %s') % project_id)
return result
@@ -1308,7 +1424,7 @@ def volume_get(context, volume_id, session=None):
filter_by(deleted=False).\
first()
if not result:
- raise exception.NotFound('No volume for id %s' % volume_id)
+ raise exception.NotFound(_('No volume for id %s') % volume_id)
return result
@@ -1364,7 +1480,7 @@ def volume_get_by_ec2_id(context, ec2_id):
raise exception.NotAuthorized()
if not result:
- raise exception.NotFound('Volume %s not found' % ec2_id)
+ raise exception.NotFound(_('Volume %s not found') % ec2_id)
return result
@@ -1388,7 +1504,7 @@ def volume_get_instance(context, volume_id):
options(joinedload('instance')).\
first()
if not result:
- raise exception.NotFound('Volume %s not found' % ec2_id)
+ raise exception.NotFound(_('Volume %s not found') % ec2_id)
return result.instance
@@ -1400,7 +1516,7 @@ def volume_get_shelf_and_blade(context, volume_id):
filter_by(volume_id=volume_id).\
first()
if not result:
- raise exception.NotFound('No export device found for volume %s' %
+ raise exception.NotFound(_('No export device found for volume %s') %
volume_id)
return (result.shelf_id, result.blade_id)
@@ -1413,7 +1529,7 @@ def volume_get_iscsi_target_num(context, volume_id):
filter_by(volume_id=volume_id).\
first()
if not result:
- raise exception.NotFound('No target id found for volume %s' %
+ raise exception.NotFound(_('No target id found for volume %s') %
volume_id)
return result.target_num
@@ -1458,7 +1574,7 @@ def security_group_get(context, security_group_id, session=None):
options(joinedload_all('rules')).\
first()
if not result:
- raise exception.NotFound("No secuity group with id %s" %
+ raise exception.NotFound(_("No security group with id %s") %
security_group_id)
return result
@@ -1475,7 +1591,7 @@ def security_group_get_by_name(context, project_id, group_name):
first()
if not result:
raise exception.NotFound(
- 'No security group named %s for project: %s' \
+ _('No security group named %s for project: %s')
% (group_name, project_id))
return result
@@ -1563,7 +1679,7 @@ def security_group_rule_get(context, security_group_rule_id, session=None):
filter_by(id=security_group_rule_id).\
first()
if not result:
- raise exception.NotFound("No secuity group rule with id %s" %
+ raise exception.NotFound(_("No secuity group rule with id %s") %
security_group_rule_id)
return result
@@ -1599,7 +1715,7 @@ def user_get(context, id, session=None):
first()
if not result:
- raise exception.NotFound('No user for id %s' % id)
+ raise exception.NotFound(_('No user for id %s') % id)
return result
@@ -1615,7 +1731,7 @@ def user_get_by_access_key(context, access_key, session=None):
first()
if not result:
- raise exception.NotFound('No user for access key %s' % access_key)
+ raise exception.NotFound(_('No user for access key %s') % access_key)
return result
@@ -1677,7 +1793,7 @@ def project_get(context, id, session=None):
first()
if not result:
- raise exception.NotFound("No project with id %s" % id)
+ raise exception.NotFound(_("No project with id %s") % id)
return result
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index c3e566c6a..a173f25db 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -22,7 +22,7 @@ SQLAlchemy models for nova data.
import datetime
from sqlalchemy.orm import relationship, backref, object_mapper
-from sqlalchemy import Column, Integer, String, schema
+from sqlalchemy import Column, Integer, Float, String, schema
from sqlalchemy import ForeignKey, DateTime, Boolean, Text
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base
@@ -171,6 +171,16 @@ class Service(BASE, NovaBase):
disabled = Column(Boolean, default=False)
+class Certificate(BASE, NovaBase):
+ """Represents a an x509 certificate"""
+ __tablename__ = 'certificates'
+ id = Column(Integer, primary_key=True)
+
+ user_id = Column(String(255))
+ project_id = Column(String(255))
+ file_name = Column(String(255))
+
+
class Instance(BASE, NovaBase):
"""Represents a guest vm."""
__tablename__ = 'instances'
@@ -250,6 +260,31 @@ class Instance(BASE, NovaBase):
# 'shutdown', 'shutoff', 'crashed'])
+class InstanceDiagnostics(BASE, NovaBase):
+ """Represents a guest VM's diagnostics"""
+ __tablename__ = "instance_diagnostics"
+ id = Column(Integer, primary_key=True)
+ instance_id = Column(Integer, ForeignKey('instances.id'))
+
+ memory_available = Column(Float)
+ memory_free = Column(Float)
+ cpu_load = Column(Float)
+ disk_read = Column(Float)
+ disk_write = Column(Float)
+ net_tx = Column(Float)
+ net_rx = Column(Float)
+
+
+class InstanceActions(BASE, NovaBase):
+ """Represents a guest VM's actions and results"""
+ __tablename__ = "instance_actions"
+ id = Column(Integer, primary_key=True)
+ instance_id = Column(Integer, ForeignKey('instances.id'))
+
+ action = Column(String(255))
+ error = Column(Text)
+
+
class Volume(BASE, NovaBase):
"""Represents a block storage device that can be attached to a vm."""
__tablename__ = 'volumes'
@@ -550,10 +585,6 @@ def register_models():
it will never need to be called explicitly elsewhere.
"""
from sqlalchemy import create_engine
- #models = (Service, Instance, Volume, ExportDevice, IscsiTarget, FixedIp,
- # FloatingIp, Network, SecurityGroup,
- # SecurityGroupIngressRule, SecurityGroupInstanceAssociation,
- # AuthToken, User, Project) # , Image, Host
models = (Service, Instance, Volume, ExportDevice, IscsiTarget, FixedIp,
FloatingIp, Network, SecurityGroup,
SecurityGroupIngressRule, SecurityGroupInstanceAssociation,