mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Ticket: CM-7360 Reviewed By: CCR-4721 Testing Done: smoke / testifreload / Tested on amd64 platform (by Sam) This patch replaces all calls to rtnetlink with python-nlmanager. Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
92 lines
3.8 KiB
Python
92 lines
3.8 KiB
Python
#!/usr/bin/python
|
|
#
|
|
# Copyright 2016 Cumulus Networks, Inc. All rights reserved.
|
|
# Author: Julien Fortin, julien@cumulusnetworks.com
|
|
#
|
|
|
|
try:
|
|
|
|
from ifupdownaddons.utilsbase import utilsBase
|
|
from nlmanager.nlmanager import NetlinkManager
|
|
import ifupdown.ifupdownflags as ifupdownflags
|
|
except ImportError, e:
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
|
class Netlink(utilsBase):
|
|
def __init__(self, *args, **kargs):
|
|
utilsBase.__init__(self, *args, **kargs)
|
|
self._nlmanager_api = NetlinkManager()
|
|
|
|
def get_iface_index(self, ifacename):
|
|
self.logger.info('netlink: %s: get iface index' % ifacename)
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
try:
|
|
return self._nlmanager_api.get_iface_index(ifacename)
|
|
except Exception as e:
|
|
raise Exception('netlink: %s: cannot get ifindex: %s'
|
|
% (ifacename, str(e)))
|
|
|
|
def link_add_vlan(self, vlanrawdevice, ifacename, vlanid):
|
|
self.logger.info('netlink: %s: creating vlan %s' % (vlanrawdevice, vlanid))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
ifindex = self.get_iface_index(vlanrawdevice)
|
|
try:
|
|
return self._nlmanager_api.link_add_vlan(ifindex, ifacename, vlanid)
|
|
except Exception as e:
|
|
raise Exception('netlink: %s: cannot create vlan %s: %s'
|
|
% (vlanrawdevice, vlanid, str(e)))
|
|
|
|
def link_add_macvlan(self, ifacename, macvlan_ifacename):
|
|
self.logger.info('netlink: %s: creating macvlan %s'
|
|
% (ifacename, macvlan_ifacename))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
ifindex = self.get_iface_index(ifacename)
|
|
try:
|
|
return self._nlmanager_api.link_add_macvlan(ifindex, macvlan_ifacename)
|
|
except Exception as e:
|
|
raise Exception('netlink: %s: cannot create macvlan %s: %s'
|
|
% (ifacename, macvlan_ifacename, str(e)))
|
|
|
|
def link_set_updown(self, ifacename, state):
|
|
self.logger.info('netlink: set link %s %s' % (ifacename, state))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
try:
|
|
return self._nlmanager_api.link_set_updown(ifacename, state)
|
|
except Exception as e:
|
|
raise Exception('netlink: cannot set link %s %s: %s'
|
|
% (ifacename, state, str(e)))
|
|
|
|
def link_set_protodown(self, ifacename, state):
|
|
self.logger.info('netlink: set link %s protodown %s' % (ifacename, state))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
try:
|
|
return self._nlmanager_api.link_set_protodown(ifacename, state)
|
|
except Exception as e:
|
|
raise Exception('netlink: cannot set link %s protodown %s: %s'
|
|
% (ifacename, state, str(e)))
|
|
|
|
def link_add_bridge_vlan(self, ifacename, vlanid):
|
|
self.logger.info('netlink: %s: creating bridge vlan %s'
|
|
% (ifacename, vlanid))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
ifindex = self.get_iface_index(ifacename)
|
|
try:
|
|
return self._nlmanager_api.link_add_bridge_vlan(ifindex, vlanid)
|
|
except Exception as e:
|
|
raise Exception('netlink: %s: cannot create bridge vlan %s: %s'
|
|
% (ifacename, vlanid, str(e)))
|
|
|
|
def link_del_bridge_vlan(self, ifacename, vlanid):
|
|
self.logger.info('netlink: %s: removing bridge vlan %s'
|
|
% (ifacename, vlanid))
|
|
if ifupdownflags.flags.DRYRUN: return
|
|
ifindex = self.get_iface_index(ifacename)
|
|
try:
|
|
return self._nlmanager_api.link_del_bridge_vlan(ifindex, vlanid)
|
|
except Exception as e:
|
|
raise Exception('netlink: %s: cannot remove bridge vlan %s: %s'
|
|
% (ifacename, vlanid, str(e)))
|
|
|
|
netlink = Netlink()
|