Prepare resource pools table for future development

This commit is contained in:
grossmj committed 2023-09-02 18:42:40 +07:00
1 parent 170f476733
commit e72b07bf5c
3 files changed
+25 -14

No files matched your search

+1
View File
@@ -22,6 +22,7 @@ from .roles import Role
from .privileges import Privilege
from .computes import Compute
from .images import Image
from .resource_pools import Resource, ResourcePool
from .templates import (
Template,
CloudTemplate,
+23 -13
View File
@@ -15,28 +15,38 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sqlalchemy import Column, String, Boolean, ForeignKey
from sqlalchemy import Table, Column, String, ForeignKey
from sqlalchemy.orm import relationship
from .base import BaseTable, generate_uuid, GUID
from .base import Base, BaseTable, generate_uuid, GUID
import logging
log = logging.getLogger(__name__)
resource_pool_map = Table(
"resource_pool_map",
Base.metadata,
Column("resource_id", GUID, ForeignKey("resources.resource_id", ondelete="CASCADE")),
Column("resource_pool_id", GUID, ForeignKey("resource_pools.resource_pool_id", ondelete="CASCADE"))
)
class Resource(BaseTable):
__tablename__ = "resources"
resource_id = Column(GUID, primary_key=True)
name = Column(String, unique=True, index=True)
resource_type = Column(String)
resource_pools = relationship("ResourcePool", secondary=resource_pool_map, back_populates="resources")
class ResourcePool(BaseTable):
__tablename__ = "resource_pools"
resource_id = Column(GUID, primary_key=True)
resource_type = Column(String)
# Create a self-referential relationship to represent a hierarchy of resources
parent_id = Column(GUID, ForeignKey("resources.resource_id", ondelete="CASCADE"))
children = relationship(
"Resource",
remote_side=[resource_id],
cascade="all, delete-orphan",
single_parent=True
)
resource_pool_id = Column(GUID, primary_key=True, default=generate_uuid)
name = Column(String, unique=True, index=True)
resources = relationship("Resource", secondary=resource_pool_map, back_populates="resource_pools")