From 61fd1c40be7dbb8a0d86d68d49a1d007a2b9d7f6 Mon Sep 17 00:00:00 2001 From: Boris Pavlovic Date: Sat, 8 Jun 2013 13:13:01 +0400 Subject: Fix db.models.Instance description DB models definition should be up-to-date with DB schema obtained after applying of migrations. Currently, there are no tests enforcing this and it's really hard to analyze what indexes should be added, and what indexes we have at the moment. So the first step is it to fix all models, and add missing descriptions about Indexes and UniqueConstraints in __table_args__ and use explicit 'nullable' parameter in columns description. Add missing 'nullable' parameters to all Columns Add empty __table_args__ parameter to Table Add 6 missing indexes in Instance model definition. blueprint db-sync-models-with-migrations Change-Id: I01025789f00dcf058754ee1def726e3b48ec7fda --- nova/db/sqlalchemy/models.py | 96 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index f5cda04cc..e724db130 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -143,6 +143,20 @@ class Certificate(BASE, NovaBase): class Instance(BASE, NovaBase): """Represents a guest VM.""" __tablename__ = 'instances' + __table_args__ = ( + Index('instances_host_deleted_idx', + 'host', 'deleted'), + Index('instances_reservation_id_idx', + 'reservation_id'), + Index('instances_terminated_at_launched_at_idx', + 'terminated_at', 'launched_at'), + Index('instances_uuid_deleted_idx', + 'uuid', 'deleted'), + Index('instances_task_state_updated_at_idx', + 'task_state', 'updated_at'), + Index('instances_host_node_deleted_idx', + 'host', 'node', 'deleted') + ) injected_files = [] id = Column(Integer, primary_key=True, autoincrement=True) @@ -172,87 +186,87 @@ class Instance(BASE, NovaBase): def _extra_keys(self): return ['name'] - user_id = Column(String(255)) - project_id = Column(String(255)) + user_id = Column(String(255), nullable=True) + project_id = Column(String(255), nullable=True) - image_ref = Column(String(255)) - kernel_id = Column(String(255)) - ramdisk_id = Column(String(255)) - hostname = Column(String(255)) + image_ref = Column(String(255), nullable=True) + kernel_id = Column(String(255), nullable=True) + ramdisk_id = Column(String(255), nullable=True) + hostname = Column(String(255), nullable=True) - launch_index = Column(Integer) - key_name = Column(String(255)) + launch_index = Column(Integer, nullable=True) + key_name = Column(String(255), nullable=True) key_data = Column(Text) - power_state = Column(Integer) - vm_state = Column(String(255)) - task_state = Column(String(255)) + power_state = Column(Integer, nullable=True) + vm_state = Column(String(255), nullable=True) + task_state = Column(String(255), nullable=True) - memory_mb = Column(Integer) - vcpus = Column(Integer) - root_gb = Column(Integer) - ephemeral_gb = Column(Integer) + memory_mb = Column(Integer, nullable=True) + vcpus = Column(Integer, nullable=True) + root_gb = Column(Integer, nullable=True) + ephemeral_gb = Column(Integer, nullable=True) # This is not related to hostname, above. It refers # to the nova node. - host = Column(String(255)) # , ForeignKey('hosts.id')) + host = Column(String(255), nullable=True) # , ForeignKey('hosts.id')) # To identify the "ComputeNode" which the instance resides in. # This equals to ComputeNode.hypervisor_hostname. - node = Column(String(255)) + node = Column(String(255), nullable=True) # *not* flavor_id - instance_type_id = Column(Integer) + instance_type_id = Column(Integer, nullable=True) - user_data = Column(Text) + user_data = Column(Text, nullable=True) - reservation_id = Column(String(255)) + reservation_id = Column(String(255), nullable=True) - scheduled_at = Column(DateTime) - launched_at = Column(DateTime) - terminated_at = Column(DateTime) + scheduled_at = Column(DateTime, nullable=True) + launched_at = Column(DateTime, nullable=True) + terminated_at = Column(DateTime, nullable=True) - availability_zone = Column(String(255)) + availability_zone = Column(String(255), nullable=True) # User editable field for display in user-facing UIs - display_name = Column(String(255)) - display_description = Column(String(255)) + display_name = Column(String(255), nullable=True) + display_description = Column(String(255), nullable=True) # To remember on which host an instance booted. # An instance may have moved to another host by live migration. - launched_on = Column(Text) - locked = Column(Boolean) + launched_on = Column(Text, nullable=True) + locked = Column(Boolean, nullable=True) - os_type = Column(String(255)) - architecture = Column(String(255)) - vm_mode = Column(String(255)) - uuid = Column(String(36)) + os_type = Column(String(255), nullable=True) + architecture = Column(String(255), nullable=True) + vm_mode = Column(String(255), nullable=True) + uuid = Column(String(36), unique=True) - root_device_name = Column(String(255)) + root_device_name = Column(String(255), nullable=True) default_ephemeral_device = Column(String(255), nullable=True) default_swap_device = Column(String(255), nullable=True) - config_drive = Column(String(255)) + config_drive = Column(String(255), nullable=True) # User editable field meant to represent what ip should be used # to connect to the instance - access_ip_v4 = Column(types.IPAddress()) - access_ip_v6 = Column(types.IPAddress()) + access_ip_v4 = Column(types.IPAddress(), nullable=True) + access_ip_v6 = Column(types.IPAddress(), nullable=True) - auto_disk_config = Column(Boolean()) - progress = Column(Integer) + auto_disk_config = Column(Boolean(), nullable=True) + progress = Column(Integer, nullable=True) # EC2 instance_initiated_shutdown_terminate # True: -> 'terminate' # False: -> 'stop' # Note(maoy): currently Nova will always stop instead of terminate # no matter what the flag says. So we set the default to False. - shutdown_terminate = Column(Boolean(), default=False, nullable=False) + shutdown_terminate = Column(Boolean(), default=False, nullable=True) # EC2 disable_api_termination - disable_terminate = Column(Boolean(), default=False, nullable=False) + disable_terminate = Column(Boolean(), default=False, nullable=True) # OpenStack compute cell name. This will only be set at the top of # the cells tree and it'll be a full cell name such as 'api!hop1!hop2' - cell_name = Column(String(255)) + cell_name = Column(String(255), nullable=True) class InstanceInfoCache(BASE, NovaBase): -- cgit