summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorMORITA Kazutaka <morita.kazutaka@gmail.com>2011-05-13 21:07:48 +0900
committerMORITA Kazutaka <morita.kazutaka@gmail.com>2011-05-13 21:07:48 +0900
commit2ecfa05337e7eefbf9791188ffa1d57f0e6ecd19 (patch)
tree442bf5218c6a7f48197875da388cfc2bf3406a62 /nova/db
parentaad857a18153792d96f300732c3bb5bb16aa02c3 (diff)
parent0576766cdf3480ad02159671d2dfc0bdcb154934 (diff)
Merge trunk
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py71
-rw-r--r--nova/db/base.py8
-rw-r--r--nova/db/migration.py2
-rw-r--r--nova/db/sqlalchemy/api.py174
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/001_austin.py8
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/003_add_label_to_networks.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/004_add_zone_tables.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/005_add_instance_metadata.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py6
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py9
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/009_add_instance_migrations.py6
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/010_add_os_type_to_instances.py7
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/011_live_migration.py5
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/012_add_ipv6_flatmanager.py8
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/013_add_flavors_to_migrations.py6
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py13
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/015_add_auto_assign_to_floating_ips.py35
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/016_add_volume_snapshot_support.py (renamed from nova/db/sqlalchemy/migrate_repo/versions/015_add_volume_snapshot_support.py)0
-rw-r--r--nova/db/sqlalchemy/models.py1
21 files changed, 191 insertions, 203 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 9fc4b8c0a..57e585a9c 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -15,8 +15,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
-"""
-Defines interface for DB access.
+
+"""Defines interface for DB access.
The underlying driver is loaded as a :class:`LazyPluggable`.
@@ -30,6 +30,7 @@ The underlying driver is loaded as a :class:`LazyPluggable`.
:enable_new_services: when adding a new service to the database, is it in the
pool of available hardware (Default: True)
+
"""
from nova import exception
@@ -88,7 +89,7 @@ def service_get(context, service_id):
def service_get_by_host_and_topic(context, host, topic):
- """Get a service by host it's on and topic it listens to"""
+ """Get a service by host it's on and topic it listens to."""
return IMPL.service_get_by_host_and_topic(context, host, topic)
@@ -115,7 +116,7 @@ def service_get_all_compute_by_host(context, host):
def service_get_all_compute_sorted(context):
"""Get all compute services sorted by instance count.
- Returns a list of (Service, instance_count) tuples.
+ :returns: a list of (Service, instance_count) tuples.
"""
return IMPL.service_get_all_compute_sorted(context)
@@ -124,7 +125,7 @@ def service_get_all_compute_sorted(context):
def service_get_all_network_sorted(context):
"""Get all network services sorted by network count.
- Returns a list of (Service, network_count) tuples.
+ :returns: a list of (Service, network_count) tuples.
"""
return IMPL.service_get_all_network_sorted(context)
@@ -133,7 +134,7 @@ def service_get_all_network_sorted(context):
def service_get_all_volume_sorted(context):
"""Get all volume services sorted by volume count.
- Returns a list of (Service, volume_count) tuples.
+ :returns: a list of (Service, volume_count) tuples.
"""
return IMPL.service_get_all_volume_sorted(context)
@@ -243,7 +244,7 @@ def floating_ip_count_by_project(context, project_id):
def floating_ip_deallocate(context, address):
- """Deallocate an floating ip by address"""
+ """Deallocate an floating ip by address."""
return IMPL.floating_ip_deallocate(context, address)
@@ -255,7 +256,7 @@ def floating_ip_destroy(context, address):
def floating_ip_disassociate(context, address):
"""Disassociate an floating ip from a fixed ip by address.
- Returns the address of the existing fixed ip.
+ :returns: the address of the existing fixed ip.
"""
return IMPL.floating_ip_disassociate(context, address)
@@ -293,25 +294,30 @@ def floating_ip_update(context, address, values):
return IMPL.floating_ip_update(context, address, values)
+def floating_ip_set_auto_assigned(context, address):
+ """Set auto_assigned flag to floating ip"""
+ return IMPL.floating_ip_set_auto_assigned(context, address)
+
####################
+
def migration_update(context, id, values):
- """Update a migration instance"""
+ """Update a migration instance."""
return IMPL.migration_update(context, id, values)
def migration_create(context, values):
- """Create a migration record"""
+ """Create a migration record."""
return IMPL.migration_create(context, values)
def migration_get(context, migration_id):
- """Finds a migration by the id"""
+ """Finds a migration by the id."""
return IMPL.migration_get(context, migration_id)
def migration_get_by_instance_and_status(context, instance_id, status):
- """Finds a migration by the instance id its migrating"""
+ """Finds a migration by the instance id its migrating."""
return IMPL.migration_get_by_instance_and_status(context, instance_id,
status)
@@ -457,11 +463,6 @@ def instance_get_project_vpn(context, project_id):
return IMPL.instance_get_project_vpn(context, project_id)
-def instance_is_vpn(context, instance_id):
- """True if instance is a vpn."""
- return IMPL.instance_is_vpn(context, instance_id)
-
-
def instance_set_state(context, instance_id, state, description=None):
"""Set the state of an instance."""
return IMPL.instance_set_state(context, instance_id, state, description)
@@ -581,7 +582,9 @@ def network_create_safe(context, values):
def network_delete_safe(context, network_id):
"""Delete network with key network_id.
+
This method assumes that the network is not associated with any project
+
"""
return IMPL.network_delete_safe(context, network_id)
@@ -676,7 +679,6 @@ def project_get_network(context, project_id, associate=True):
network if one is not found, otherwise it returns None.
"""
-
return IMPL.project_get_network(context, project_id, associate)
@@ -724,7 +726,9 @@ def iscsi_target_create_safe(context, values):
The device is not returned. If the create violates the unique
constraints because the iscsi_target and host already exist,
- no exception is raised."""
+ no exception is raised.
+
+ """
return IMPL.iscsi_target_create_safe(context, values)
@@ -1089,10 +1093,7 @@ def project_delete(context, project_id):
def host_get_networks(context, host):
- """Return all networks for which the given host is the designated
- network host.
-
- """
+ """All networks for which the given host is the network host."""
return IMPL.host_get_networks(context, host)
@@ -1154,38 +1155,40 @@ def console_get(context, console_id, instance_id=None):
def instance_type_create(context, values):
- """Create a new instance type"""
+ """Create a new instance type."""
return IMPL.instance_type_create(context, values)
def instance_type_get_all(context, inactive=False):
- """Get all instance types"""
+ """Get all instance types."""
return IMPL.instance_type_get_all(context, inactive)
def instance_type_get_by_id(context, id):
- """Get instance type by id"""
+ """Get instance type by id."""
return IMPL.instance_type_get_by_id(context, id)
def instance_type_get_by_name(context, name):
- """Get instance type by name"""
+ """Get instance type by name."""
return IMPL.instance_type_get_by_name(context, name)
def instance_type_get_by_flavor_id(context, id):
- """Get instance type by name"""
+ """Get instance type by name."""
return IMPL.instance_type_get_by_flavor_id(context, id)
def instance_type_destroy(context, name):
- """Delete a instance type"""
+ """Delete a instance type."""
return IMPL.instance_type_destroy(context, name)
def instance_type_purge(context, name):
- """Purges (removes) an instance type from DB
- Use instance_type_destroy for most cases
+ """Purges (removes) an instance type from DB.
+
+ Use instance_type_destroy for most cases
+
"""
return IMPL.instance_type_purge(context, name)
@@ -1222,15 +1225,15 @@ def zone_get_all(context):
def instance_metadata_get(context, instance_id):
- """Get all metadata for an instance"""
+ """Get all metadata for an instance."""
return IMPL.instance_metadata_get(context, instance_id)
def instance_metadata_delete(context, instance_id, key):
- """Delete the given metadata item"""
+ """Delete the given metadata item."""
IMPL.instance_metadata_delete(context, instance_id, key)
def instance_metadata_update_or_create(context, instance_id, metadata):
- """Create or update instance metadata"""
+ """Create or update instance metadata."""
IMPL.instance_metadata_update_or_create(context, instance_id, metadata)
diff --git a/nova/db/base.py b/nova/db/base.py
index a0f2180c6..a0d055d5b 100644
--- a/nova/db/base.py
+++ b/nova/db/base.py
@@ -16,20 +16,20 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""
-Base class for classes that need modular database access.
-"""
+"""Base class for classes that need modular database access."""
from nova import utils
from nova import flags
+
FLAGS = flags.FLAGS
flags.DEFINE_string('db_driver', 'nova.db.api',
'driver to use for database access')
class Base(object):
- """DB driver is injected in the init method"""
+ """DB driver is injected in the init method."""
+
def __init__(self, db_driver=None):
if not db_driver:
db_driver = FLAGS.db_driver
diff --git a/nova/db/migration.py b/nova/db/migration.py
index e54b90cd8..ccd06cffe 100644
--- a/nova/db/migration.py
+++ b/nova/db/migration.py
@@ -15,11 +15,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+
"""Database setup and migration commands."""
from nova import flags
from nova import utils
+
FLAGS = flags.FLAGS
flags.DECLARE('db_backend', 'nova.db.api')
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 059a22cb9..7302f25b0 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -94,7 +94,7 @@ def require_admin_context(f):
"""
def wrapper(*args, **kwargs):
if not is_admin_context(args[0]):
- raise exception.NotAuthorized()
+ raise exception.AdminRequired()
return f(*args, **kwargs)
return wrapper
@@ -105,7 +105,7 @@ def require_context(f):
"""
def wrapper(*args, **kwargs):
if not is_admin_context(args[0]) and not is_user_context(args[0]):
- raise exception.NotAuthorized()
+ raise exception.AdminRequired()
return f(*args, **kwargs)
return wrapper
@@ -137,7 +137,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.ServiceNotFound(service_id=service_id)
return result
@@ -196,8 +196,7 @@ def service_get_all_compute_by_host(context, host):
all()
if not result:
- raise exception.NotFound(_("%s does not exist or is not "
- "a compute node.") % host)
+ raise exception.ComputeHostNotFound(host=host)
return result
@@ -284,8 +283,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 %(host)s, %(binary)s')
- % locals())
+ raise exception.HostBinaryNotFound(host=host, binary=binary)
return result
@@ -323,7 +321,7 @@ def compute_node_get(context, compute_id, session=None):
first()
if not result:
- raise exception.NotFound(_('No computeNode for id %s') % compute_id)
+ raise exception.ComputeHostNotFound(host=compute_id)
return result
@@ -359,7 +357,7 @@ def certificate_get(context, certificate_id, session=None):
first()
if not result:
- raise exception.NotFound('No certificate for id %s' % certificate_id)
+ raise exception.CertificateNotFound(certificate_id=certificate_id)
return result
@@ -461,6 +459,7 @@ def floating_ip_count_by_project(context, project_id):
session = get_session()
return session.query(models.FloatingIp).\
filter_by(project_id=project_id).\
+ filter_by(auto_assigned=False).\
filter_by(deleted=False).\
count()
@@ -489,6 +488,7 @@ def floating_ip_deallocate(context, address):
address,
session=session)
floating_ip_ref['project_id'] = None
+ floating_ip_ref['auto_assigned'] = False
floating_ip_ref.save(session=session)
@@ -522,6 +522,17 @@ def floating_ip_disassociate(context, address):
return fixed_ip_address
+@require_context
+def floating_ip_set_auto_assigned(context, address):
+ session = get_session()
+ with session.begin():
+ floating_ip_ref = floating_ip_get_by_address(context,
+ address,
+ session=session)
+ floating_ip_ref.auto_assigned = True
+ floating_ip_ref.save(session=session)
+
+
@require_admin_context
def floating_ip_get_all(context):
session = get_session()
@@ -548,6 +559,7 @@ def floating_ip_get_all_by_project(context, project_id):
return session.query(models.FloatingIp).\
options(joinedload_all('fixed_ip.instance')).\
filter_by(project_id=project_id).\
+ filter_by(auto_assigned=False).\
filter_by(deleted=False).\
all()
@@ -564,7 +576,7 @@ def floating_ip_get_by_address(context, address, session=None):
filter_by(deleted=can_read_deleted(context)).\
first()
if not result:
- raise exception.NotFound('No floating ip for address %s' % address)
+ raise exception.FloatingIpNotFound(fixed_ip=address)
return result
@@ -672,7 +684,7 @@ def fixed_ip_get_all(context, session=None):
session = get_session()
result = session.query(models.FixedIp).all()
if not result:
- raise exception.NotFound(_('No fixed ips defined'))
+ raise exception.NoFloatingIpsDefined()
return result
@@ -688,7 +700,7 @@ def fixed_ip_get_all_by_host(context, host=None):
all()
if not result:
- raise exception.NotFound(_('No fixed ips for this host defined'))
+ raise exception.NoFloatingIpsDefinedForHost(host=host)
return result
@@ -704,7 +716,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.FloatingIpNotFound(fixed_ip=address)
if is_user_context(context):
authorize_project_context(context, result.instance.project_id)
@@ -725,7 +737,7 @@ def fixed_ip_get_all_by_instance(context, instance_id):
filter_by(instance_id=instance_id).\
filter_by(deleted=False)
if not rv:
- raise exception.NotFound(_('No address for instance %s') % instance_id)
+ raise exception.NoFloatingIpsFoundForInstance(instance_id=instance_id)
return rv
@@ -770,9 +782,10 @@ def instance_create(context, values):
metadata = values.get('metadata')
metadata_refs = []
if metadata:
- for metadata_item in metadata:
+ for k, v in metadata.iteritems():
metadata_ref = models.InstanceMetadata()
- metadata_ref.update(metadata_item)
+ metadata_ref['key'] = k
+ metadata_ref['value'] = v
metadata_refs.append(metadata_ref)
values['metadata'] = metadata_refs
@@ -803,17 +816,17 @@ def instance_destroy(context, instance_id):
with session.begin():
session.query(models.Instance).\
filter_by(id=instance_id).\
- update({'deleted': 1,
+ update({'deleted': True,
'deleted_at': datetime.datetime.utcnow(),
'updated_at': literal_column('updated_at')})
session.query(models.SecurityGroupInstanceAssociation).\
filter_by(instance_id=instance_id).\
- update({'deleted': 1,
+ update({'deleted': True,
'deleted_at': datetime.datetime.utcnow(),
'updated_at': literal_column('updated_at')})
session.query(models.InstanceMetadata).\
filter_by(instance_id=instance_id).\
- update({'deleted': 1,
+ update({'deleted': True,
'deleted_at': datetime.datetime.utcnow(),
'updated_at': literal_column('updated_at')})
@@ -847,9 +860,7 @@ def instance_get(context, instance_id, session=None):
filter_by(deleted=False).\
first()
if not result:
- raise exception.InstanceNotFound(_('Instance %s not found')
- % instance_id,
- instance_id)
+ raise exception.InstanceNotFound(instance_id=instance_id)
return result
@@ -940,7 +951,7 @@ def instance_get_project_vpn(context, project_id):
options(joinedload('security_groups')).\
options(joinedload('instance_type')).\
filter_by(project_id=project_id).\
- filter_by(image_id=FLAGS.vpn_image_id).\
+ filter_by(image_id=str(FLAGS.vpn_image_id)).\
filter_by(deleted=can_read_deleted(context)).\
first()
@@ -980,13 +991,6 @@ def instance_get_floating_address(context, instance_id):
@require_admin_context
-def instance_is_vpn(context, instance_id):
- # TODO(vish): Move this into image code somewhere
- instance_ref = instance_get(context, instance_id)
- return instance_ref['image_id'] == FLAGS.vpn_image_id
-
-
-@require_admin_context
def instance_set_state(context, instance_id, state, description=None):
# TODO(devcamcar): Move this out of models and into driver
from nova.compute import power_state
@@ -1125,8 +1129,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 %(user_id)s,'
- ' name %(name)s') % locals())
+ raise exception.KeypairNotFound(user_id=user_id, name=name)
return result
@@ -1252,7 +1255,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.NetworkNotFound(network_id=network_id)
return result
@@ -1262,7 +1265,7 @@ def network_get_all(context):
session = get_session()
result = session.query(models.Network)
if not result:
- raise exception.NotFound(_('No networks defined'))
+ raise exception.NoNetworksFound()
return result
@@ -1291,7 +1294,7 @@ def network_get_by_bridge(context, bridge):
first()
if not result:
- raise exception.NotFound(_('No network for bridge %s') % bridge)
+ raise exception.NetworkNotFoundForBridge(bridge=bridge)
return result
@@ -1302,8 +1305,7 @@ def network_get_by_cidr(context, cidr):
filter_by(cidr=cidr).first()
if not result:
- raise exception.NotFound(_('Network with cidr %s does not exist') %
- cidr)
+ raise exception.NetworkNotFoundForCidr(cidr=cidr)
return result
@@ -1317,7 +1319,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.NetworkNotFoundForInstance(instance_id=instance_id)
return rv
@@ -1330,7 +1332,7 @@ def network_get_all_by_instance(_context, instance_id):
filter_by(instance_id=instance_id).\
filter_by(deleted=False)
if not rv:
- raise exception.NotFound(_('No network for instance %s') % instance_id)
+ raise exception.NetworkNotFoundForInstance(instance_id=instance_id)
return rv
@@ -1344,7 +1346,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.NetworkNotFound(network_id=network_id)
# NOTE(vish): if with_lockmode isn't supported, as in sqlite,
# then this has concurrency issues
@@ -1469,7 +1471,7 @@ def auth_token_get(context, token_hash, session=None):
filter_by(deleted=can_read_deleted(context)).\
first()
if not tk:
- raise exception.NotFound(_('Token %s does not exist') % token_hash)
+ raise exception.AuthTokenNotFound(token=token_hash)
return tk
@@ -1503,7 +1505,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.ProjectQuotaNotFound(project_id=project_id)
return result
@@ -1658,8 +1660,7 @@ def volume_get(context, volume_id, session=None):
filter_by(deleted=False).\
first()
if not result:
- raise exception.VolumeNotFound(_('Volume %s not found') % volume_id,
- volume_id)
+ raise exception.VolumeNotFound(volume_id=volume_id)
return result
@@ -1691,7 +1692,7 @@ def volume_get_all_by_instance(context, instance_id):
filter_by(deleted=False).\
all()
if not result:
- raise exception.NotFound(_('No volume for instance %s') % instance_id)
+ raise exception.VolumeNotFoundForInstance(instance_id=instance_id)
return result
@@ -1716,8 +1717,7 @@ def volume_get_instance(context, volume_id):
options(joinedload('instance')).\
first()
if not result:
- raise exception.VolumeNotFound(_('Volume %s not found') % volume_id,
- volume_id)
+ raise exception.VolumeNotFound(volume_id=volume_id)
return result.instance
@@ -1729,8 +1729,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') %
- volume_id)
+ raise exception.ExportDeviceNotFoundForVolume(volume_id=volume_id)
return (result.shelf_id, result.blade_id)
@@ -1742,8 +1741,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') %
- volume_id)
+ raise exception.ISCSITargetNotFoundForVolume(volume_id=volume_id)
return result.target_num
@@ -1800,8 +1798,7 @@ def snapshot_get(context, snapshot_id, session=None):
filter_by(deleted=False).\
first()
if not result:
- raise exception.SnapshotNotFound(_('Snapshot %s not found') % snapshot_id,
- snapshot_id)
+ raise exception.SnapshotNotFound(snapshot_id=snapshot_id)
return result
@@ -1864,8 +1861,8 @@ def security_group_get(context, security_group_id, session=None):
options(joinedload_all('rules')).\
first()
if not result:
- raise exception.NotFound(_("No security group with id %s") %
- security_group_id)
+ raise exception.SecurityGroupNotFound(
+ security_group_id=security_group_id)
return result
@@ -1880,9 +1877,8 @@ def security_group_get_by_name(context, project_id, group_name):
options(joinedload_all('instances')).\
first()
if not result:
- raise exception.NotFound(
- _('No security group named %(group_name)s'
- ' for project: %(project_id)s') % locals())
+ raise exception.SecurityGroupNotFoundForProject(project_id=project_id,
+ security_group_id=group_name)
return result
@@ -1983,8 +1979,8 @@ 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") %
- security_group_rule_id)
+ raise exception.SecurityGroupNotFoundForRule(
+ rule_id=security_group_rule_id)
return result
@@ -2057,7 +2053,7 @@ def user_get(context, id, session=None):
first()
if not result:
- raise exception.NotFound(_('No user for id %s') % id)
+ raise exception.UserNotFound(user_id=id)
return result
@@ -2073,7 +2069,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.AccessKeyNotFound(access_key=access_key)
return result
@@ -2138,7 +2134,7 @@ def project_get(context, id, session=None):
first()
if not result:
- raise exception.NotFound(_("No project with id %s") % id)
+ raise exception.ProjectNotFound(project_id=id)
return result
@@ -2159,7 +2155,7 @@ def project_get_by_user(context, user_id):
options(joinedload_all('projects')).\
first()
if not user:
- raise exception.NotFound(_('Invalid user_id %s') % user_id)
+ raise exception.UserNotFound(user_id=user_id)
return user.projects
@@ -2299,8 +2295,7 @@ def migration_get(context, id, session=None):
result = session.query(models.Migration).\
filter_by(id=id).first()
if not result:
- raise exception.NotFound(_("No migration found with id %s")
- % id)
+ raise exception.MigrationNotFound(migration_id=id)
return result
@@ -2311,8 +2306,8 @@ def migration_get_by_instance_and_status(context, instance_id, status):
filter_by(instance_id=instance_id).\
filter_by(status=status).first()
if not result:
- raise exception.NotFound(_("No migration found for instance "
- "%(instance_id)s with status %(status)s") % locals())
+ raise exception.MigrationNotFoundByStatus(instance_id=instance_id,
+ status=status)
return result
@@ -2333,8 +2328,7 @@ def console_pool_get(context, pool_id):
filter_by(id=pool_id).\
first()
if not result:
- raise exception.NotFound(_("No console pool with id %(pool_id)s")
- % locals())
+ raise exception.ConsolePoolNotFound(pool_id=pool_id)
return result
@@ -2350,9 +2344,9 @@ def console_pool_get_by_host_type(context, compute_host, host,
options(joinedload('consoles')).\
first()
if not result:
- raise exception.NotFound(_('No console pool of type %(console_type)s '
- 'for compute host %(compute_host)s '
- 'on proxy host %(host)s') % locals())
+ raise exception.ConsolePoolNotFoundForHostType(host=host,
+ console_type=console_type,
+ compute_host=compute_host)
return result
@@ -2390,8 +2384,8 @@ def console_get_by_pool_instance(context, pool_id, instance_id):
options(joinedload('pool')).\
first()
if not result:
- raise exception.NotFound(_('No console for instance %(instance_id)s '
- 'in pool %(pool_id)s') % locals())
+ raise exception.ConsoleNotFoundInPoolForInstance(pool_id=pool_id,
+ instance_id=instance_id)
return result
@@ -2412,9 +2406,11 @@ def console_get(context, console_id, instance_id=None):
query = query.filter_by(instance_id=instance_id)
result = query.options(joinedload('pool')).first()
if not result:
- idesc = (_("on instance %s") % instance_id) if instance_id else ""
- raise exception.NotFound(_("No console with id %(console_id)s"
- " %(idesc)s") % locals())
+ if instance_id:
+ raise exception.ConsoleNotFoundForInstance(console_id=console_id,
+ instance_id=instance_id)
+ else:
+ raise exception.ConsoleNotFound(console_id=console_id)
return result
@@ -2453,7 +2449,7 @@ def instance_type_get_all(context, inactive=False):
inst_dict[i['name']] = dict(i)
return inst_dict
else:
- raise exception.NotFound
+ raise exception.NoInstanceTypesFound()
@require_context
@@ -2464,7 +2460,7 @@ def instance_type_get_by_id(context, id):
filter_by(id=id).\
first()
if not inst_type:
- raise exception.NotFound(_("No instance type with id %s") % id)
+ raise exception.InstanceTypeNotFound(instance_type=id)
else:
return dict(inst_type)
@@ -2477,7 +2473,7 @@ def instance_type_get_by_name(context, name):
filter_by(name=name).\
first()
if not inst_type:
- raise exception.NotFound(_("No instance type with name %s") % name)
+ raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
else:
return dict(inst_type)
@@ -2490,7 +2486,7 @@ def instance_type_get_by_flavor_id(context, id):
filter_by(flavorid=int(id)).\
first()
if not inst_type:
- raise exception.NotFound(_("No flavor with flavorid %s") % id)
+ raise exception.FlavorNotFound(flavor_id=id)
else:
return dict(inst_type)
@@ -2503,7 +2499,7 @@ def instance_type_destroy(context, name):
filter_by(name=name)
records = instance_type_ref.update(dict(deleted=True))
if records == 0:
- raise exception.NotFound
+ raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
else:
return instance_type_ref
@@ -2518,7 +2514,7 @@ def instance_type_purge(context, name):
filter_by(name=name)
records = instance_type_ref.delete()
if records == 0:
- raise exception.NotFound
+ raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
else:
return instance_type_ref
@@ -2539,7 +2535,7 @@ def zone_update(context, zone_id, values):
session = get_session()
zone = session.query(models.Zone).filter_by(id=zone_id).first()
if not zone:
- raise exception.NotFound(_("No zone with id %(zone_id)s") % locals())
+ raise exception.ZoneNotFound(zone_id=zone_id)
zone.update(values)
zone.save()
return zone
@@ -2559,7 +2555,7 @@ def zone_get(context, zone_id):
session = get_session()
result = session.query(models.Zone).filter_by(id=zone_id).first()
if not result:
- raise exception.NotFound(_("No zone with id %(zone_id)s") % locals())
+ raise exception.ZoneNotFound(zone_id=zone_id)
return result
@@ -2593,7 +2589,7 @@ def instance_metadata_delete(context, instance_id, key):
filter_by(instance_id=instance_id).\
filter_by(key=key).\
filter_by(deleted=False).\
- update({'deleted': 1,
+ update({'deleted': True,
'deleted_at': datetime.datetime.utcnow(),
'updated_at': literal_column('updated_at')})
@@ -2609,8 +2605,8 @@ def instance_metadata_get_item(context, instance_id, key):
first()
if not meta_result:
- raise exception.NotFound(_('Invalid metadata key for instance %s') %
- instance_id)
+ raise exception.InstanceMetadataNotFound(metadata_key=key,
+ instance_id=instance_id)
return meta_result
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/001_austin.py b/nova/db/sqlalchemy/migrate_repo/versions/001_austin.py
index 9e7ab3554..63bbaccc1 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/001_austin.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/001_austin.py
@@ -17,15 +17,13 @@
# under the License.
## Table code mostly autogenerated by genmodel.py
-from sqlalchemy import *
-from migrate import *
-
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey
+from sqlalchemy import ForeignKeyConstraint, Integer, MetaData, String
+from sqlalchemy import Table, Text
from nova import log as logging
-
meta = MetaData()
-
auth_tokens = Table('auth_tokens', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py b/nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py
index 413536a59..9bb8a8ada 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/002_bexar.py
@@ -16,15 +16,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey
+from sqlalchemy import Integer, MetaData, String, Table, Text
from nova import log as logging
-
meta = MetaData()
-
# Just for the ForeignKey and column creation to succeed, these are not the
# actual definitions of instances or services.
instances = Table('instances', meta,
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/003_add_label_to_networks.py b/nova/db/sqlalchemy/migrate_repo/versions/003_add_label_to_networks.py
index 5ba7910f1..8e0de4d2b 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/003_add_label_to_networks.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/003_add_label_to_networks.py
@@ -15,15 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Column, Integer, MetaData, String, Table
meta = MetaData()
-
networks = Table('networks', meta,
Column('id', Integer(), primary_key=True, nullable=False),
)
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/004_add_zone_tables.py b/nova/db/sqlalchemy/migrate_repo/versions/004_add_zone_tables.py
index ade981687..0abea374c 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/004_add_zone_tables.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/004_add_zone_tables.py
@@ -13,15 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
+from sqlalchemy import Boolean, Column, DateTime, Integer
+from sqlalchemy import MetaData, String, Table
from nova import log as logging
-
meta = MetaData()
-
#
# New Tables
#
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/005_add_instance_metadata.py b/nova/db/sqlalchemy/migrate_repo/versions/005_add_instance_metadata.py
index 4cb07e0d8..a1a86e3b4 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/005_add_instance_metadata.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/005_add_instance_metadata.py
@@ -15,15 +15,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer
+from sqlalchemy import MetaData, String, Table
from nova import log as logging
-
meta = MetaData()
-
# Just for the ForeignKey and column creation to succeed, these are not the
# actual definitions of instances or services.
instances = Table('instances', meta,
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py b/nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py
index 705fc8ff3..4627d3332 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/006_add_provider_data_to_volumes.py
@@ -15,11 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Column, Integer, MetaData, String, Table
meta = MetaData()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py b/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py
index 427934d53..6f2668040 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/007_add_ipv6_to_fixed_ips.py
@@ -13,15 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Column, Integer, MetaData, String, Table
meta = MetaData()
-
# Table stub-definitions
# Just for the ForeignKey and column creation to succeed, these are not the
# actual definitions of instances or services.
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py b/nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py
index 5e2cb69d9..63999f6ff 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/008_add_instance_types.py
@@ -13,15 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
-from nova import api
-from nova import db
+from sqlalchemy import Boolean, Column, DateTime, Integer
+from sqlalchemy import MetaData, String, Table
from nova import log as logging
-import datetime
-
meta = MetaData()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/009_add_instance_migrations.py b/nova/db/sqlalchemy/migrate_repo/versions/009_add_instance_migrations.py
index 4fda525f1..0f2d0079a 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/009_add_instance_migrations.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/009_add_instance_migrations.py
@@ -15,12 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.from sqlalchemy import *
-from sqlalchemy import *
-from migrate import *
-
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer
+from sqlalchemy import MetaData, String, Table
from nova import log as logging
-
meta = MetaData()
# Just for the ForeignKey and column creation to succeed, these are not the
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/010_add_os_type_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/010_add_os_type_to_instances.py
index eb3066894..a5b80586e 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/010_add_os_type_to_instances.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/010_add_os_type_to_instances.py
@@ -14,12 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from sqlalchemy.sql import text
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Column, Integer, MetaData, String, Table
meta = MetaData()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/011_live_migration.py b/nova/db/sqlalchemy/migrate_repo/versions/011_live_migration.py
index 23ccccb4e..b2b0256d2 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/011_live_migration.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/011_live_migration.py
@@ -16,10 +16,9 @@
# License for the specific language governing permissions and limitations
# under the License.
-from migrate import *
+from sqlalchemy import Boolean, Column, DateTime, Integer, MetaData
+from sqlalchemy import Table, Text
from nova import log as logging
-from sqlalchemy import *
-
meta = MetaData()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/012_add_ipv6_flatmanager.py b/nova/db/sqlalchemy/migrate_repo/versions/012_add_ipv6_flatmanager.py
index e87085668..10d250522 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/012_add_ipv6_flatmanager.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/012_add_ipv6_flatmanager.py
@@ -13,15 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer
+from sqlalchemy import MetaData, String, Table
meta = MetaData()
-
# Table stub-definitions
# Just for the ForeignKey and column creation to succeed, these are not the
# actual definitions of instances or services.
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/013_add_flavors_to_migrations.py b/nova/db/sqlalchemy/migrate_repo/versions/013_add_flavors_to_migrations.py
index 3fb92e85c..7246839b7 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/013_add_flavors_to_migrations.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/013_add_flavors_to_migrations.py
@@ -15,11 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.from sqlalchemy import *
-from sqlalchemy import *
-from migrate import *
-
-from nova import log as logging
-
+from sqlalchemy import Column, Integer, MetaData, Table
meta = MetaData()
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py
index b12a0a801..62216be12 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/014_add_instance_type_id_to_instances.py
@@ -14,16 +14,11 @@
# License for the specific language governing permissions and limitations
# under the License.
-from sqlalchemy import *
-from sqlalchemy.sql import text
-from migrate import *
-
+from sqlalchemy import Column, Integer, MetaData, String, Table
#from nova import log as logging
-
meta = MetaData()
-
c_instance_type = Column('instance_type',
String(length=255, convert_unicode=False,
assert_unicode=None, unicode_error=None,
@@ -54,10 +49,12 @@ def upgrade(migrate_engine):
instances.create_column(c_instance_type_id)
+ type_names = {}
recs = migrate_engine.execute(instance_types.select())
for row in recs:
- type_id = row[0]
- type_name = row[1]
+ type_names[row[0]] = row[1]
+
+ for type_id, type_name in type_names.iteritems():
migrate_engine.execute(instances.update()\
.where(instances.c.instance_type == type_name)\
.values(instance_type_id=type_id))
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/015_add_auto_assign_to_floating_ips.py b/nova/db/sqlalchemy/migrate_repo/versions/015_add_auto_assign_to_floating_ips.py
new file mode 100644
index 000000000..375760c84
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/015_add_auto_assign_to_floating_ips.py
@@ -0,0 +1,35 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# Copyright 2011 Grid Dynamics
+#
+# 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.
+
+from sqlalchemy import Boolean, Column, MetaData, Table
+
+meta = MetaData()
+
+c_auto_assigned = Column('auto_assigned', Boolean, default=False)
+
+
+def upgrade(migrate_engine):
+ # Upgrade operations go here. Don't create your own engine;
+ # bind migrate_engine to your metadata
+ meta.bind = migrate_engine
+
+ floating_ips = Table('floating_ips',
+ meta,
+ autoload=True,
+ autoload_with=migrate_engine)
+
+ floating_ips.create_column(c_auto_assigned)
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/015_add_volume_snapshot_support.py b/nova/db/sqlalchemy/migrate_repo/versions/016_add_volume_snapshot_support.py
index 288f63e72..288f63e72 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/015_add_volume_snapshot_support.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/016_add_volume_snapshot_support.py
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 9abe4d9ae..2e0ead5f9 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -616,6 +616,7 @@ class FloatingIp(BASE, NovaBase):
'FloatingIp.deleted == False)')
project_id = Column(String(255))
host = Column(String(255)) # , ForeignKey('hosts.id'))
+ auto_assigned = Column(Boolean, default=False, nullable=False)
class ConsolePool(BASE, NovaBase):