diff options
| author | Tushar Patil <tushar.vitthal.patil@gmail.com> | 2011-09-08 13:49:03 -0700 |
|---|---|---|
| committer | Tushar Patil <tushar.vitthal.patil@gmail.com> | 2011-09-08 13:49:03 -0700 |
| commit | 7e96a2d7c5f2ac8572c6d0fd20e4e8c7e146dce9 (patch) | |
| tree | 055e839e762222bd1ab9f8cc8362e17d09b61da0 /nova/db | |
| parent | 9773d900d35316edbad4468a869ca62a353d3114 (diff) | |
| parent | b48ccfdfbc42f399aaeb29e5305c3855a719b02d (diff) | |
Added docstring to explain usage of reserved keyword argument
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/api.py | 10 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 33 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/045_add_network_priority.py | 44 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 1 |
4 files changed, 88 insertions, 0 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index efc088e35..a9d2dc065 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -422,6 +422,11 @@ def virtual_interface_get_by_address(context, address): return IMPL.virtual_interface_get_by_address(context, address) +def virtual_interface_get_by_uuid(context, vif_uuid): + """Gets a virtual interface from the table filtering on vif uuid.""" + return IMPL.virtual_interface_get_by_uuid(context, vif_uuid) + + def virtual_interface_get_by_fixed_ip(context, fixed_ip_id): """Gets the virtual interface fixed_ip is associated with.""" return IMPL.virtual_interface_get_by_fixed_ip(context, fixed_ip_id) @@ -717,6 +722,11 @@ def network_get_by_bridge(context, bridge): return IMPL.network_get_by_bridge(context, bridge) +def network_get_by_uuid(context, uuid): + """Get a network by uuid or raise if it does not exist.""" + return IMPL.network_get_by_uuid(context, uuid) + + def network_get_by_cidr(context, cidr): """Get a network by cidr or raise if it does not exist""" return IMPL.network_get_by_cidr(context, cidr) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index e0be8454e..40e2ca167 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -671,6 +671,10 @@ def floating_ip_update(context, address, values): @require_admin_context def fixed_ip_associate(context, address, instance_id, network_id=None, reserved=False): + """Keyword arguments: + reserved -- should be a boolean value(True or False), exact value will be + used to filter on the fixed ip address + """ session = get_session() with session.begin(): network_or_none = or_(models.FixedIp.network_id == network_id, @@ -946,6 +950,22 @@ def virtual_interface_get_by_address(context, address): @require_context +def virtual_interface_get_by_uuid(context, vif_uuid): + """Gets a virtual interface from the table. + + :param vif_uuid: the uuid of the interface you're looking to get + """ + session = get_session() + vif_ref = session.query(models.VirtualInterface).\ + filter_by(uuid=vif_uuid).\ + options(joinedload('network')).\ + options(joinedload('instance')).\ + options(joinedload('fixed_ips')).\ + first() + return vif_ref + + +@require_context def virtual_interface_get_by_fixed_ip(context, fixed_ip_id): """Gets the virtual interface fixed_ip is associated with. @@ -1859,6 +1879,19 @@ def network_get_by_bridge(context, bridge): @require_admin_context +def network_get_by_uuid(context, uuid): + session = get_session() + result = session.query(models.Network).\ + filter_by(uuid=uuid).\ + filter_by(deleted=False).\ + first() + + if not result: + raise exception.NetworkNotFoundForUUID(uuid=uuid) + return result + + +@require_admin_context def network_get_by_cidr(context, cidr): session = get_session() result = session.query(models.Network).\ diff --git a/nova/db/sqlalchemy/migrate_repo/versions/045_add_network_priority.py b/nova/db/sqlalchemy/migrate_repo/versions/045_add_network_priority.py new file mode 100644 index 000000000..b9b0ea37c --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/045_add_network_priority.py @@ -0,0 +1,44 @@ +# Copyright 2011 Nicira, Inc. +# 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. + +from sqlalchemy import * +from migrate import * + +from nova import log as logging +from nova import utils + + +meta = MetaData() + +networks = Table('networks', meta, + Column("id", Integer(), primary_key=True, nullable=False)) + +# Add priority column to networks table +priority = Column('priority', Integer()) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + + try: + networks.create_column(priority) + except Exception: + logging.error(_("priority column not added to networks table")) + raise + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + networks.drop_column(priority) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 854034f12..211049112 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -628,6 +628,7 @@ class Network(BASE, NovaBase): dhcp_start = Column(String(255)) project_id = Column(String(255)) + priority = Column(Integer) host = Column(String(255)) # , ForeignKey('hosts.id')) uuid = Column(String(36)) |
