2020-02-15 22:10:34 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
# models.py - PVC Database models
|
|
|
|
# Part of the Parallel Virtual Cluster (PVC) system
|
|
|
|
#
|
2023-12-29 11:16:59 -05:00
|
|
|
# Copyright (C) 2018-2024 Joshua M. Boniface <joshua@boniface.me>
|
2020-02-15 22:10:34 -05:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2021-03-25 16:57:17 -04:00
|
|
|
# the Free Software Foundation, version 3.
|
2020-02-15 22:10:34 -05:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
2020-11-06 19:22:49 -05:00
|
|
|
from pvcapid.flaskapi import db
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBSystemTemplate(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "system_template"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
|
|
|
vcpu_count = db.Column(db.Integer, nullable=False)
|
|
|
|
vram_mb = db.Column(db.Integer, nullable=False)
|
|
|
|
serial = db.Column(db.Boolean, nullable=False)
|
|
|
|
vnc = db.Column(db.Boolean, nullable=False)
|
|
|
|
vnc_bind = db.Column(db.Text)
|
|
|
|
node_limit = db.Column(db.Text)
|
|
|
|
node_selector = db.Column(db.Text)
|
|
|
|
node_autostart = db.Column(db.Boolean, nullable=False)
|
2020-10-29 11:31:32 -04:00
|
|
|
migration_method = db.Column(db.Text)
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime = db.Column(db.Integer, default=300, server_default="300")
|
2020-02-17 11:27:35 -05:00
|
|
|
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
vcpu_count,
|
|
|
|
vram_mb,
|
|
|
|
serial,
|
|
|
|
vnc,
|
|
|
|
vnc_bind,
|
|
|
|
node_limit,
|
|
|
|
node_selector,
|
|
|
|
node_autostart,
|
|
|
|
migration_method,
|
2024-01-10 16:13:31 -05:00
|
|
|
migration_max_downtime,
|
2021-11-06 03:02:43 -04:00
|
|
|
ova=None,
|
|
|
|
):
|
2020-02-15 22:10:34 -05:00
|
|
|
self.name = name
|
|
|
|
self.vcpu_count = vcpu_count
|
|
|
|
self.vram_mb = vram_mb
|
|
|
|
self.serial = serial
|
|
|
|
self.vnc = vnc
|
|
|
|
self.vnc_bind = vnc_bind
|
|
|
|
self.node_limit = node_limit
|
|
|
|
self.node_selector = node_selector
|
|
|
|
self.node_autostart = node_autostart
|
2020-10-29 11:31:32 -04:00
|
|
|
self.migration_method = migration_method
|
2024-01-10 16:13:31 -05:00
|
|
|
self.migration_max_downtime = migration_max_downtime
|
2020-02-17 11:27:35 -05:00
|
|
|
self.ova = ova
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBNetworkTemplate(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "network_template"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
|
|
|
mac_template = db.Column(db.Text)
|
2020-02-17 11:27:35 -05:00
|
|
|
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-02-17 11:27:35 -05:00
|
|
|
def __init__(self, name, mac_template, ova=None):
|
2020-02-15 22:10:34 -05:00
|
|
|
self.name = name
|
|
|
|
self.mac_template = mac_template
|
2020-02-17 11:27:35 -05:00
|
|
|
self.ova = ova
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBNetworkElement(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "network"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-11-06 03:02:43 -04:00
|
|
|
network_template = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("network_template.id"), nullable=False
|
|
|
|
)
|
2021-06-03 00:22:48 -04:00
|
|
|
vni = db.Column(db.Text, nullable=False)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
def __init__(self, network_template, vni):
|
|
|
|
self.network_template = network_template
|
|
|
|
self.vni = vni
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBStorageTemplate(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "storage_template"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
2020-02-17 11:27:35 -05:00
|
|
|
ova = db.Column(db.Integer, db.ForeignKey("ova.id"), nullable=True)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-02-17 11:27:35 -05:00
|
|
|
def __init__(self, name, ova=None):
|
2020-02-15 22:10:34 -05:00
|
|
|
self.name = name
|
2020-02-17 11:27:35 -05:00
|
|
|
self.ova = ova
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBStorageElement(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "storage"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-11-06 03:02:43 -04:00
|
|
|
storage_template = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("storage_template.id"), nullable=False
|
|
|
|
)
|
2020-02-15 22:10:34 -05:00
|
|
|
pool = db.Column(db.Text, nullable=False)
|
|
|
|
disk_id = db.Column(db.Text, nullable=False)
|
|
|
|
source_volume = db.Column(db.Text)
|
|
|
|
disk_size_gb = db.Column(db.Integer)
|
|
|
|
mountpoint = db.Column(db.Text)
|
|
|
|
filesystem = db.Column(db.Text)
|
|
|
|
filesystem_args = db.Column(db.Text)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
storage_template,
|
|
|
|
pool,
|
|
|
|
disk_id,
|
|
|
|
source_volume,
|
|
|
|
disk_size_gb,
|
|
|
|
mountpoint,
|
|
|
|
filesystem,
|
|
|
|
filesystem_args,
|
|
|
|
):
|
2020-02-15 22:10:34 -05:00
|
|
|
self.storage_template = storage_template
|
|
|
|
self.pool = pool
|
|
|
|
self.disk_id = disk_id
|
|
|
|
self.source_volume = source_volume
|
|
|
|
self.disk_size_gb = disk_size_gb
|
|
|
|
self.mountpoint = mountpoint
|
|
|
|
self.filesystem = filesystem
|
|
|
|
self.filesystem_args = filesystem_args
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBUserdata(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "userdata"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
|
|
|
userdata = db.Column(db.Text, nullable=False)
|
|
|
|
|
|
|
|
def __init__(self, name, userdata):
|
|
|
|
self.name = name
|
|
|
|
self.userdata = userdata
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBScript(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "script"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
|
|
|
script = db.Column(db.Text, nullable=False)
|
|
|
|
|
|
|
|
def __init__(self, name, script):
|
|
|
|
self.name = name
|
|
|
|
self.script = script
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-15 22:10:34 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-17 11:27:35 -05:00
|
|
|
class DBOva(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "ova"
|
2020-02-17 11:27:35 -05:00
|
|
|
|
|
|
|
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):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-17 11:27:35 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-17 11:27:35 -05:00
|
|
|
class DBOvaVolume(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "ova_volume"
|
2020-02-17 11:27:35 -05:00
|
|
|
|
|
|
|
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):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-02-17 11:27:35 -05:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-02-15 22:10:34 -05:00
|
|
|
class DBProfile(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "profile"
|
2020-02-15 22:10:34 -05:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.Text, nullable=False, unique=True)
|
2020-02-17 11:27:35 -05:00
|
|
|
profile_type = db.Column(db.Text, nullable=False)
|
2022-10-06 10:27:08 -04:00
|
|
|
system_template = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("system_template.id"), nullable=False
|
|
|
|
)
|
2020-02-15 22:10:34 -05:00
|
|
|
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"))
|
2022-10-06 10:27:08 -04:00
|
|
|
script = db.Column(db.Integer, db.ForeignKey("script.id"), nullable=False)
|
2020-02-17 11:27:35 -05:00
|
|
|
ova = db.Column(db.Integer, db.ForeignKey("ova.id"))
|
2020-02-15 22:10:34 -05:00
|
|
|
arguments = db.Column(db.Text)
|
|
|
|
|
2021-11-06 03:02:43 -04:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
name,
|
|
|
|
profile_type,
|
|
|
|
system_template,
|
|
|
|
network_template,
|
|
|
|
storage_template,
|
|
|
|
userdata,
|
|
|
|
script,
|
|
|
|
ova,
|
|
|
|
arguments,
|
|
|
|
):
|
2020-02-15 22:10:34 -05:00
|
|
|
self.name = name
|
2020-02-17 11:27:35 -05:00
|
|
|
self.profile_type = profile_type
|
2020-02-15 22:10:34 -05:00
|
|
|
self.system_template = system_template
|
|
|
|
self.network_template = network_template
|
|
|
|
self.storage_template = storage_template
|
|
|
|
self.userdata = userdata
|
|
|
|
self.script = script
|
2020-02-17 11:27:35 -05:00
|
|
|
self.ova = ova
|
2020-02-15 22:10:34 -05:00
|
|
|
self.arguments = arguments
|
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|
2020-08-24 14:57:52 -04:00
|
|
|
|
2020-11-07 14:45:24 -05:00
|
|
|
|
2020-08-24 14:57:52 -04:00
|
|
|
class DBStorageBenchmarks(db.Model):
|
2021-11-06 03:02:43 -04:00
|
|
|
__tablename__ = "storage_benchmarks"
|
2020-08-24 14:57:52 -04:00
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
job = db.Column(db.Text, nullable=False)
|
2021-11-06 03:02:43 -04:00
|
|
|
test_format = db.Column(db.Integer, nullable=False, default=0, server_default="0")
|
2020-08-24 14:57:52 -04:00
|
|
|
result = db.Column(db.Text, nullable=False)
|
|
|
|
|
2021-10-02 00:53:27 -04:00
|
|
|
def __init__(self, job, result, test_format):
|
2020-08-24 14:57:52 -04:00
|
|
|
self.job = job
|
|
|
|
self.result = result
|
2021-10-02 00:53:27 -04:00
|
|
|
self.test_format = test_format
|
2020-08-24 14:57:52 -04:00
|
|
|
|
|
|
|
def __repr__(self):
|
2021-11-06 03:02:43 -04:00
|
|
|
return "<id {}>".format(self.id)
|