mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
some more ifquery support (for vxlan devices etc)
Ticket: CM-3784 Reviewed By: Testing Done: Tested ifquery check/running and sanity
This commit is contained in:
@@ -16,10 +16,17 @@ import time
|
|||||||
class bridge(moduleBase):
|
class bridge(moduleBase):
|
||||||
""" ifupdown2 addon module to configure linux bridges """
|
""" ifupdown2 addon module to configure linux bridges """
|
||||||
|
|
||||||
_modinfo = { 'mhelp' : 'bridge configuration module',
|
_modinfo = { 'mhelp' : 'Bridge configuration module. Supports both ' +
|
||||||
|
'vlan aware and non vlan aware bridges. For the vlan ' +
|
||||||
|
'aware bridge, the port specific attributes must be ' +
|
||||||
|
'specified under the port. And for vlan unaware bridge ' +
|
||||||
|
'port specific attributes must be specified under the ' +
|
||||||
|
'bridge.',
|
||||||
'attrs' : {
|
'attrs' : {
|
||||||
'bridge-vlan-aware' :
|
'bridge-vlan-aware' :
|
||||||
{'help' : 'bridge vlan aware',
|
{'help' : 'vlan aware bridge. Setting this ' +
|
||||||
|
'attribute to yes enables vlan filtering' +
|
||||||
|
' on the bridge',
|
||||||
'example' : ['bridge-vlan-aware yes/no']},
|
'example' : ['bridge-vlan-aware yes/no']},
|
||||||
'bridge-ports' :
|
'bridge-ports' :
|
||||||
{'help' : 'bridge ports',
|
{'help' : 'bridge ports',
|
||||||
@@ -123,15 +130,18 @@ class bridge(moduleBase):
|
|||||||
'example' : ['bridge-mcsqi 31']},
|
'example' : ['bridge-mcsqi 31']},
|
||||||
'bridge-mcqv4src' :
|
'bridge-mcqv4src' :
|
||||||
{ 'help' : 'set per VLAN v4 multicast querier source address',
|
{ 'help' : 'set per VLAN v4 multicast querier source address',
|
||||||
|
'compat' : True,
|
||||||
'example' : ['bridge-mcqv4src 100=172.16.100.1 101=172.16.101.1']},
|
'example' : ['bridge-mcqv4src 100=172.16.100.1 101=172.16.101.1']},
|
||||||
'bridge-portmcrouter' :
|
'bridge-portmcrouter' :
|
||||||
{ 'help' : 'set port multicast routers',
|
{ 'help' : 'set port multicast routers',
|
||||||
'default' : '1',
|
'default' : '1',
|
||||||
'example' : ['bridge-portmcrouter swp1=1 swp2=1']},
|
'example' : ['under the bridge: bridge-portmcrouter swp1=1 swp2=1',
|
||||||
|
'under the port: bridge-portmcrouter 1']},
|
||||||
'bridge-portmcfl' :
|
'bridge-portmcfl' :
|
||||||
{ 'help' : 'port multicast fast leave',
|
{ 'help' : 'port multicast fast leave.',
|
||||||
'default' : '0',
|
'default' : '0',
|
||||||
'example' : ['bridge-portmcfl swp1=0 swp2=0']},
|
'example' : ['under the bridge: bridge-portmcfl swp1=0 swp2=0',
|
||||||
|
'under the port: bridge-portmcfl 0']},
|
||||||
'bridge-waitport' :
|
'bridge-waitport' :
|
||||||
{ 'help' : 'wait for a max of time secs for the' +
|
{ 'help' : 'wait for a max of time secs for the' +
|
||||||
' specified ports to become available,' +
|
' specified ports to become available,' +
|
||||||
@@ -153,22 +163,31 @@ class bridge(moduleBase):
|
|||||||
'default' : '0',
|
'default' : '0',
|
||||||
'example' : ['bridge-maxwait 3']},
|
'example' : ['bridge-maxwait 3']},
|
||||||
'bridge-vids' :
|
'bridge-vids' :
|
||||||
{ 'help' : 'bridge vlans',
|
{ 'help' : 'bridge port vids. Can be specified ' +
|
||||||
|
'under the bridge or under the port. ' +
|
||||||
|
'If specified under the bridge the ports ' +
|
||||||
|
'inherit it unless overridden by a ' +
|
||||||
|
'bridge-vids attribuet under the port',
|
||||||
'example' : ['bridge-vids 4000']},
|
'example' : ['bridge-vids 4000']},
|
||||||
'bridge-pvid' :
|
'bridge-pvid' :
|
||||||
{ 'help' : 'bridge vlans',
|
{ 'help' : 'bridge port pvid. Must be specified under' +
|
||||||
|
' the bridge port',
|
||||||
'example' : ['bridge-pvid 1']},
|
'example' : ['bridge-pvid 1']},
|
||||||
'bridge-access' :
|
'bridge-access' :
|
||||||
{ 'help' : 'bridge access vlans',
|
{ 'help' : 'bridge port access vlan. Must be ' +
|
||||||
|
'specified under the bridge port',
|
||||||
'example' : ['bridge-access 300']},
|
'example' : ['bridge-access 300']},
|
||||||
'bridge-port-vids' :
|
'bridge-port-vids' :
|
||||||
{ 'help' : 'bridge vlans',
|
{ 'help' : 'bridge vlans',
|
||||||
|
'compat': True,
|
||||||
'example' : ['bridge-port-vids bond0=1-1000,1010-1020']},
|
'example' : ['bridge-port-vids bond0=1-1000,1010-1020']},
|
||||||
'bridge-port-pvids' :
|
'bridge-port-pvids' :
|
||||||
{ 'help' : 'bridge port vlans',
|
{ 'help' : 'bridge port vlans',
|
||||||
|
'compat': True,
|
||||||
'example' : ['bridge-port-pvids bond0=100 bond1=200']},
|
'example' : ['bridge-port-pvids bond0=100 bond1=200']},
|
||||||
'bridge-igmp-querier-src' :
|
'bridge-igmp-querier-src' :
|
||||||
{ 'help' : 'bridge igmp querier src',
|
{ 'help' : 'bridge igmp querier src. Must be ' +
|
||||||
|
'specified under the vlan interface',
|
||||||
'example' : ['bridge-igmp-querier-src 172.16.101.1']},
|
'example' : ['bridge-igmp-querier-src 172.16.101.1']},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -969,7 +988,8 @@ class bridge(moduleBase):
|
|||||||
# else:
|
# else:
|
||||||
# ifaceobjcurr.update_config_with_status('bridge-vids', attrval,
|
# ifaceobjcurr.update_config_with_status('bridge-vids', attrval,
|
||||||
# 1)
|
# 1)
|
||||||
ifaceobjcurr.update_config_with_status('bridge-vids', attrval, -1)
|
if attrval:
|
||||||
|
ifaceobjcurr.update_config_with_status('bridge-vids', attrval, -1)
|
||||||
|
|
||||||
def _query_check_bridge(self, ifaceobj, ifaceobjcurr,
|
def _query_check_bridge(self, ifaceobj, ifaceobjcurr,
|
||||||
ifaceobj_getfunc=None):
|
ifaceobj_getfunc=None):
|
||||||
@@ -1132,7 +1152,7 @@ class bridge(moduleBase):
|
|||||||
attr_name = 'bridge-pvid'
|
attr_name = 'bridge-pvid'
|
||||||
pvid = ifaceobj.get_attr_value_first(attr_name)
|
pvid = ifaceobj.get_attr_value_first(attr_name)
|
||||||
if pvid:
|
if pvid:
|
||||||
if running_pvid and runing_pvid == pvid:
|
if running_pvid and running_pvid == pvid:
|
||||||
ifaceobjcurr.update_config_with_status(attr_name,
|
ifaceobjcurr.update_config_with_status(attr_name,
|
||||||
running_pvid, 0)
|
running_pvid, 0)
|
||||||
else:
|
else:
|
||||||
|
@@ -126,11 +126,14 @@ class mstpctl(moduleBase):
|
|||||||
{ 'help' : 'port tree cost',
|
{ 'help' : 'port tree cost',
|
||||||
'required' : False},
|
'required' : False},
|
||||||
'mstpctl-portbpdufilter' :
|
'mstpctl-portbpdufilter' :
|
||||||
{ 'help' : 'enable/disable bpdu filter on a port',
|
{ 'help' : 'enable/disable bpdu filter on a port. ' +
|
||||||
|
'syntax varies when defined under a bridge ' +
|
||||||
|
'vs under a port',
|
||||||
'validvals' : ['yes', 'no'],
|
'validvals' : ['yes', 'no'],
|
||||||
'default' : 'no',
|
'default' : 'no',
|
||||||
'required' : False,
|
'required' : False,
|
||||||
'example' : ['mstpctl-portbpdufilter swp1=no swp2=no']},
|
'example' : ['under a bridge: mstpctl-portbpdufilter swp1=no swp2=no',
|
||||||
|
'under a port: mstpctl-portbpdufilter yes']},
|
||||||
}}
|
}}
|
||||||
|
|
||||||
_port_attrs_map = {'mstpctl-portpathcost' : 'portpathcost',
|
_port_attrs_map = {'mstpctl-portpathcost' : 'portpathcost',
|
||||||
|
@@ -4,6 +4,7 @@ from ifupdown.iface import *
|
|||||||
from ifupdownaddons.modulebase import moduleBase
|
from ifupdownaddons.modulebase import moduleBase
|
||||||
from ifupdownaddons.iproute2 import iproute2
|
from ifupdownaddons.iproute2 import iproute2
|
||||||
import logging
|
import logging
|
||||||
|
from sets import Set
|
||||||
|
|
||||||
class vxlan(moduleBase):
|
class vxlan(moduleBase):
|
||||||
_modinfo = {'mhelp' : 'vxlan module configures vxlan interfaces.',
|
_modinfo = {'mhelp' : 'vxlan module configures vxlan interfaces.',
|
||||||
@@ -50,16 +51,81 @@ class vxlan(moduleBase):
|
|||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log_warn(str(e))
|
self.log_warn(str(e))
|
||||||
|
|
||||||
|
def _query_check_n_update(self, ifaceobjcurr, attrname, attrval,
|
||||||
|
running_attrval):
|
||||||
|
if running_attrval and attrval == running_attrval:
|
||||||
|
ifaceobjcurr.update_config_with_status(attrname, attrval, 0)
|
||||||
|
else:
|
||||||
|
ifaceobjcurr.update_config_with_status(attrname, running_attrval, 1)
|
||||||
|
|
||||||
|
def _query_check_n_update_addresses(self, ifaceobjcurr, attrname,
|
||||||
|
addresses, running_addresses):
|
||||||
|
if addresses:
|
||||||
|
for a in addresses:
|
||||||
|
if a in running_addresses:
|
||||||
|
ifaceobjcurr.update_config_with_status(attrname, a, 0)
|
||||||
|
else:
|
||||||
|
ifaceobjcurr.update_config_with_status(attrname, a, 1)
|
||||||
|
running_addresses = Set(running_addresses).difference(
|
||||||
|
Set(addresses))
|
||||||
|
[ifaceobjcurr.update_config_with_status(attrname, a, 1)
|
||||||
|
for a in running_addresses]
|
||||||
|
|
||||||
def _query_check(self, ifaceobj, ifaceobjcurr):
|
def _query_check(self, ifaceobj, ifaceobjcurr):
|
||||||
if not self.ipcmd.link_exists(ifaceobj.name):
|
if not self.ipcmd.link_exists(ifaceobj.name):
|
||||||
ifaceobjcurr.status = ifaceStatus.NOTFOUND
|
ifaceobjcurr.status = ifaceStatus.NOTFOUND
|
||||||
return
|
return
|
||||||
|
|
||||||
# Update vxlan object
|
# Update vxlan object
|
||||||
|
vxlanattrs = self.ipcmd.get_vxlandev_attrs(ifaceobj.name)
|
||||||
|
if not vxlanattrs:
|
||||||
|
ifaceobjcurr.check_n_update_config_with_status_many(
|
||||||
|
self.get_mod_attrs(), -1)
|
||||||
|
return
|
||||||
|
self._query_check_n_update(ifaceobjcurr, 'vxlan-id',
|
||||||
|
ifaceobj.get_attr_value_first('vxlan-id'),
|
||||||
|
vxlanattrs.get('vxlanid'))
|
||||||
|
|
||||||
|
self._query_check_n_update(ifaceobjcurr, 'vxlan-local-tunnelip',
|
||||||
|
ifaceobj.get_attr_value_first('vxlan-local-tunnelip'),
|
||||||
|
vxlanattrs.get('local'))
|
||||||
|
|
||||||
|
self._query_check_n_update_addresses(ifaceobjcurr, 'vxlan-svcnodeip',
|
||||||
|
ifaceobj.get_attr_value('vxlan-svcnodeip'),
|
||||||
|
vxlanattrs.get('svcnode', []))
|
||||||
|
|
||||||
|
self._query_check_n_update_addresses(ifaceobjcurr, 'vxlan-peernodeip',
|
||||||
|
ifaceobj.get_attr_value('vxlan-peernodeip'),
|
||||||
|
vxlanattrs.get('peernode', []))
|
||||||
|
|
||||||
|
learning = ifaceobj.get_attr_value_first('vxlan-learning')
|
||||||
|
running_learning = vxlanattrs.get('learning')
|
||||||
|
if learning == running_learning:
|
||||||
|
ifaceobjcurr.update_config_with_status('vxlan-learning',
|
||||||
|
running_learning, 0)
|
||||||
|
else:
|
||||||
|
ifaceobjcurr.update_config_with_status('vxlan-learning',
|
||||||
|
running_learning, 1)
|
||||||
|
|
||||||
def _query_running(self, ifaceobjrunning):
|
def _query_running(self, ifaceobjrunning):
|
||||||
# Not implemented
|
vxlanattrs = self.ipcmd.get_vxlandev_attrs(ifaceobjrunning.name)
|
||||||
return
|
if not vxlanattrs:
|
||||||
|
return
|
||||||
|
ifaceobjrunning.update_config('vxlan-id', vxlanattrs.get('vxlanid'))
|
||||||
|
attrval = vxlanattrs.get('local')
|
||||||
|
if attrval:
|
||||||
|
ifaceobjrunning.update_config('vxlan-local-tunnelip', attrval)
|
||||||
|
attrval = vxlanattrs.get('svcnode')
|
||||||
|
if attrval:
|
||||||
|
[ifaceobjrunning.update_config('vxlan-svcnode', a)
|
||||||
|
for a in attrval]
|
||||||
|
attrval = vxlanattrs.get('peernode')
|
||||||
|
if attrval:
|
||||||
|
[ifaceobjrunning.update_config('vxlan-peernode', a)
|
||||||
|
for a in attrval]
|
||||||
|
attrval = vxlanattrs.get('learning')
|
||||||
|
if attrval and attrval == 'on':
|
||||||
|
ifaceobjrunning.update_config('vxlan-learning', 'on')
|
||||||
|
|
||||||
|
|
||||||
_run_ops = {'pre-up' : _up,
|
_run_ops = {'pre-up' : _up,
|
||||||
'post-down' : _down,
|
'post-down' : _down,
|
||||||
|
@@ -169,7 +169,8 @@ class networkInterfaces():
|
|||||||
attrval, lineno):
|
attrval, lineno):
|
||||||
newattrname = attrname.replace("_", "-")
|
newattrname = attrname.replace("_", "-")
|
||||||
try:
|
try:
|
||||||
if not self.callbacks.get('validateifaceattr')(newattrname, attrval):
|
if not self.callbacks.get('validateifaceattr')(newattrname,
|
||||||
|
attrval):
|
||||||
self._parse_error(self._currentfile, lineno,
|
self._parse_error(self._currentfile, lineno,
|
||||||
'iface %s: unsupported keyword (%s)'
|
'iface %s: unsupported keyword (%s)'
|
||||||
%(ifacename, attrname))
|
%(ifacename, attrname))
|
||||||
|
@@ -67,7 +67,8 @@ class iproute2(utilsBase):
|
|||||||
linkattrs['linkinfo'] = {'vlanid' : citems[i+2]}
|
linkattrs['linkinfo'] = {'vlanid' : citems[i+2]}
|
||||||
elif citems[i] == 'vxlan' and citems[i+1] == 'id':
|
elif citems[i] == 'vxlan' and citems[i+1] == 'id':
|
||||||
vattrs = {'vxlanid' : citems[i+2],
|
vattrs = {'vxlanid' : citems[i+2],
|
||||||
'svcnode' : []}
|
'svcnode' : [],
|
||||||
|
'learning': 'on'}
|
||||||
for j in range(i+2, len(citems)):
|
for j in range(i+2, len(citems)):
|
||||||
if citems[j] == 'local':
|
if citems[j] == 'local':
|
||||||
vattrs['local'] = citems[j+1]
|
vattrs['local'] = citems[j+1]
|
||||||
@@ -75,6 +76,8 @@ class iproute2(utilsBase):
|
|||||||
vattrs['svcnode'].append(citems[j+1])
|
vattrs['svcnode'].append(citems[j+1])
|
||||||
elif citems[j] == 'peernode':
|
elif citems[j] == 'peernode':
|
||||||
vattrs['peernode'].append(citems[j+1])
|
vattrs['peernode'].append(citems[j+1])
|
||||||
|
elif citems[j] == 'nolearning':
|
||||||
|
vattrs['learning'] = 'off'
|
||||||
linkattrs['linkinfo'] = vattrs
|
linkattrs['linkinfo'] = vattrs
|
||||||
break
|
break
|
||||||
#linkattrs['alias'] = self.read_file_oneline(
|
#linkattrs['alias'] = self.read_file_oneline(
|
||||||
@@ -471,6 +474,8 @@ class iproute2(utilsBase):
|
|||||||
args += ' peernode %s' %s
|
args += ' peernode %s' %s
|
||||||
if learning == 'on':
|
if learning == 'on':
|
||||||
args += ' learning'
|
args += ' learning'
|
||||||
|
else:
|
||||||
|
args += ' nolearning'
|
||||||
|
|
||||||
if self.link_exists(name):
|
if self.link_exists(name):
|
||||||
cmd = 'link set dev %s type vxlan ' %(name)
|
cmd = 'link set dev %s type vxlan ' %(name)
|
||||||
@@ -505,6 +510,9 @@ class iproute2(utilsBase):
|
|||||||
return (self._cache_get('link', [ifacename, 'linkinfo', 'link']),
|
return (self._cache_get('link', [ifacename, 'linkinfo', 'link']),
|
||||||
self._cache_get('link', [ifacename, 'linkinfo', 'vlanid']))
|
self._cache_get('link', [ifacename, 'linkinfo', 'vlanid']))
|
||||||
|
|
||||||
|
def get_vxlandev_attrs(self, ifacename):
|
||||||
|
return self._cache_get('link', [ifacename, 'linkinfo'])
|
||||||
|
|
||||||
def link_get_mtu(self, ifacename):
|
def link_get_mtu(self, ifacename):
|
||||||
return self._cache_get('link', [ifacename, 'mtu'])
|
return self._cache_get('link', [ifacename, 'mtu'])
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user