|
Packit Service |
293802 |
#
|
|
Packit Service |
dd31ba |
# Copyright (c) 2020-2021 Red Hat, Inc.
|
|
Packit Service |
293802 |
#
|
|
Packit Service |
293802 |
# This file is part of nmstate
|
|
Packit Service |
293802 |
#
|
|
Packit Service |
293802 |
# This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
293802 |
# it under the terms of the GNU Lesser General Public License as published by
|
|
Packit Service |
293802 |
# the Free Software Foundation, either version 2.1 of the License, or
|
|
Packit Service |
293802 |
# (at your option) any later version.
|
|
Packit Service |
293802 |
#
|
|
Packit Service |
293802 |
# This program is distributed in the hope that it will be useful,
|
|
Packit Service |
293802 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
293802 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
293802 |
# GNU Lesser General Public License for more details.
|
|
Packit Service |
293802 |
#
|
|
Packit Service |
293802 |
# You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
293802 |
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
293802 |
#
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
from nispor import NisporNetState
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
from libnmstate.plugin import NmstatePlugin
|
|
Packit Service |
293802 |
from libnmstate.schema import Route
|
|
Packit Service |
588ec5 |
from libnmstate.schema import RouteRule
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
from .base_iface import NisporPluginBaseIface
|
|
Packit Service |
293802 |
from .bond import NisporPluginBondIface
|
|
Packit Service |
293802 |
from .bridge import NisporPluginBridgeIface
|
|
Packit Service |
293802 |
from .dummy import NisporPluginDummyIface
|
|
Packit Service |
293802 |
from .ethernet import NisporPluginEthernetIface
|
|
Packit Service |
293802 |
from .macvlan import NisporPluginMacVlanIface
|
|
Packit Service |
588ec5 |
from .macvtap import NisporPluginMacVtapIface
|
|
Packit Service |
dd31ba |
from .veth import NisporPluginVethIface
|
|
Packit Service |
293802 |
from .vlan import NisporPluginVlanIface
|
|
Packit Service |
293802 |
from .vxlan import NisporPluginVxlanIface
|
|
Packit Service |
293802 |
from .route import nispor_route_state_to_nmstate
|
|
Packit Service |
588ec5 |
from .route_rule import nispor_route_rule_state_to_nmstate
|
|
Packit Service |
293802 |
from .vrf import NisporPluginVrfIface
|
|
Packit Service |
293802 |
from .ovs import NisporPluginOvsInternalIface
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
|
|
Packit Service |
5e62f7 |
_INFO_TYPE_RUNNING = "running"
|
|
Packit Service |
5e62f7 |
_INFO_TYPE_RUNNING_CONFIG = "running_config"
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
293802 |
class NisporPlugin(NmstatePlugin):
|
|
Packit Service |
293802 |
@property
|
|
Packit Service |
293802 |
def name(self):
|
|
Packit Service |
293802 |
return "nispor"
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
@property
|
|
Packit Service |
293802 |
def plugin_capabilities(self):
|
|
Packit Service |
293802 |
return [
|
|
Packit Service |
293802 |
NmstatePlugin.PLUGIN_CAPABILITY_IFACE,
|
|
Packit Service |
293802 |
NmstatePlugin.PLUGIN_CAPABILITY_ROUTE,
|
|
Packit Service |
588ec5 |
NmstatePlugin.PLUGIN_CAPABILITY_ROUTE_RULE,
|
|
Packit Service |
293802 |
]
|
|
Packit Service |
293802 |
|
|
Packit Service |
293802 |
@property
|
|
Packit Service |
293802 |
def priority(self):
|
|
Packit Service |
293802 |
# Let NetworkManagerPlugin take priority as nispor might be wrong on
|
|
Packit Service |
293802 |
# DHCP status and currently nispor does not support all interface types
|
|
Packit Service |
293802 |
# yet.
|
|
Packit Service |
293802 |
return NmstatePlugin.DEFAULT_PRIORITY - 1
|
|
Packit Service |
293802 |
|
|
Packit Service |
5e62f7 |
def _get_interfaces(self, info_type):
|
|
Packit Service |
293802 |
np_state = NisporNetState.retrieve()
|
|
Packit Service |
293802 |
ifaces = []
|
|
Packit Service |
5e62f7 |
config_only = info_type == _INFO_TYPE_RUNNING_CONFIG
|
|
Packit Service |
293802 |
for np_iface in np_state.ifaces.values():
|
|
Packit Service |
293802 |
iface_type = np_iface.type
|
|
Packit Service |
588ec5 |
if iface_type == "dummy":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginDummyIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "veth":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
dd31ba |
NisporPluginVethIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "ethernet":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginEthernetIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "bond":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginBondIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "vlan":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginVlanIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "vxlan":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginVxlanIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "mac_vlan":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginMacVlanIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "mac_vtap":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginMacVtapIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "bridge":
|
|
Packit Service |
293802 |
np_ports = []
|
|
Packit Service |
293802 |
for port_name in np_iface.ports:
|
|
Packit Service |
293802 |
if port_name in np_state.ifaces.keys():
|
|
Packit Service |
293802 |
np_ports.append(np_state.ifaces[port_name])
|
|
Packit Service |
293802 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginBridgeIface(np_iface, np_ports).to_dict(
|
|
Packit Service |
5e62f7 |
config_only
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
293802 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "vrf":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginVrfIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
588ec5 |
elif iface_type == "openv_switch":
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginOvsInternalIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
293802 |
else:
|
|
Packit Service |
5e62f7 |
ifaces.append(
|
|
Packit Service |
5e62f7 |
NisporPluginBaseIface(np_iface).to_dict(config_only)
|
|
Packit Service |
5e62f7 |
)
|
|
Packit Service |
293802 |
return ifaces
|
|
Packit Service |
293802 |
|
|
Packit Service |
5e62f7 |
def get_interfaces(self):
|
|
Packit Service |
5e62f7 |
return self._get_interfaces(_INFO_TYPE_RUNNING)
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
5e62f7 |
def get_running_config_interfaces(self):
|
|
Packit Service |
5e62f7 |
return self._get_interfaces(_INFO_TYPE_RUNNING_CONFIG)
|
|
Packit Service |
5e62f7 |
|
|
Packit Service |
293802 |
def get_routes(self):
|
|
Packit Service |
293802 |
np_state = NisporNetState.retrieve()
|
|
Packit Service |
293802 |
return {Route.RUNNING: nispor_route_state_to_nmstate(np_state.routes)}
|
|
Packit Service |
588ec5 |
|
|
Packit Service |
588ec5 |
def get_route_rules(self):
|
|
Packit Service |
588ec5 |
np_state = NisporNetState.retrieve()
|
|
Packit Service |
588ec5 |
return {
|
|
Packit Service |
588ec5 |
RouteRule.CONFIG: nispor_route_rule_state_to_nmstate(
|
|
Packit Service |
588ec5 |
np_state.route_rules
|
|
Packit Service |
588ec5 |
)
|
|
Packit Service |
588ec5 |
}
|