|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
# Copyright (c) 2020 Red Hat, Inc.
|
|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
# This file is part of nmstate
|
|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
# This program is free software: you can redistribute it and/or modify
|
|
Packit |
b9ca78 |
# it under the terms of the GNU Lesser General Public License as published by
|
|
Packit |
b9ca78 |
# the Free Software Foundation, either version 2.1 of the License, or
|
|
Packit |
b9ca78 |
# (at your option) any later version.
|
|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
# This program is distributed in the hope that it will be useful,
|
|
Packit |
b9ca78 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
b9ca78 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
b9ca78 |
# GNU Lesser General Public License for more details.
|
|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
# You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
b9ca78 |
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
b9ca78 |
#
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
from operator import itemgetter
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
from libnmstate.schema import Team
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
from .base_iface import BaseIface
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
class TeamIface(BaseIface):
|
|
Packit |
b9ca78 |
@property
|
|
Packit |
b9ca78 |
def slaves(self):
|
|
Packit |
b9ca78 |
ports = self.raw.get(Team.CONFIG_SUBTREE, {}).get(
|
|
Packit |
b9ca78 |
Team.PORT_SUBTREE, []
|
|
Packit |
b9ca78 |
)
|
|
Packit |
b9ca78 |
return [p[Team.Port.NAME] for p in ports]
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
@property
|
|
Packit |
b9ca78 |
def is_master(self):
|
|
Packit |
b9ca78 |
return True
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
@property
|
|
Packit |
b9ca78 |
def is_virtual(self):
|
|
Packit |
b9ca78 |
return True
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
def sort_slaves(self):
|
|
Packit |
b9ca78 |
if self.slaves:
|
|
Packit |
b9ca78 |
self.raw[Team.CONFIG_SUBTREE][Team.PORT_SUBTREE].sort(
|
|
Packit |
b9ca78 |
key=itemgetter(Team.Port.NAME)
|
|
Packit |
b9ca78 |
)
|
|
Packit |
b9ca78 |
|
|
Packit |
b9ca78 |
def remove_slave(self, slave_name):
|
|
Packit |
b9ca78 |
if self.slaves:
|
|
Packit |
b9ca78 |
slaves_config = self.raw[Team.CONFIG_SUBTREE][Team.PORT_SUBTREE]
|
|
Packit |
b9ca78 |
self.raw[Team.CONFIG_SUBTREE][Team.PORT_SUBTREE] = [
|
|
Packit |
b9ca78 |
s for s in slaves_config if s[Team.Port.NAME] != slave_name
|
|
Packit |
b9ca78 |
]
|
|
Packit |
b9ca78 |
self.sort_slaves()
|