Revert "New flavor"

This reverts commit aecfc71fdd.

Change-Id: Idbc41b50a9dede2bb99b1a882d5c19677ada4f2a
This commit is contained in:
Zhenguo Niu
2017-06-15 03:24:11 +00:00
parent a58e95c750
commit 4210266c28
10 changed files with 4 additions and 317 deletions

View File

@@ -54,62 +54,6 @@ def upgrade():
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'flavor_cpus',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('model', sa.String(length=255), nullable=True),
sa.Column('cores', sa.Integer(), nullable=False),
sa.Column('flavor_uuid', sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['flavor_uuid'],
['flavors.uuid']),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'flavor_memory',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=True),
sa.Column('size_mb', sa.Integer(), nullable=False),
sa.Column('flavor_uuid', sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['flavor_uuid'],
['flavors.uuid']),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'flavor_disks',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=True),
sa.Column('size_gb', sa.Integer(), nullable=False),
sa.Column('flavor_uuid', sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['flavor_uuid'],
['flavors.uuid']),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'flavor_nics',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(length=255), nullable=True),
sa.Column('speed', sa.String(length=255), nullable=False),
sa.Column('flavor_uuid', sa.String(length=36), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['flavor_uuid'],
['flavors.uuid']),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)
op.create_table(
'servers',
sa.Column('created_at', sa.DateTime(), nullable=True),

View File

@@ -96,39 +96,6 @@ def add_identity_filter(query, value):
raise exception.InvalidParameterValue(identity=value)
def _dict_with_extra_fields(flavor_query):
"""Takes a server type query and returns it as a dictionary."""
flavor_dict = dict(flavor_query)
# cpus
cpus = {}
for c in flavor_query['cpus']:
cpus = {'model': c['model'], 'cores': c['cores']}
flavor_dict['cpus'] = cpus
# memory
memory = {}
for m in flavor_query['memory']:
memory = {'type': m['type'], 'size_mb': m['size_mb']}
flavor_dict['memory'] = memory
# nics
nics = []
for n in flavor_query['nics']:
nic = {'type': n['type'], 'speed': n['speed']}
nics.append(nic)
flavor_dict['nics'] = nics
# disks
disks = []
for d in flavor_query['disks']:
disk = {'type': d['type'], 'size_gb': d['size_gb']}
disks.append(disk)
flavor_dict['disks'] = disks
return flavor_dict
class Connection(api.Connection):
"""SqlAlchemy connection."""
@@ -143,45 +110,16 @@ class Connection(api.Connection):
if not values.get('description'):
values['description'] = ""
cpus = values.pop('cpus', None)
memory = values.pop('memory', None)
nics = values.pop('nics', [])
disks = values.pop('disks', [])
flavor = models.Flavors()
flavor.update(values)
with _session_for_write() as session:
try:
session.add(flavor)
# add flavor cpus
if cpus:
flavor_cpus = models.FlavorCpus()
cpus['flavor_uuid'] = values['uuid']
flavor_cpus.update(cpus)
session.add(flavor_cpus)
# add flavor memory
if memory:
flavor_mem = models.FlavorMemory()
memory['flavor_uuid'] = values['uuid']
flavor_mem.update(memory)
session.add(flavor_mem)
# add flavor nics
for nic in nics:
flavor_nic = models.FlavorNics()
nic['flavor_uuid'] = values['uuid']
flavor_nic.update(nic)
session.add(flavor_nic)
# add flavor disks
for disk in disks:
flavor_disk = models.FlavorDisks()
disk['flavor_uuid'] = values['uuid']
flavor_disk.update(disk)
session.add(flavor_disk)
session.flush()
except db_exc.DBDuplicateEntry:
raise exception.FlavorAlreadyExists(uuid=values['uuid'])
return _dict_with_extra_fields(flavor)
return flavor
def flavor_get(self, context, flavor_uuid):
query = model_query(context, models.Flavors).filter_by(
@@ -195,7 +133,7 @@ class Connection(api.Connection):
query = query.filter(or_(*the_filter))
try:
return _dict_with_extra_fields(query.one())
return query.one()
except NoResultFound:
raise exception.FlavorNotFound(
type_id=flavor_uuid)
@@ -222,40 +160,12 @@ class Connection(api.Connection):
])
query = query.filter(or_(*the_filter))
return [_dict_with_extra_fields(i) for i in query.all()]
return [i for i in query.all()]
def flavor_destroy(self, context, flavor_uuid):
with _session_for_write():
type_id = _type_get_id_from_type(context, flavor_uuid)
# Clean up cpus related to this flavor
cpus_query = model_query(
context,
models.FlavorCpus).filter_by(
flavor_uuid=type_id)
cpus_query.delete()
# Clean up memory related to this flavor
memory_query = model_query(
context,
models.FlavorMemory).filter_by(
flavor_uuid=type_id)
memory_query.delete()
# Clean up nics related to this flavor
nics_query = model_query(
context,
models.FlavorNics).filter_by(
flavor_uuid=type_id)
nics_query.delete()
# Clean up disks related to this flavor
disks_query = model_query(
context,
models.FlavorDisks).filter_by(
flavor_uuid=type_id)
disks_query.delete()
# Clean up all access related to this flavor
project_query = model_query(
context,

View File

@@ -209,74 +209,6 @@ class FlavorProjects(Base):
' == Flavors.uuid')
class FlavorCpus(Base):
"""Represents the flavor cpus."""
__tablename__ = 'flavor_cpus'
id = Column(Integer, primary_key=True)
model = Column(String(255), nullable=False)
cores = Column(Integer, nullable=False)
flavor_uuid = Column(String(36), ForeignKey('flavors.uuid'),
nullable=False)
flavor = orm.relationship(
Flavors,
backref='cpus',
foreign_keys=flavor_uuid,
primaryjoin='FlavorCpus.flavor_uuid '
'== Flavors.uuid')
class FlavorMemory(Base):
"""Represents the flavor memory."""
__tablename__ = 'flavor_memory'
id = Column(Integer, primary_key=True)
type = Column(String(255), nullable=False)
size_mb = Column(Integer, nullable=False)
flavor_uuid = Column(String(36), ForeignKey('flavors.uuid'),
nullable=False)
flavor = orm.relationship(
Flavors,
backref='memory',
foreign_keys=flavor_uuid,
primaryjoin='FlavorMemory.flavor_uuid '
'== Flavors.uuid')
class FlavorDisks(Base):
"""Represents the flavor disks."""
__tablename__ = 'flavor_disks'
id = Column(Integer, primary_key=True)
type = Column(String(255), nullable=False)
size_gb = Column(Integer, nullable=False)
flavor_uuid = Column(String(36), ForeignKey('flavors.uuid'),
nullable=False)
flavor = orm.relationship(
Flavors,
backref='disks',
foreign_keys=flavor_uuid,
primaryjoin='FlavorDisks.flavor_uuid '
'== Flavors.uuid')
class FlavorNics(Base):
"""Represents the flavor nics."""
__tablename__ = 'flavor_nics'
id = Column(Integer, primary_key=True)
type = Column(String(255), nullable=False)
speed = Column(String(255), nullable=False)
flavor_uuid = Column(String(36), ForeignKey('flavors.uuid'),
nullable=False)
flavor = orm.relationship(
Flavors,
backref='nics',
foreign_keys=flavor_uuid,
primaryjoin='FlavorNics.flavor_uuid '
'== Flavors.uuid')
class ServerFault(Base):
"""Represents fault info for server"""