VSA code redesign. Drive types completely replaced by Volume types
This commit is contained in:
@@ -918,16 +918,6 @@ def volume_get_all_by_project(context, project_id):
|
||||
return IMPL.volume_get_all_by_project(context, project_id)
|
||||
|
||||
|
||||
def volume_get_all_assigned_to_vsa(context, vsa_id):
|
||||
"""Get all volumes assigned to particular VSA."""
|
||||
return IMPL.volume_get_all_assigned_to_vsa(context, vsa_id)
|
||||
|
||||
|
||||
def volume_get_all_assigned_from_vsa(context, vsa_id):
|
||||
"""Get all volumes created from particular VSA."""
|
||||
return IMPL.volume_get_all_assigned_from_vsa(context, vsa_id)
|
||||
|
||||
|
||||
def volume_get_by_ec2_id(context, ec2_id):
|
||||
"""Get a volume by ec2 id."""
|
||||
return IMPL.volume_get_by_ec2_id(context, ec2_id)
|
||||
@@ -1528,36 +1518,6 @@ def volume_type_extra_specs_update_or_create(context, volume_type_id,
|
||||
####################
|
||||
|
||||
|
||||
def drive_type_create(context, values):
|
||||
"""Creates drive type record."""
|
||||
return IMPL.drive_type_create(context, values)
|
||||
|
||||
|
||||
def drive_type_update(context, drive_type_id, values):
|
||||
"""Updates drive type record."""
|
||||
return IMPL.drive_type_update(context, drive_type_id, values)
|
||||
|
||||
|
||||
def drive_type_destroy(context, drive_type_id):
|
||||
"""Deletes drive type record."""
|
||||
return IMPL.drive_type_destroy(context, drive_type_id)
|
||||
|
||||
|
||||
def drive_type_get(context, drive_type_id):
|
||||
"""Get drive type record by id."""
|
||||
return IMPL.drive_type_get(context, drive_type_id)
|
||||
|
||||
|
||||
def drive_type_get_by_name(context, name):
|
||||
"""Get drive type record by name."""
|
||||
return IMPL.drive_type_get_by_name(context, name)
|
||||
|
||||
|
||||
def drive_type_get_all(context, visible):
|
||||
"""Returns all (or only visible) drive types."""
|
||||
return IMPL.drive_type_get_all(context, visible)
|
||||
|
||||
|
||||
def vsa_create(context, values):
|
||||
"""Creates Virtual Storage Array record."""
|
||||
return IMPL.vsa_create(context, values)
|
||||
@@ -1586,8 +1546,3 @@ def vsa_get_all(context):
|
||||
def vsa_get_all_by_project(context, project_id):
|
||||
"""Get all Virtual Storage Array records by project ID."""
|
||||
return IMPL.vsa_get_all_by_project(context, project_id)
|
||||
|
||||
|
||||
def vsa_get_vc_ips_list(context, vsa_id):
|
||||
"""Retrieves IPs of instances associated with Virtual Storage Array."""
|
||||
return IMPL.vsa_get_vc_ips_list(context, vsa_id)
|
||||
|
||||
@@ -2226,7 +2226,6 @@ def volume_get(context, volume_id, session=None):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(id=volume_id).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
first()
|
||||
@@ -2235,7 +2234,6 @@ def volume_get(context, volume_id, session=None):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(project_id=context.project_id).\
|
||||
filter_by(id=volume_id).\
|
||||
filter_by(deleted=False).\
|
||||
@@ -2253,7 +2251,6 @@ def volume_get_all(context):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
all()
|
||||
|
||||
@@ -2265,7 +2262,6 @@ def volume_get_all_by_host(context, host):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(host=host).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
all()
|
||||
@@ -2277,7 +2273,6 @@ def volume_get_all_by_instance(context, instance_id):
|
||||
result = session.query(models.Volume).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(instance_id=instance_id).\
|
||||
filter_by(deleted=False).\
|
||||
all()
|
||||
@@ -2286,28 +2281,6 @@ def volume_get_all_by_instance(context, instance_id):
|
||||
return result
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def volume_get_all_assigned_to_vsa(context, vsa_id):
|
||||
session = get_session()
|
||||
result = session.query(models.Volume).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(to_vsa_id=vsa_id).\
|
||||
filter_by(deleted=False).\
|
||||
all()
|
||||
return result
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def volume_get_all_assigned_from_vsa(context, vsa_id):
|
||||
session = get_session()
|
||||
result = session.query(models.Volume).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(from_vsa_id=vsa_id).\
|
||||
filter_by(deleted=False).\
|
||||
all()
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def volume_get_all_by_project(context, project_id):
|
||||
authorize_project_context(context, project_id)
|
||||
@@ -2317,7 +2290,6 @@ def volume_get_all_by_project(context, project_id):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
filter_by(project_id=project_id).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
all()
|
||||
@@ -2332,7 +2304,6 @@ def volume_get_instance(context, volume_id):
|
||||
options(joinedload('instance')).\
|
||||
options(joinedload('volume_metadata')).\
|
||||
options(joinedload('volume_type')).\
|
||||
options(joinedload('drive_type')).\
|
||||
first()
|
||||
if not result:
|
||||
raise exception.VolumeNotFound(volume_id=volume_id)
|
||||
@@ -2377,7 +2348,7 @@ def volume_update(context, volume_id, values):
|
||||
volume_ref = volume_get(context, volume_id, session=session)
|
||||
volume_ref.update(values)
|
||||
volume_ref.save(session=session)
|
||||
return volume_ref
|
||||
|
||||
|
||||
####################
|
||||
|
||||
@@ -3871,106 +3842,6 @@ def volume_type_extra_specs_update_or_create(context, volume_type_id,
|
||||
####################
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def drive_type_create(context, values):
|
||||
"""
|
||||
Creates drive type record.
|
||||
"""
|
||||
try:
|
||||
drive_type_ref = models.DriveTypes()
|
||||
drive_type_ref.update(values)
|
||||
drive_type_ref.save()
|
||||
except Exception, e:
|
||||
raise exception.DBError(e)
|
||||
return drive_type_ref
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def drive_type_update(context, drive_type_id, values):
|
||||
"""
|
||||
Updates drive type record.
|
||||
"""
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
drive_type_ref = drive_type_get(context, drive_type_id,
|
||||
session=session)
|
||||
drive_type_ref.update(values)
|
||||
drive_type_ref.save(session=session)
|
||||
return drive_type_ref
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def drive_type_destroy(context, drive_type_id):
|
||||
"""
|
||||
Deletes drive type record.
|
||||
"""
|
||||
session = get_session()
|
||||
drive_type_ref = session.query(models.DriveTypes).\
|
||||
filter_by(id=drive_type_id)
|
||||
records = drive_type_ref.delete()
|
||||
if records == 0:
|
||||
raise exception.VirtualDiskTypeNotFound(id=drive_type_id)
|
||||
|
||||
|
||||
@require_context
|
||||
def drive_type_get(context, drive_type_id, session=None):
|
||||
"""
|
||||
Get drive type record by id.
|
||||
"""
|
||||
if not session:
|
||||
session = get_session()
|
||||
|
||||
result = session.query(models.DriveTypes).\
|
||||
filter_by(id=drive_type_id).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
first()
|
||||
if not result:
|
||||
raise exception.VirtualDiskTypeNotFound(id=drive_type_id)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def drive_type_get_by_name(context, name, session=None):
|
||||
"""
|
||||
Get drive type record by name.
|
||||
"""
|
||||
if not session:
|
||||
session = get_session()
|
||||
|
||||
result = session.query(models.DriveTypes).\
|
||||
filter_by(name=name).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
first()
|
||||
if not result:
|
||||
raise exception.VirtualDiskTypeNotFoundByName(name=name)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def drive_type_get_all(context, visible):
|
||||
"""
|
||||
Returns all (or only visible) drive types.
|
||||
"""
|
||||
session = get_session()
|
||||
if visible:
|
||||
drive_types = session.query(models.DriveTypes).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
filter_by(visible=True).\
|
||||
order_by("name").\
|
||||
all()
|
||||
else:
|
||||
drive_types = session.query(models.DriveTypes).\
|
||||
filter_by(deleted=can_read_deleted(context)).\
|
||||
order_by("name").\
|
||||
all()
|
||||
return drive_types
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def vsa_create(context, values):
|
||||
"""
|
||||
@@ -4067,26 +3938,4 @@ def vsa_get_all_by_project(context, project_id):
|
||||
all()
|
||||
|
||||
|
||||
@require_context
|
||||
def vsa_get_vc_ips_list(context, vsa_id):
|
||||
"""
|
||||
Retrieves IPs of instances associated with Virtual Storage Array.
|
||||
"""
|
||||
result = []
|
||||
|
||||
vc_instances = instance_get_all_by_filters(context,
|
||||
search_opts={'metadata': dict(vsa_id=str(vsa_id))})
|
||||
for vc_instance in vc_instances:
|
||||
if vc_instance['fixed_ips']:
|
||||
for fixed in vc_instance['fixed_ips']:
|
||||
# insert the [floating,fixed] (if exists) in the head,
|
||||
# otherwise append the [none,fixed] in the tail
|
||||
ip = {}
|
||||
ip['fixed'] = fixed['address']
|
||||
if fixed['floating_ips']:
|
||||
ip['floating'] = fixed['floating_ips'][0]['address']
|
||||
result.append(ip)
|
||||
|
||||
return result
|
||||
|
||||
####################
|
||||
|
||||
@@ -22,19 +22,7 @@ from nova import log as logging
|
||||
|
||||
meta = MetaData()
|
||||
|
||||
# Just for the ForeignKey and column creation to succeed, these are not the
|
||||
# actual definitions of tables .
|
||||
#
|
||||
|
||||
volumes = Table('volumes', meta,
|
||||
Column('id', Integer(), primary_key=True, nullable=False),
|
||||
)
|
||||
|
||||
to_vsa_id = Column('to_vsa_id', Integer(), nullable=True)
|
||||
from_vsa_id = Column('from_vsa_id', Integer(), nullable=True)
|
||||
drive_type_id = Column('drive_type_id', Integer(), nullable=True)
|
||||
|
||||
|
||||
# New Tables
|
||||
#
|
||||
|
||||
@@ -67,67 +55,21 @@ virtual_storage_arrays = Table('virtual_storage_arrays', meta,
|
||||
unicode_error=None, _warn_on_bytestring=False)),
|
||||
)
|
||||
|
||||
drive_types = Table('drive_types', meta,
|
||||
Column('created_at', DateTime(timezone=False)),
|
||||
Column('updated_at', DateTime(timezone=False)),
|
||||
Column('deleted_at', DateTime(timezone=False)),
|
||||
Column('deleted', Boolean(create_constraint=True, name=None)),
|
||||
Column('id', Integer(), primary_key=True, nullable=False),
|
||||
Column('name',
|
||||
String(length=255, convert_unicode=False, assert_unicode=None,
|
||||
unicode_error=None, _warn_on_bytestring=False),
|
||||
unique=True),
|
||||
Column('type',
|
||||
String(length=255, convert_unicode=False, assert_unicode=None,
|
||||
unicode_error=None, _warn_on_bytestring=False)),
|
||||
Column('size_gb', Integer(), nullable=False),
|
||||
Column('rpm',
|
||||
String(length=255, convert_unicode=False, assert_unicode=None,
|
||||
unicode_error=None, _warn_on_bytestring=False)),
|
||||
Column('capabilities',
|
||||
String(length=255, convert_unicode=False, assert_unicode=None,
|
||||
unicode_error=None, _warn_on_bytestring=False)),
|
||||
Column('visible', Boolean(create_constraint=True, name=None)),
|
||||
)
|
||||
|
||||
new_tables = (virtual_storage_arrays, drive_types)
|
||||
|
||||
#
|
||||
# Tables to alter
|
||||
#
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
# Upgrade operations go here. Don't create your own engine;
|
||||
# bind migrate_engine to your metadata
|
||||
meta.bind = migrate_engine
|
||||
|
||||
for table in new_tables:
|
||||
try:
|
||||
table.create()
|
||||
except Exception:
|
||||
logging.info(repr(table))
|
||||
logging.exception('Exception while creating table')
|
||||
raise
|
||||
|
||||
volumes.create_column(to_vsa_id)
|
||||
volumes.create_column(from_vsa_id)
|
||||
volumes.create_column(drive_type_id)
|
||||
try:
|
||||
virtual_storage_arrays.create()
|
||||
except Exception:
|
||||
logging.info(repr(table))
|
||||
logging.exception('Exception while creating table')
|
||||
raise
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
|
||||
volumes.drop_column(to_vsa_id)
|
||||
volumes.drop_column(from_vsa_id)
|
||||
volumes.drop_column(drive_type_id)
|
||||
|
||||
for table in new_tables:
|
||||
table.drop()
|
||||
virtual_storage_arrays.drop()
|
||||
@@ -352,13 +352,6 @@ class Volume(BASE, NovaBase):
|
||||
|
||||
volume_type_id = Column(Integer)
|
||||
|
||||
to_vsa_id = Column(Integer,
|
||||
ForeignKey('virtual_storage_arrays.id'), nullable=True)
|
||||
from_vsa_id = Column(Integer,
|
||||
ForeignKey('virtual_storage_arrays.id'), nullable=True)
|
||||
drive_type_id = Column(Integer,
|
||||
ForeignKey('drive_types.id'), nullable=True)
|
||||
|
||||
|
||||
class VolumeMetadata(BASE, NovaBase):
|
||||
"""Represents a metadata key/value pair for a volume"""
|
||||
@@ -402,38 +395,6 @@ class VolumeTypeExtraSpecs(BASE, NovaBase):
|
||||
'VolumeTypeExtraSpecs.deleted == False)')
|
||||
|
||||
|
||||
class DriveTypes(BASE, NovaBase):
|
||||
"""Represents the known drive types (storage media)."""
|
||||
__tablename__ = 'drive_types'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
"""
|
||||
@property
|
||||
def name(self):
|
||||
if self.capabilities:
|
||||
return FLAGS.drive_type_template_long % \
|
||||
(self.type, str(self.size_gb), self.rpm, self.capabilities)
|
||||
else:
|
||||
return FLAGS.drive_type_template_short % \
|
||||
(self.type, str(self.size_gb), self.rpm)
|
||||
"""
|
||||
|
||||
name = Column(String(255), unique=True)
|
||||
type = Column(String(255))
|
||||
size_gb = Column(Integer)
|
||||
rpm = Column(String(255))
|
||||
capabilities = Column(String(255))
|
||||
|
||||
visible = Column(Boolean, default=True)
|
||||
|
||||
volumes = relationship(Volume,
|
||||
backref=backref('drive_type', uselist=False),
|
||||
foreign_keys=id,
|
||||
primaryjoin='and_(Volume.drive_type_id == '
|
||||
'DriveTypes.id)')
|
||||
|
||||
|
||||
class Quota(BASE, NovaBase):
|
||||
"""Represents a single quota override for a project.
|
||||
|
||||
@@ -918,7 +879,9 @@ def register_models():
|
||||
Network, SecurityGroup, SecurityGroupIngressRule,
|
||||
SecurityGroupInstanceAssociation, AuthToken, User,
|
||||
Project, Certificate, ConsolePool, Console, Zone,
|
||||
AgentBuild, InstanceMetadata, InstanceTypeExtraSpecs, Migration)
|
||||
VolumeMetadata, VolumeTypes, VolumeTypeExtraSpecs,
|
||||
AgentBuild, InstanceMetadata, InstanceTypeExtraSpecs, Migration,
|
||||
VirtualStorageArray)
|
||||
engine = create_engine(FLAGS.sql_connection, echo=False)
|
||||
for model in models:
|
||||
model.metadata.create_all(engine)
|
||||
|
||||
@@ -30,9 +30,11 @@ import nova.exception
|
||||
import nova.flags
|
||||
import nova.log
|
||||
|
||||
|
||||
FLAGS = nova.flags.FLAGS
|
||||
LOG = nova.log.getLogger("nova.db.sqlalchemy")
|
||||
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user