Skip to content
Snippets Groups Projects
TopologyModel.py 1.82 KiB
Newer Older
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
import logging #, operator
from typing import Dict #, List
from sqlalchemy import Column, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
from sqlalchemy.orm import relationship
from ._Base import _Base

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
LOGGER = logging.getLogger(__name__)

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
class TopologyModel(_Base):
    __tablename__ = 'Topology'
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    context_uuid = Column(UUID(as_uuid=False), ForeignKey('context.context_uuid'), primary_key=True)
    topology_uuid = Column(UUID(as_uuid=False), primary_key=True, unique=True)

    # Relationships
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    context = relationship('ContextModel', back_populates='topology')
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed

    def dump_id(self) -> Dict:
        context_id = self.context.dump_id()
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
        return {
            'context_id': context_id,
            'topology_uuid': {'uuid': self.topology_uuid},
        }

Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    #@staticmethod
    #def main_pk_name() -> str:
    #    return 'topology_uuid'
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
    def dump(self) -> Dict:
        # pylint: disable=arguments-differ
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
        result = {'topology_id': self.dump_id()}
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
        # params: , devices=None, links=None
        #if devices:
        #    result['device_ids'] = [device.dump_id() for device in devices]
        #if links:
        #    result['link_ids'] = [link.dump_id() for link in links]
Lluis Gifre Renom's avatar
Lluis Gifre Renom committed
        return result