Add database fields for OVA storage

This commit is contained in:
Joshua Boniface 2020-02-17 11:27:35 -05:00
parent b16e2b4925
commit d975f90f29
2 changed files with 126 additions and 4 deletions

View File

@ -0,0 +1,76 @@
"""PVC version 0.7
Revision ID: 88c8514684f7
Revises: 2d1daa722a0a
Create Date: 2020-02-16 19:49:50.126265
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '88c8514684f7'
down_revision = '2d1daa722a0a'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('ova',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.Text(), nullable=False),
sa.Column('ovf', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('ova_volume',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('ova', sa.Integer(), nullable=False),
sa.Column('pool', sa.Text(), nullable=False),
sa.Column('volume_name', sa.Text(), nullable=False),
sa.Column('volume_format', sa.Text(), nullable=False),
sa.Column('disk_id', sa.Text(), nullable=False),
sa.Column('disk_size_gb', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['ova'], ['ova.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.alter_column('network', 'network_template',
existing_type=sa.INTEGER(),
nullable=False)
op.add_column('network_template', sa.Column('ova', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'network_template', 'ova', ['ova'], ['id'])
op.add_column('profile', sa.Column('ova', sa.Integer(), nullable=True))
op.add_column('profile', sa.Column('profile_type', sa.Text(), nullable=False))
op.create_foreign_key(None, 'profile', 'ova', ['ova'], ['id'])
op.alter_column('storage', 'storage_template',
existing_type=sa.INTEGER(),
nullable=False)
op.add_column('storage_template', sa.Column('ova', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'storage_template', 'ova', ['ova'], ['id'])
op.add_column('system_template', sa.Column('ova', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'system_template', 'ova', ['ova'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'system_template', type_='foreignkey')
op.drop_column('system_template', 'ova')
op.drop_constraint(None, 'storage_template', type_='foreignkey')
op.drop_column('storage_template', 'ova')
op.alter_column('storage', 'storage_template',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_constraint(None, 'profile', type_='foreignkey')
op.drop_column('profile', 'profile_type')
op.drop_column('profile', 'ova')
op.drop_constraint(None, 'network_template', type_='foreignkey')
op.drop_column('network_template', 'ova')
op.alter_column('network', 'network_template',
existing_type=sa.INTEGER(),
nullable=True)
op.drop_table('ova_volume')
op.drop_table('ova')
# ### end Alembic commands ###

View File

@ -35,8 +35,9 @@ class DBSystemTemplate(db.Model):
node_limit = db.Column(db.Text)
node_selector = db.Column(db.Text)
node_autostart = db.Column(db.Boolean, nullable=False)
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
def __init__(self, name, vcpu_count, vram_mb, serial, vnc, vnc_bind, node_limit, node_selector, node_autostart):
def __init__(self, name, vcpu_count, vram_mb, serial, vnc, vnc_bind, node_limit, node_selector, node_autostart, ova=None):
self.name = name
self.vcpu_count = vcpu_count
self.vram_mb = vram_mb
@ -46,6 +47,7 @@ class DBSystemTemplate(db.Model):
self.node_limit = node_limit
self.node_selector = node_selector
self.node_autostart = node_autostart
self.ova = ova
def __repr__(self):
return '<id {}>'.format(self.id)
@ -56,10 +58,12 @@ class DBNetworkTemplate(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text, nullable=False, unique=True)
mac_template = db.Column(db.Text)
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
def __init__(self, name, mac_template):
def __init__(self, name, mac_template, ova=None):
self.name = name
self.mac_template = mac_template
self.ova = ova
def __repr__(self):
return '<id {}>'.format(self.id)
@ -83,9 +87,11 @@ class DBStorageTemplate(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text, nullable=False, unique=True)
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
def __init__(self, name):
def __init__(self, name, ova=None):
self.name = name
self.ova = ova
def __repr__(self):
return '<id {}>'.format(self.id)
@ -144,25 +150,65 @@ class DBScript(db.Model):
def __repr__(self):
return '<id {}>'.format(self.id)
class DBOva(db.Model):
__tablename__ = 'ova'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text, nullable=False, unique=True)
ovf = db.Column(db.Text, nullable=False)
def __init__(self, name, ovf):
self.name = name
self.ovf = ovf
def __repr__(self):
return '<id {}>'.format(self.id)
class DBOvaVolume(db.Model):
__tablename__ = 'ova_volume'
id = db.Column(db.Integer, primary_key=True)
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=False)
pool = db.Column(db.Text, nullable=False)
volume_name = db.Column(db.Text, nullable=False)
volume_format = db.Column(db.Text, nullable=False)
disk_id = db.Column(db.Text, nullable=False)
disk_size_gb = db.Column(db.Integer, nullable=False)
def __init__(self, ova, pool, volume_name, volume_format, disk_id, disk_size_gb):
self.ova = ova
self.pool = pool
self.volume_name = volume_name
self.volume_format = volume_format
self.disk_id = disk_id
self.disk_size_gb = disk_size_gb
def __repr__(self):
return '<id {}>'.format(self.id)
class DBProfile(db.Model):
__tablename__ = 'profile'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text, nullable=False, unique=True)
profile_type = db.Column(db.Text, nullable=False)
system_template = db.Column(db.Integer, db.ForeignKey("system_template.id"))
network_template = db.Column(db.Integer, db.ForeignKey("network_template.id"))
storage_template = db.Column(db.Integer, db.ForeignKey("storage_template.id"))
userdata = db.Column(db.Integer, db.ForeignKey("userdata.id"))
script = db.Column(db.Integer, db.ForeignKey("script.id"))
ova = db.Column(db.Integer, db.ForeignKey("ova.id"))
arguments = db.Column(db.Text)
def __init__(self, name, system_template, network_template, storage_template, userdata, script, arguments):
def __init__(self, name, profile_type, system_template, network_template, storage_template, userdata, script, ova, arguments):
self.name = name
self.profile_type = profile_type
self.system_template = system_template
self.network_template = network_template
self.storage_template = storage_template
self.userdata = userdata
self.script = script
self.ova = ova
self.arguments = arguments
def __repr__(self):