From 2a6f97940f71c056b4bfb0cd9a86f5d676abc4e1 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Mon, 11 Jul 2011 13:34:39 -0700 Subject: add optional parameter networks to the Create server OS API --- nova/db/api.py | 32 ++++++++++++ nova/db/sqlalchemy/api.py | 125 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 156 insertions(+), 1 deletion(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index b7c5700e5..ca904738d 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -341,6 +341,14 @@ def fixed_ip_associate_pool(context, network_id, instance_id): return IMPL.fixed_ip_associate_pool(context, network_id, instance_id) +def fixed_ip_associate_by_address(context, network_id, instance_id, address): + """check if the address is free and is in the network + and it is not associated to any instance. + """ + return IMPL.fixed_ip_associate_by_address(context, network_id, + instance_id, address) + + def fixed_ip_create(context, values): """Create a fixed ip from the values dictionary.""" return IMPL.fixed_ip_create(context, values) @@ -400,6 +408,13 @@ def fixed_ip_update(context, address, values): return IMPL.fixed_ip_update(context, address, values) +def fixed_ip_validate_by_network_address(context, network_id, + address): + """validates if the address belongs to the network""" + return IMPL.fixed_ip_validate_by_network_address(context, network_id, + address) + + #################### @@ -689,7 +704,14 @@ def network_get_all(context): return IMPL.network_get_all(context) +def network_get_requested_networks(context, requested_networks): + """Return all defined networks.""" + return IMPL.network_get_requested_networks(context, requested_networks) + + # pylint: disable=C0103 + + def network_get_associated_fixed_ips(context, network_id): """Get all network's ips that have been associated.""" return IMPL.network_get_associated_fixed_ips(context, network_id) @@ -1228,6 +1250,16 @@ def project_get_networks(context, project_id, associate=True): return IMPL.project_get_networks(context, project_id, associate) +def project_get_requested_networks(context, requested_networks): + """Return the network associated with the project. + + 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_requested_networks(context, requested_networks) + + def project_get_networks_v6(context, project_id): return IMPL.project_get_networks_v6(context, project_id) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ffd009513..d5cfc6099 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -251,7 +251,7 @@ def service_get_all_network_sorted(context): session = get_session() with session.begin(): topic = 'network' - label = 'network_count' + label = 'network_' subq = session.query(models.Network.host, func.count(models.Network.id).label(label)).\ filter_by(deleted=False).\ @@ -684,6 +684,40 @@ def fixed_ip_associate_pool(context, network_id, instance_id): return fixed_ip_ref['address'] +@require_admin_context +def fixed_ip_associate_by_address(context, network_id, instance_id, + address): + if address is None: + return fixed_ip_associate_pool(context, network_id, instance_id) + + session = get_session() + with session.begin(): + fixed_ip_ref = session.query(models.FixedIp).\ + filter_by(reserved=False).\ + filter_by(deleted=False).\ + filter_by(network_id=network_id).\ + filter_by(address=address).\ + with_lockmode('update').\ + first() + # NOTE(vish): if with_lockmode isn't supported, as in sqlite, + # then this has concurrency issues + if fixed_ip_ref is None: + raise exception.FixedIpNotFoundForNetwork(address=address, + network_id=network_id) + if fixed_ip_ref.instance is not None: + raise exception.FixedIpAlreadyInUse(address=address) + + if not fixed_ip_ref.network: + fixed_ip_ref.network = network_get(context, + network_id, + session=session) + fixed_ip_ref.instance = instance_get(context, + instance_id, + session=session) + session.add(fixed_ip_ref) + return fixed_ip_ref['address'] + + @require_context def fixed_ip_create(_context, values): fixed_ip_ref = models.FixedIp() @@ -771,6 +805,26 @@ def fixed_ip_get_by_address(context, address, session=None): return result +@require_context +def fixed_ip_validate_by_network_address(context, network_id, + address): + session = get_session() + fixed_ip_ref = session.query(models.FixedIp).\ + filter_by(address=address).\ + filter_by(reserved=False).\ + filter_by(network_id=network_id).\ + filter_by(deleted=can_read_deleted(context)).\ + first() + + if fixed_ip_ref is None: + raise exception.FixedIpNotFoundForNetwork(address=address, + network_id=network_id) + if fixed_ip_ref.instance is not None: + raise exception.FixedIpAlreadyInUse(address=address) + + return fixed_ip_ref + + @require_context def fixed_ip_get_by_instance(context, instance_id): session = get_session() @@ -1613,6 +1667,39 @@ def network_get_all(context): return result +@require_admin_context +def network_get_requested_networks(context, requested_networks): + session = get_session() + + network_ids = [] + for id, fixed_ip in requested_networks: + network_ids.append(id) + + result = session.query(models.Network).\ + filter(models.Network.id.in_(network_ids)).\ + filter_by(deleted=False).all() + if not result: + raise exception.NoNetworksFound() + + #check if host is set to all of the networks + # returned in the result + for network in result: + if network['host'] is None: + raise exception.NetworkHostNotSet(network_id=network['id']) + + #check if the result contains all the networks + #we are looking for + for network_id in network_ids: + found = False + for network in result: + if network['id'] == network_id: + found = True + break + if not found: + raise exception.NetworkNotFound(network_id=network_id) + + return result + # NOTE(vish): pylint complains because of the long method name, but # it fits with the names of the rest of the methods # pylint: disable=C0103 @@ -2727,6 +2814,42 @@ def project_get_networks(context, project_id, associate=True): return result +@require_context +def project_get_requested_networks(context, requested_networks): + session = get_session() + + network_ids = [] + for id, fixed_ip in requested_networks: + network_ids.append(id) + + result = session.query(models.Network).\ + filter(models.Network.id.in_(network_ids)).\ + filter_by(deleted=False).\ + filter_by(project_id=context.project_id).all() + + if not result: + raise exception.NoNetworksFound() + + #check if host is set to all of the networks + # returned in the result + for network in result: + if network['host'] is None: + raise exception.NetworkHostNotSet(network_id=network['id']) + + #check if the result contains all the networks + #we are looking for + for network_id in network_ids: + found = False + for network in result: + if network['id'] == network_id: + found = True + break + if not found: + raise exception.NetworkNotFoundForProject(network_id=network_id, + project_id=context.project_id) + return result + + @require_context def project_get_networks_v6(context, project_id): return project_get_networks(context, project_id) -- cgit From d963e25906b75a48c75b6e589deb2a53f75d6ee3 Mon Sep 17 00:00:00 2001 From: Christopher MacGown Date: Fri, 22 Jul 2011 20:29:37 -0700 Subject: Config-Drive happiness, minus smoketest --- .../versions/035_add_config_drive_to_instances.py | 43 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 1 + 2 files changed, 44 insertions(+) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/035_add_config_drive_to_instances.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/035_add_config_drive_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/035_add_config_drive_to_instances.py new file mode 100644 index 000000000..65ea012dd --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/035_add_config_drive_to_instances.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# +# 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 Column, Integer, MetaData, String, Table + +from nova import utils + + +meta = MetaData() + +instances = Table("instances", meta, + Column("id", Integer(), primary_key=True, nullable=False)) +config_drive_column = Column("config_drive", String(255)) # matches image_ref + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + instances.create_column(config_drive_column) + + rows = migrate_engine.execute(instances.select()) + for row in rows: + instance_config_drive = None # pre-existing instances don't have one. + migrate_engine.execute(instances.update()\ + .where(instances.c.id == row[0])\ + .values(config_drive=instance_config_drive)) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + instances.drop_column(config_drive_column) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index c1150f7ca..73ad1f011 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -238,6 +238,7 @@ class Instance(BASE, NovaBase): uuid = Column(String(36)) root_device_name = Column(String(255)) + config_drive = Column(String(255)) # TODO(vish): see Ewan's email about state improvements, probably # should be in a driver base class or some such -- cgit From aee7778549904dc89fbd792ee60924932621a720 Mon Sep 17 00:00:00 2001 From: Ryu Ishimoto Date: Fri, 5 Aug 2011 15:02:29 +0900 Subject: Added migration to add uuid to virtual interfaces. Added uuid column to models --- .../versions/037_add_uuid_to_virtual_interfaces.py | 44 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 2 + 2 files changed, 46 insertions(+) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_virtual_interfaces.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_virtual_interfaces.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_virtual_interfaces.py new file mode 100644 index 000000000..0f542cbec --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_virtual_interfaces.py @@ -0,0 +1,44 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2011 Midokura KK +# +# 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 Column, Integer, MetaData, String, Table + +from nova import utils + + +meta = MetaData() + +virtual_interfaces = Table("virtual_interfaces", meta, + Column("id", Integer(), primary_key=True, + nullable=False)) +uuid_column = Column("uuid", String(36)) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + virtual_interfaces.create_column(uuid_column) + + rows = migrate_engine.execute(virtual_interfaces.select()) + for row in rows: + vif_uuid = str(utils.gen_uuid()) + migrate_engine.execute(virtual_interfaces.update()\ + .where(virtual_interfaces.c.id == row[0])\ + .values(uuid=vif_uuid)) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + virtual_interfaces.drop_column(uuid_column) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 9f4c7a0aa..3ab0a2b0c 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -565,6 +565,8 @@ class VirtualInterface(BASE, NovaBase): instance_id = Column(Integer, ForeignKey('instances.id'), nullable=False) instance = relationship(Instance, backref=backref('virtual_interfaces')) + uuid = Column(String(36)) + @property def fixed_ipv6(self): cidr_v6 = self.network.cidr_v6 -- cgit From fb0b82c0d6af2d67ec9a88842d857b558eaec5d1 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Fri, 5 Aug 2011 15:00:31 -0700 Subject: Refactored code to reduce lines of code and changed method signature --- nova/db/api.py | 12 ++++++------ nova/db/sqlalchemy/api.py | 14 ++------------ 2 files changed, 8 insertions(+), 18 deletions(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index b98859ef9..789e9bc97 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -710,9 +710,9 @@ def network_get_all(context): return IMPL.network_get_all(context) -def network_get_requested_networks(context, requested_networks): - """Return all defined networks.""" - return IMPL.network_get_requested_networks(context, requested_networks) +def network_get_networks_by_ids(context, network_ids): + """Return networks by ids.""" + return IMPL.network_get_networks_by_ids(context, network_ids) # pylint: disable=C0103 @@ -1262,14 +1262,14 @@ def project_get_networks(context, project_id, associate=True): return IMPL.project_get_networks(context, project_id, associate) -def project_get_requested_networks(context, requested_networks): - """Return the network associated with the project. +def project_get_networks_by_ids(context, network_ids): + """Return the networks by ids associated with the project. 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_requested_networks(context, requested_networks) + return IMPL.project_get_networks_by_ids(context, network_ids) def project_get_networks_v6(context, project_id): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 5de720205..63964a193 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1701,13 +1701,8 @@ def network_get_all(context): @require_admin_context -def network_get_requested_networks(context, requested_networks): +def network_get_networks_by_ids(context, network_ids): session = get_session() - - network_ids = [] - for id, fixed_ip in requested_networks: - network_ids.append(id) - result = session.query(models.Network).\ filter(models.Network.id.in_(network_ids)).\ filter_by(deleted=False).all() @@ -2873,13 +2868,8 @@ def project_get_networks(context, project_id, associate=True): @require_context -def project_get_requested_networks(context, requested_networks): +def project_get_networks_by_ids(context, network_ids): session = get_session() - - network_ids = [] - for id, fixed_ip in requested_networks: - network_ids.append(id) - result = session.query(models.Network).\ filter(models.Network.id.in_(network_ids)).\ filter_by(deleted=False).\ -- cgit From 19a4ddaf157ebb388cce37ddc142dfad304b8cf0 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Fri, 12 Aug 2011 16:48:13 -0700 Subject: Added add securitygroup to instance and remove securitygroup from instance functionality --- nova/db/api.py | 6 ++++++ nova/db/sqlalchemy/api.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index 0f2218752..cf814d43e 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -570,6 +570,12 @@ def instance_add_security_group(context, instance_id, security_group_id): security_group_id) +def instance_remove_security_group(context, instance_id, security_group_id): + """Disassociate the given security group from the given instance.""" + return IMPL.instance_remove_security_group(context, instance_id, + security_group_id) + + def instance_get_vcpu_sum_by_host_and_project(context, hostname, proj_id): """Get instances.vcpus by host and project.""" return IMPL.instance_get_vcpu_sum_by_host_and_project(context, diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index e5d35a20b..ba16f9109 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1482,6 +1482,19 @@ def instance_add_security_group(context, instance_id, security_group_id): instance_ref.save(session=session) +@require_context +def instance_remove_security_group(context, instance_id, security_group_id): + """Disassociate the given security group from the given instance""" + session = get_session() + + session.query(models.SecurityGroupInstanceAssociation).\ + filter_by(instance_id=instance_id).\ + filter_by(security_group_id=security_group_id).\ + update({'deleted': True, + 'deleted_at': utils.utcnow(), + 'updated_at': literal_column('updated_at')}) + + @require_context def instance_get_vcpu_sum_by_host_and_project(context, hostname, proj_id): session = get_session() @@ -2456,6 +2469,7 @@ def security_group_get(context, security_group_id, session=None): filter_by(deleted=can_read_deleted(context),).\ filter_by(id=security_group_id).\ options(joinedload_all('rules')).\ + options(joinedload_all('instances')).\ first() else: result = session.query(models.SecurityGroup).\ @@ -2463,6 +2477,7 @@ def security_group_get(context, security_group_id, session=None): filter_by(id=security_group_id).\ filter_by(project_id=context.project_id).\ options(joinedload_all('rules')).\ + options(joinedload_all('instances')).\ first() if not result: raise exception.SecurityGroupNotFound( -- cgit From 066b675e3ce5c2bd67dde124cbe01b68bd1eded8 Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 15 Aug 2011 13:22:14 -0700 Subject: fix bug which DescribeInstances in EC2 api was returning deleted instances --- nova/db/sqlalchemy/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index e5d35a20b..e7b71d494 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -1209,7 +1209,8 @@ def instance_get_all_by_filters(context, filters): options(joinedload('security_groups')).\ options(joinedload_all('fixed_ips.network')).\ options(joinedload('metadata')).\ - options(joinedload('instance_type')) + options(joinedload('instance_type')).\ + filter_by(deleted=can_read_deleted(context)) # Make a copy of the filters dictionary to use going forward, as we'll # be modifying it and we shouldn't affect the caller's use of it. -- cgit From 9081e8b62ea01828238ecaebdcf3e627ada3fe9a Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Tue, 16 Aug 2011 16:04:18 -0700 Subject: Added uuid for networks and made changes to the Create server API format to accept network as uuid instead of id --- nova/db/api.py | 23 +++--------- nova/db/sqlalchemy/api.py | 40 +++++--------------- .../versions/037_add_uuid_to_networks.py | 43 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 1 + 4 files changed, 59 insertions(+), 48 deletions(-) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index b6b98daf4..6833e6312 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -404,14 +404,6 @@ def fixed_ip_update(context, address, values): """Create a fixed ip from the values dictionary.""" return IMPL.fixed_ip_update(context, address, values) - -def fixed_ip_validate_by_network_address(context, network_id, - address): - """validates if the address belongs to the network""" - return IMPL.fixed_ip_validate_by_network_address(context, network_id, - address) - - #################### @@ -695,9 +687,9 @@ def network_get_all(context): return IMPL.network_get_all(context) -def network_get_networks_by_ids(context, network_ids): +def network_get_networks_by_uuids(context, network_uuids): """Return networks by ids.""" - return IMPL.network_get_networks_by_ids(context, network_ids) + return IMPL.network_get_networks_by_uuids(context, network_uuids) # pylint: disable=C0103 @@ -1252,14 +1244,9 @@ def project_get_networks(context, project_id, associate=True): return IMPL.project_get_networks(context, project_id, associate) -def project_get_networks_by_ids(context, network_ids): - """Return the networks by ids associated with the project. - - 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_networks_by_ids(context, network_ids) +def project_get_networks_by_uuids(context, network_uuids): + """Return the networks by uuids associated with the project.""" + return IMPL.project_get_networks_by_uuids(context, network_uuids) def project_get_networks_v6(context, project_id): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index dde371820..21eb85b2c 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -824,26 +824,6 @@ def fixed_ip_get_by_address(context, address, session=None): return result -@require_context -def fixed_ip_validate_by_network_address(context, network_id, - address): - session = get_session() - fixed_ip_ref = session.query(models.FixedIp).\ - filter_by(address=address).\ - filter_by(reserved=False).\ - filter_by(network_id=network_id).\ - filter_by(deleted=can_read_deleted(context)).\ - first() - - if fixed_ip_ref is None: - raise exception.FixedIpNotFoundForNetwork(address=address, - network_id=network_id) - if fixed_ip_ref.instance is not None: - raise exception.FixedIpAlreadyInUse(address=address) - - return fixed_ip_ref - - @require_context def fixed_ip_get_by_instance(context, instance_id): session = get_session() @@ -1778,10 +1758,10 @@ def network_get_all(context): @require_admin_context -def network_get_networks_by_ids(context, network_ids): +def network_get_networks_by_uuids(context, network_uuids): session = get_session() result = session.query(models.Network).\ - filter(models.Network.id.in_(network_ids)).\ + filter(models.Network.uuid.in_(network_uuids)).\ filter_by(deleted=False).all() if not result: raise exception.NoNetworksFound() @@ -1794,14 +1774,14 @@ def network_get_networks_by_ids(context, network_ids): #check if the result contains all the networks #we are looking for - for network_id in network_ids: + for network_uuid in network_uuids: found = False for network in result: - if network['id'] == network_id: + if network['uuid'] == network_uuid: found = True break if not found: - raise exception.NetworkNotFound(network_id=network_id) + raise exception.NetworkNotFound(network_id=network_uuid) return result @@ -2962,10 +2942,10 @@ def project_get_networks(context, project_id, associate=True): @require_context -def project_get_networks_by_ids(context, network_ids): +def project_get_networks_by_uuids(context, network_uuids): session = get_session() result = session.query(models.Network).\ - filter(models.Network.id.in_(network_ids)).\ + filter(models.Network.uuid.in_(network_uuids)).\ filter_by(deleted=False).\ filter_by(project_id=context.project_id).all() @@ -2980,14 +2960,14 @@ def project_get_networks_by_ids(context, network_ids): #check if the result contains all the networks #we are looking for - for network_id in network_ids: + for uuid in network_uuids: found = False for network in result: - if network['id'] == network_id: + if network['uuid'] == uuid: found = True break if not found: - raise exception.NetworkNotFoundForProject(network_id=network_id, + raise exception.NetworkNotFoundForProject(network_uuid=uuid, project_id=context.project_id) return result diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py new file mode 100644 index 000000000..38c543d51 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# +# 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 Column, Integer, MetaData, String, Table + +from nova import utils + + +meta = MetaData() + +networks = Table("networks", meta, + Column("id", Integer(), primary_key=True, nullable=False)) +uuid_column = Column("uuid", String(36)) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + networks.create_column(uuid_column) + + rows = migrate_engine.execute(networks.select()) + for row in rows: + networks_uuid = str(utils.gen_uuid()) + migrate_engine.execute(networks.update()\ + .where(networks.c.id == row[0])\ + .values(uuid=networks_uuid)) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + networks.drop_column(uuid_column) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index f2a4680b0..5cadd156d 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -557,6 +557,7 @@ class Network(BASE, NovaBase): project_id = Column(String(255)) host = Column(String(255)) # , ForeignKey('hosts.id')) + uuid = Column(String(36)) class VirtualInterface(BASE, NovaBase): -- cgit From c890722ddfec7b6ef1911bfbbfd834ac1e3666d5 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 16 Aug 2011 23:15:54 -0400 Subject: Remove instances.admin_pass column. --- .../versions/037_instances_drop_admin_pass.py | 37 ++++++++++++++++++++++ nova/db/sqlalchemy/models.py | 1 - 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_instances_drop_admin_pass.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_instances_drop_admin_pass.py b/nova/db/sqlalchemy/migrate_repo/versions/037_instances_drop_admin_pass.py new file mode 100644 index 000000000..b957666c2 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_instances_drop_admin_pass.py @@ -0,0 +1,37 @@ +# Copyright 2011 OpenStack LLC. +# +# 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 Column, MetaData, Table, String + +meta = MetaData() + +admin_pass = Column( + 'admin_pass', + String(length=255, convert_unicode=False, assert_unicode=None, + unicode_error=None, _warn_on_bytestring=False), + nullable=True) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True, + autoload_with=migrate_engine) + instances.drop_column('admin_pass') + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True, + autoload_with=migrate_engine) + instances.create_column(admin_pass) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index f2a4680b0..a8e9c36db 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -173,7 +173,6 @@ class Instance(BASE, NovaBase): base_name += "-rescue" return base_name - admin_pass = Column(String(255)) user_id = Column(String(255)) project_id = Column(String(255)) -- cgit From 7e3f360eb256ba82629a44de60d36be643d5105d Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 17 Aug 2011 15:33:08 -0400 Subject: Added migration for accessIPv4 and accessIPv6 --- .../versions/037_add_instances_accessip.py | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py new file mode 100644 index 000000000..82de2a874 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py @@ -0,0 +1,49 @@ +# Copyright 2011 OpenStack LLC. +# +# 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 Column, Integer, MetaData, Table, String + +meta = MetaData() + +accessIPv4 = Column( + 'access_ip_v4', + String(length=255, convert_unicode=False, assert_unicode=None, + unicode_error=None, _warn_on_bytestring=False), + nullable=True) + +accessIPv6 = Column( + 'access_ip_v6', + String(length=255, convert_unicode=False, assert_unicode=None, + unicode_error=None, _warn_on_bytestring=False), + nullable=True) + +instances = Table('instances', meta, + Column('id', Integer(), primary_key=True, nullable=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 + instances.create_column(accessIPv4) + instances.create_column(accessIPv6) + + +def downgrade(migrate_engine): + # Operations to reverse the above upgrade go here. + meta.bind = migrate_engine + instances.drop_column('access_ip_v4') + instances.drop_column('access_ip_v6') -- cgit From 8ba3ea03aa58d5b0791b9fd3654dd034cbd3a8bc Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 17 Aug 2011 15:40:17 -0400 Subject: Added accessip to models pep8 --- .../sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py | 1 - nova/db/sqlalchemy/models.py | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py index 82de2a874..39f0dd6ce 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py @@ -33,7 +33,6 @@ instances = Table('instances', meta, ) - def upgrade(migrate_engine): # Upgrade operations go here. Don't create your own engine; # bind migrate_engine to your metadata diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index f2a4680b0..1249a6269 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -232,6 +232,11 @@ class Instance(BASE, NovaBase): root_device_name = Column(String(255)) + # User editable field meant to represent what ip should be used + # to connect to the instance + access_ip_v4 = Column(String(255)) + access_ip_v6 = 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 -- cgit From bbcb84a5fed2c537bd6d2143e344fa96f669d231 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 18 Aug 2011 20:25:32 +0000 Subject: DB password should be an empty string for MySQLdb --- nova/db/sqlalchemy/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/session.py b/nova/db/sqlalchemy/session.py index 07f281938..643e2338e 100644 --- a/nova/db/sqlalchemy/session.py +++ b/nova/db/sqlalchemy/session.py @@ -73,9 +73,11 @@ def get_engine(): elif MySQLdb and "mysql" in connection_dict.drivername: LOG.info(_("Using mysql/eventlet db_pool.")) + # MySQLdb won't accept 'None' in the password field + password = connection_dict.password or '' pool_args = { "db": connection_dict.database, - "passwd": connection_dict.password, + "passwd": password, "host": connection_dict.host, "user": connection_dict.username, "min_size": FLAGS.sql_min_pool_size, -- cgit From be0c70562ce978e3ffa85465fc08dd5cb3ca07c3 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Fri, 19 Aug 2011 10:47:16 -0400 Subject: updated migration number --- .../versions/037_add_instances_accessip.py | 48 ---------------------- .../versions/038_add_instances_accessip.py | 48 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/038_add_instances_accessip.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py deleted file mode 100644 index 39f0dd6ce..000000000 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_instances_accessip.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2011 OpenStack LLC. -# -# 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 Column, Integer, MetaData, Table, String - -meta = MetaData() - -accessIPv4 = Column( - 'access_ip_v4', - String(length=255, convert_unicode=False, assert_unicode=None, - unicode_error=None, _warn_on_bytestring=False), - nullable=True) - -accessIPv6 = Column( - 'access_ip_v6', - String(length=255, convert_unicode=False, assert_unicode=None, - unicode_error=None, _warn_on_bytestring=False), - nullable=True) - -instances = Table('instances', meta, - Column('id', Integer(), primary_key=True, nullable=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 - instances.create_column(accessIPv4) - instances.create_column(accessIPv6) - - -def downgrade(migrate_engine): - # Operations to reverse the above upgrade go here. - meta.bind = migrate_engine - instances.drop_column('access_ip_v4') - instances.drop_column('access_ip_v6') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/038_add_instances_accessip.py b/nova/db/sqlalchemy/migrate_repo/versions/038_add_instances_accessip.py new file mode 100644 index 000000000..39f0dd6ce --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/038_add_instances_accessip.py @@ -0,0 +1,48 @@ +# Copyright 2011 OpenStack LLC. +# +# 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 Column, Integer, MetaData, Table, String + +meta = MetaData() + +accessIPv4 = Column( + 'access_ip_v4', + String(length=255, convert_unicode=False, assert_unicode=None, + unicode_error=None, _warn_on_bytestring=False), + nullable=True) + +accessIPv6 = Column( + 'access_ip_v6', + String(length=255, convert_unicode=False, assert_unicode=None, + unicode_error=None, _warn_on_bytestring=False), + nullable=True) + +instances = Table('instances', meta, + Column('id', Integer(), primary_key=True, nullable=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 + instances.create_column(accessIPv4) + instances.create_column(accessIPv6) + + +def downgrade(migrate_engine): + # Operations to reverse the above upgrade go here. + meta.bind = migrate_engine + instances.drop_column('access_ip_v4') + instances.drop_column('access_ip_v6') -- cgit From 83d4c5b9b1f7ed9b75ae04464423b7ca4b5d627d Mon Sep 17 00:00:00 2001 From: Christopher MacGown Date: Fri, 19 Aug 2011 08:08:23 -0700 Subject: Fix config_drive migration, per Matt Dietz. --- .../versions/037_add_config_drive_to_instances.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py index 65ea012dd..36a6af16f 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py @@ -23,20 +23,15 @@ meta = MetaData() instances = Table("instances", meta, Column("id", Integer(), primary_key=True, nullable=False)) -config_drive_column = Column("config_drive", String(255)) # matches image_ref + +# matches the size of an image_ref +config_drive_column = Column("config_drive", String(255), nullable=True) def upgrade(migrate_engine): meta.bind = migrate_engine instances.create_column(config_drive_column) - rows = migrate_engine.execute(instances.select()) - for row in rows: - instance_config_drive = None # pre-existing instances don't have one. - migrate_engine.execute(instances.update()\ - .where(instances.c.id == row[0])\ - .values(config_drive=instance_config_drive)) - def downgrade(migrate_engine): meta.bind = migrate_engine -- cgit From c4fc9f0737ec9f8d5c950b850fed9930a68164f4 Mon Sep 17 00:00:00 2001 From: Christopher MacGown Date: Fri, 19 Aug 2011 08:44:14 -0700 Subject: Add copyright notices --- .../migrate_repo/versions/037_add_config_drive_to_instances.py | 4 ++-- nova/db/sqlalchemy/models.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py index 36a6af16f..d3058f00d 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_config_drive_to_instances.py @@ -1,6 +1,6 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 OpenStack LLC. +# +# Copyright 2011 Piston Cloud Computing, Inc. # # 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 diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 8a6e2f673..c454cfcc3 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -2,6 +2,7 @@ # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. +# Copyright 2011 Piston Cloud Computing, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may -- cgit From d27a4d4a59a0103762ece2776ddd484629a72d54 Mon Sep 17 00:00:00 2001 From: Tushar Patil Date: Fri, 19 Aug 2011 14:25:41 -0700 Subject: Fixed review comments --- nova/db/api.py | 21 +---- nova/db/sqlalchemy/api.py | 104 ++++++--------------- .../versions/037_add_uuid_to_networks.py | 43 --------- .../versions/039_add_uuid_to_networks.py | 43 +++++++++ 4 files changed, 76 insertions(+), 135 deletions(-) delete mode 100644 nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/039_add_uuid_to_networks.py (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index 6833e6312..34d560ca3 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -323,13 +323,13 @@ def migration_get_by_instance_and_status(context, instance_uuid, status): #################### -def fixed_ip_associate(context, address, instance_id): +def fixed_ip_associate(context, address, instance_id, network_id=None): """Associate fixed ip to instance. Raises if fixed ip is not available. """ - return IMPL.fixed_ip_associate(context, address, instance_id) + return IMPL.fixed_ip_associate(context, address, instance_id, network_id) def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): @@ -342,14 +342,6 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): instance_id, host) -def fixed_ip_associate_by_address(context, network_id, instance_id, address): - """check if the address is free and is in the network - and it is not associated to any instance. - """ - return IMPL.fixed_ip_associate_by_address(context, network_id, - instance_id, address) - - def fixed_ip_create(context, values): """Create a fixed ip from the values dictionary.""" return IMPL.fixed_ip_create(context, values) @@ -687,9 +679,9 @@ def network_get_all(context): return IMPL.network_get_all(context) -def network_get_networks_by_uuids(context, network_uuids): +def network_get_all_by_uuids(context, network_uuids, project_id=None): """Return networks by ids.""" - return IMPL.network_get_networks_by_uuids(context, network_uuids) + return IMPL.network_get_all_by_uuids(context, network_uuids, project_id) # pylint: disable=C0103 @@ -1244,11 +1236,6 @@ def project_get_networks(context, project_id, associate=True): return IMPL.project_get_networks(context, project_id, associate) -def project_get_networks_by_uuids(context, network_uuids): - """Return the networks by uuids associated with the project.""" - return IMPL.project_get_networks_by_uuids(context, network_uuids) - - def project_get_networks_v6(context, project_id): return IMPL.project_get_networks_v6(context, project_id) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 5aa49213a..005500058 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -266,7 +266,7 @@ def service_get_all_network_sorted(context): session = get_session() with session.begin(): topic = 'network' - label = 'network_' + label = 'network_count' subq = session.query(models.Network.host, func.count(models.Network.id).label(label)).\ filter_by(deleted=False).\ @@ -652,23 +652,36 @@ def floating_ip_update(context, address, values): ################### -@require_context -def fixed_ip_associate(context, address, instance_id): +@require_admin_context +def fixed_ip_associate(context, address, instance_id, network_id=None): session = get_session() with session.begin(): - instance = instance_get(context, instance_id, session=session) + network_or_none = or_(models.FixedIp.network_id == network_id, + models.FixedIp.network_id == None) fixed_ip_ref = session.query(models.FixedIp).\ - filter_by(address=address).\ + filter(network_or_none).\ + filter_by(reserved=False).\ filter_by(deleted=False).\ - filter_by(instance=None).\ + filter_by(address=address).\ with_lockmode('update').\ first() # NOTE(vish): if with_lockmode isn't supported, as in sqlite, # then this has concurrency issues - if not fixed_ip_ref: - raise exception.NoMoreFixedIps() - fixed_ip_ref.instance = instance + if fixed_ip_ref is None: + raise exception.FixedIpNotFoundForNetwork(address=address, + network_id=network_id) + if fixed_ip_ref.instance is not None: + raise exception.FixedIpAlreadyInUse(address=address) + + if not fixed_ip_ref.network: + fixed_ip_ref.network = network_get(context, + network_id, + session=session) + fixed_ip_ref.instance = instance_get(context, + instance_id, + session=session) session.add(fixed_ip_ref) + return fixed_ip_ref['address'] @require_admin_context @@ -703,40 +716,6 @@ def fixed_ip_associate_pool(context, network_id, instance_id=None, host=None): return fixed_ip_ref['address'] -@require_admin_context -def fixed_ip_associate_by_address(context, network_id, instance_id, - address): - if address is None: - return fixed_ip_associate_pool(context, network_id, instance_id) - - session = get_session() - with session.begin(): - fixed_ip_ref = session.query(models.FixedIp).\ - filter_by(reserved=False).\ - filter_by(deleted=False).\ - filter_by(network_id=network_id).\ - filter_by(address=address).\ - with_lockmode('update').\ - first() - # NOTE(vish): if with_lockmode isn't supported, as in sqlite, - # then this has concurrency issues - if fixed_ip_ref is None: - raise exception.FixedIpNotFoundForNetwork(address=address, - network_id=network_id) - if fixed_ip_ref.instance is not None: - raise exception.FixedIpAlreadyInUse(address=address) - - if not fixed_ip_ref.network: - fixed_ip_ref.network = network_get(context, - network_id, - session=session) - fixed_ip_ref.instance = instance_get(context, - instance_id, - session=session) - session.add(fixed_ip_ref) - return fixed_ip_ref['address'] - - @require_context def fixed_ip_create(_context, values): fixed_ip_ref = models.FixedIp() @@ -1777,10 +1756,13 @@ def network_get_all(context): @require_admin_context -def network_get_networks_by_uuids(context, network_uuids): +def network_get_all_by_uuids(context, network_uuids, project_id=None): session = get_session() + project_or_none = or_(models.Network.project_id == project_id, + models.Network.project_id == None) result = session.query(models.Network).\ filter(models.Network.uuid.in_(network_uuids)).\ + filter(project_or_none).\ filter_by(deleted=False).all() if not result: raise exception.NoNetworksFound() @@ -1800,6 +1782,9 @@ def network_get_networks_by_uuids(context, network_uuids): found = True break if not found: + if project_id: + raise exception.NetworkNotFoundForProject(network_uuid=uuid, + project_id=context.project_id) raise exception.NetworkNotFound(network_id=network_uuid) return result @@ -2961,37 +2946,6 @@ def project_get_networks(context, project_id, associate=True): return result -@require_context -def project_get_networks_by_uuids(context, network_uuids): - session = get_session() - result = session.query(models.Network).\ - filter(models.Network.uuid.in_(network_uuids)).\ - filter_by(deleted=False).\ - filter_by(project_id=context.project_id).all() - - if not result: - raise exception.NoNetworksFound() - - #check if host is set to all of the networks - # returned in the result - for network in result: - if network['host'] is None: - raise exception.NetworkHostNotSet(network_id=network['id']) - - #check if the result contains all the networks - #we are looking for - for uuid in network_uuids: - found = False - for network in result: - if network['uuid'] == uuid: - found = True - break - if not found: - raise exception.NetworkNotFoundForProject(network_uuid=uuid, - project_id=context.project_id) - return result - - @require_context def project_get_networks_v6(context, project_id): return project_get_networks(context, project_id) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py deleted file mode 100644 index 38c543d51..000000000 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_uuid_to_networks.py +++ /dev/null @@ -1,43 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 OpenStack LLC. -# -# 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 Column, Integer, MetaData, String, Table - -from nova import utils - - -meta = MetaData() - -networks = Table("networks", meta, - Column("id", Integer(), primary_key=True, nullable=False)) -uuid_column = Column("uuid", String(36)) - - -def upgrade(migrate_engine): - meta.bind = migrate_engine - networks.create_column(uuid_column) - - rows = migrate_engine.execute(networks.select()) - for row in rows: - networks_uuid = str(utils.gen_uuid()) - migrate_engine.execute(networks.update()\ - .where(networks.c.id == row[0])\ - .values(uuid=networks_uuid)) - - -def downgrade(migrate_engine): - meta.bind = migrate_engine - networks.drop_column(uuid_column) diff --git a/nova/db/sqlalchemy/migrate_repo/versions/039_add_uuid_to_networks.py b/nova/db/sqlalchemy/migrate_repo/versions/039_add_uuid_to_networks.py new file mode 100644 index 000000000..38c543d51 --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/039_add_uuid_to_networks.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# +# 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 Column, Integer, MetaData, String, Table + +from nova import utils + + +meta = MetaData() + +networks = Table("networks", meta, + Column("id", Integer(), primary_key=True, nullable=False)) +uuid_column = Column("uuid", String(36)) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + networks.create_column(uuid_column) + + rows = migrate_engine.execute(networks.select()) + for row in rows: + networks_uuid = str(utils.gen_uuid()) + migrate_engine.execute(networks.update()\ + .where(networks.c.id == row[0])\ + .values(uuid=networks_uuid)) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + networks.drop_column(uuid_column) -- cgit From 7f1adb50cfab91a553f2d129b9b2eef1e5b2145b Mon Sep 17 00:00:00 2001 From: Christopher MacGown Date: Mon, 22 Aug 2011 22:17:51 -0700 Subject: Moved migration and fixed tests from upstream --- .../versions/041_add_config_drive_to_instances.py | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 nova/db/sqlalchemy/migrate_repo/versions/041_add_config_drive_to_instances.py (limited to 'nova/db') diff --git a/nova/db/sqlalchemy/migrate_repo/versions/041_add_config_drive_to_instances.py b/nova/db/sqlalchemy/migrate_repo/versions/041_add_config_drive_to_instances.py new file mode 100644 index 000000000..d3058f00d --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/041_add_config_drive_to_instances.py @@ -0,0 +1,38 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2011 Piston Cloud Computing, Inc. +# +# 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 Column, Integer, MetaData, String, Table + +from nova import utils + + +meta = MetaData() + +instances = Table("instances", meta, + Column("id", Integer(), primary_key=True, nullable=False)) + +# matches the size of an image_ref +config_drive_column = Column("config_drive", String(255), nullable=True) + + +def upgrade(migrate_engine): + meta.bind = migrate_engine + instances.create_column(config_drive_column) + + +def downgrade(migrate_engine): + meta.bind = migrate_engine + instances.drop_column(config_drive_column) -- cgit