Blame libnmstate/ifaces/vlan.py

Packit Service 0535c1
#
Packit Service 0535c1
# Copyright (c) 2020 Red Hat, Inc.
Packit Service 0535c1
#
Packit Service 0535c1
# This file is part of nmstate
Packit Service 0535c1
#
Packit Service 0535c1
# This program is free software: you can redistribute it and/or modify
Packit Service 0535c1
# it under the terms of the GNU Lesser General Public License as published by
Packit Service 0535c1
# the Free Software Foundation, either version 2.1 of the License, or
Packit Service 0535c1
# (at your option) any later version.
Packit Service 0535c1
#
Packit Service 0535c1
# This program is distributed in the hope that it will be useful,
Packit Service 0535c1
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 0535c1
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 0535c1
# GNU Lesser General Public License for more details.
Packit Service 0535c1
#
Packit Service 0535c1
# You should have received a copy of the GNU Lesser General Public License
Packit Service 0535c1
# along with this program. If not, see <https://www.gnu.org/licenses/>.
Packit Service 0535c1
#
Packit Service 0535c1
Packit Service 0535c1
from libnmstate.error import NmstateValueError
Packit Service 0535c1
from libnmstate.schema import VLAN
Packit Service 0535c1
Packit Service 0535c1
from .base_iface import BaseIface
Packit Service 0535c1
Packit Service 0535c1
Packit Service 0535c1
class VlanIface(BaseIface):
Packit Service 0535c1
    @property
Packit Service 0535c1
    def parent(self):
Packit Service 0535c1
        return self._vlan_config.get(VLAN.BASE_IFACE)
Packit Service 0535c1
Packit Service 0535c1
    @property
Packit Service 0535c1
    def need_parent(self):
Packit Service 0535c1
        return True
Packit Service 0535c1
Packit Service 0535c1
    @property
Packit Service 0535c1
    def _vlan_config(self):
Packit Service 0535c1
        return self.raw.get(VLAN.CONFIG_SUBTREE, {})
Packit Service 0535c1
Packit Service 0535c1
    @property
Packit Service 0535c1
    def is_virtual(self):
Packit Service 0535c1
        return True
Packit Service 0535c1
Packit Service 0535c1
    @property
Packit Service 0535c1
    def can_have_ip_when_enslaved(self):
Packit Service 0535c1
        return True
Packit Service 0535c1
Packit Service 0535c1
    def pre_edit_validation_and_cleanup(self):
Packit Service 0535c1
        self._validate_mandatory_properties()
Packit Service 0535c1
        super().pre_edit_validation_and_cleanup()
Packit Service 0535c1
Packit Service 0535c1
    def _validate_mandatory_properties(self):
Packit Service 0535c1
        if self.is_up:
Packit Service 0535c1
            for prop in (VLAN.ID, VLAN.BASE_IFACE):
Packit Service 0535c1
                if prop not in self._vlan_config:
Packit Service 0535c1
                    raise NmstateValueError(
Packit Service 0535c1
                        f"VLAN tunnel {self.name} has missing mandatory "
Packit Service 0535c1
                        f"property: {prop}"
Packit Service 0535c1
                    )