summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorvladimir.p <vladimir@zadarastorage.com>2011-08-24 09:10:28 -0700
committervladimir.p <vladimir@zadarastorage.com>2011-08-24 09:10:28 -0700
commitcac910b2b58536eb8ef151b1b5a48ea95d0df51b (patch)
tree8e0c07bf59221ac64858c9dc610b376429ad4236 /nova/db
parent29940dd27f3a40a4ad54bc2f7a4cea5ac2226b83 (diff)
parentc8920f480233546d8a57265da66de7821c32ac7e (diff)
downloadnova-cac910b2b58536eb8ef151b1b5a48ea95d0df51b.tar.gz
nova-cac910b2b58536eb8ef151b1b5a48ea95d0df51b.tar.xz
nova-cac910b2b58536eb8ef151b1b5a48ea95d0df51b.zip
merged with rev.1485
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py18
-rw-r--r--nova/db/sqlalchemy/api.py81
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/037_instances_drop_admin_pass.py37
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/038_add_uuid_to_virtual_interfaces.py44
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/039_add_instances_accessip.py48
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/040_add_uuid_to_networks.py43
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/041_add_config_drive_to_instances.py38
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/042_add_volume_types_and_extradata.py (renamed from nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py)0
-rw-r--r--nova/db/sqlalchemy/models.py11
-rw-r--r--nova/db/sqlalchemy/session.py4
10 files changed, 310 insertions, 14 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 494d27708..8726df6dd 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):
@@ -396,7 +396,6 @@ def fixed_ip_update(context, address, values):
"""Create a fixed ip from the values dictionary."""
return IMPL.fixed_ip_update(context, address, values)
-
####################
@@ -570,6 +569,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_action_create(context, values):
"""Create an instance action from the values dictionary."""
return IMPL.instance_action_create(context, values)
@@ -680,7 +685,14 @@ def network_get_all(context):
return IMPL.network_get_all(context)
+def network_get_all_by_uuids(context, network_uuids, project_id=None):
+ """Return networks by ids."""
+ return IMPL.network_get_all_by_uuids(context, network_uuids, project_id)
+
+
# 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)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index f14f95ab0..5abdd71f9 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -666,23 +666,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
@@ -1236,7 +1249,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.
@@ -1515,6 +1529,19 @@ def instance_add_security_group(context, instance_id, security_group_id):
@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_action_create(context, values):
"""Create an instance action from the values dictionary."""
action_ref = models.InstanceActions()
@@ -1755,6 +1782,40 @@ def network_get_all(context):
return result
+@require_admin_context
+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()
+
+ #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_uuid in network_uuids:
+ found = False
+ for network in result:
+ if network['uuid'] == network_uuid:
+ 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
+
# 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
@@ -2576,6 +2637,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).\
@@ -2583,6 +2645,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(
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/migrate_repo/versions/038_add_uuid_to_virtual_interfaces.py b/nova/db/sqlalchemy/migrate_repo/versions/038_add_uuid_to_virtual_interfaces.py
new file mode 100644
index 000000000..0f542cbec
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/038_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/migrate_repo/versions/039_add_instances_accessip.py b/nova/db/sqlalchemy/migrate_repo/versions/039_add_instances_accessip.py
new file mode 100644
index 000000000..39f0dd6ce
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/039_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')
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/040_add_uuid_to_networks.py b/nova/db/sqlalchemy/migrate_repo/versions/040_add_uuid_to_networks.py
new file mode 100644
index 000000000..38c543d51
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/040_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/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)
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py b/nova/db/sqlalchemy/migrate_repo/versions/042_add_volume_types_and_extradata.py
index 27c8afcee..27c8afcee 100644
--- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py
+++ b/nova/db/sqlalchemy/migrate_repo/versions/042_add_volume_types_and_extradata.py
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 4195ca113..a37ccf91a 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
@@ -173,7 +174,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))
@@ -231,6 +231,12 @@ class Instance(BASE, NovaBase):
uuid = Column(String(36))
root_device_name = Column(String(255))
+ config_drive = 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
@@ -601,6 +607,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):
@@ -615,6 +622,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
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,