Add validvals to addons, to be used by iface/ifedit wrapper

Ticket: CM-8669
Reviewed By: Julien
Testing Done:

<DETAILED DESCRIPTION (REPLACE)>
This commit is contained in:
Daniel Walton 2016-05-31 13:12:21 -07:00 committed by Julien Fortin
parent 198ded6a35
commit c6370b563b
15 changed files with 140 additions and 32 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.pyc
*.swp
build

0
addons/__init__.py Normal file
View File

View File

@ -7,7 +7,7 @@
import os import os
try: try:
from ipaddr import IPNetwork from ipaddr import IPNetwork, IPv4Network, IPv6Network, IPv4Address, IPv6Address
from sets import Set from sets import Set
from ifupdown.iface import * from ifupdown.iface import *
from ifupdownaddons.modulebase import moduleBase from ifupdownaddons.modulebase import moduleBase
@ -28,34 +28,44 @@ class address(moduleBase):
'attrs': { 'attrs': {
'address' : 'address' :
{'help' : 'ipv4 or ipv6 addresses', {'help' : 'ipv4 or ipv6 addresses',
'validvals' : [IPv4Network, IPv6Network],
'multiline' : True,
'example' : ['address 10.0.12.3/24', 'example' : ['address 10.0.12.3/24',
'address 2000:1000:1000:1000:3::5/128']}, 'address 2000:1000:1000:1000:3::5/128']},
'netmask' : 'netmask' :
{'help': 'netmask', {'help': 'netmask',
'validvals' : [IPv4Address, ],
'example' : ['netmask 255.255.255.0'], 'example' : ['netmask 255.255.255.0'],
'compat' : True}, 'compat' : True},
'broadcast' : 'broadcast' :
{'help': 'broadcast address', {'help': 'broadcast address',
'validvals' : [IPv4Address, ],
'example' : ['broadcast 10.0.1.255']}, 'example' : ['broadcast 10.0.1.255']},
'scope' : 'scope' :
{'help': 'scope', {'help': 'scope',
'validvals' : ['universe', 'site', 'link', 'host', 'nowhere'],
'example' : ['scope host']}, 'example' : ['scope host']},
'preferred-lifetime' : 'preferred-lifetime' :
{'help': 'preferred lifetime', {'help': 'preferred lifetime',
'validrange' : ['0', '65535'],
'example' : ['preferred-lifetime forever', 'example' : ['preferred-lifetime forever',
'preferred-lifetime 10']}, 'preferred-lifetime 10']},
'gateway' : 'gateway' :
{'help': 'default gateway', {'help': 'default gateway',
'validvals' : [IPv4Address, IPv6Address],
'example' : ['gateway 255.255.255.0']}, 'example' : ['gateway 255.255.255.0']},
'mtu' : 'mtu' :
{ 'help': 'interface mtu', { 'help': 'interface mtu',
'validrange' : ['552', '9216'],
'example' : ['mtu 1600'], 'example' : ['mtu 1600'],
'default' : '1500'}, 'default' : '1500'},
'hwaddress' : 'hwaddress' :
{'help' : 'hw address', {'help' : 'hw address',
'validvals' : ['<mac>',],
'example': ['hwaddress 44:38:39:00:27:b8']}, 'example': ['hwaddress 44:38:39:00:27:b8']},
'alias' : 'alias' :
{ 'help': 'description/alias', { 'help': 'description/alias',
'validvals' : ['<text>',],
'example' : ['alias testnetwork']}, 'example' : ['alias testnetwork']},
'address-purge' : 'address-purge' :
{ 'help': 'purge existing addresses. By default ' + { 'help': 'purge existing addresses. By default ' +
@ -63,11 +73,13 @@ class address(moduleBase):
'purged to match persistant addresses in the ' + 'purged to match persistant addresses in the ' +
'interfaces file. Set this attribute to \'no\'' + 'interfaces file. Set this attribute to \'no\'' +
'if you want to preserve existing addresses', 'if you want to preserve existing addresses',
'validvals' : ['yes', 'no'],
'default' : 'yes', 'default' : 'yes',
'example' : ['address-purge yes/no']}, 'example' : ['address-purge yes/no']},
'clagd-vxlan-anycast-ip' : 'clagd-vxlan-anycast-ip' :
{ 'help' : 'Anycast local IP address for ' + { 'help' : 'Anycast local IP address for ' +
'dual connected VxLANs', 'dual connected VxLANs',
'validvals' : [IPv4Address, ],
'example' : ['clagd-vxlan-anycast-ip 36.0.0.11']}}} 'example' : ['clagd-vxlan-anycast-ip 36.0.0.11']}}}
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):

View File

@ -7,13 +7,12 @@
from ifupdown.iface import * 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 ifupdown.ifupdownconfig as ifupdownConfig import ifupdown.ifupdownconfig as ifupdownConfig
import ifupdown.statemanager as statemanager import ifupdown.statemanager as statemanager
from ifupdown.netlink import netlink from ifupdown.netlink import netlink
import ifupdown.ifupdownflags as ifupdownflags import ifupdown.ifupdownflags as ifupdownflags
from ipaddr import IPNetwork from ipaddr import IPNetwork, IPv4Network
import logging import logging
import os import os
import glob import glob
@ -27,7 +26,8 @@ class addressvirtual(moduleBase):
'attrs' : { 'attrs' : {
'address-virtual' : 'address-virtual' :
{ 'help' : 'bridge router virtual mac and ip', { 'help' : 'bridge router virtual mac and ip',
'example' : ['address-virtual 00:11:22:33:44:01 11.0.1.254/24 11.0.1.254/24']} 'validvals' : [('<mac>', IPv4Network), ],
'example' : ['address-virtual 00:11:22:33:44:01 11.0.1.1/24 11.0.1.2/24']}
}} }}

View File

@ -62,25 +62,30 @@ class bond(moduleBase):
'bond-min-links': 'bond-min-links':
{'help' : 'bond min links', {'help' : 'bond min links',
'default' : '0', 'default' : '0',
'validrange' : ['0', '255'],
'example' : ['bond-min-links 0']}, 'example' : ['bond-min-links 0']},
'bond-ad-sys-priority': 'bond-ad-sys-priority':
{'help' : '802.3ad system priority', {'help' : '802.3ad system priority',
'default' : '65535', 'default' : '65535',
'validrange' : ['0', '65535'],
'example' : ['bond-ad-sys-priority 65535'], 'example' : ['bond-ad-sys-priority 65535'],
'deprecated' : True, 'deprecated' : True,
'new-attribute' : 'bond-ad-actor-sys-prio'}, 'new-attribute' : 'bond-ad-actor-sys-prio'},
'bond-ad-actor-sys-prio': 'bond-ad-actor-sys-prio':
{'help' : '802.3ad system priority', {'help' : '802.3ad system priority',
'default' : '65535', 'default' : '65535',
'validrange' : ['0', '65535'],
'example' : ['bond-ad-actor-sys-prio 65535']}, 'example' : ['bond-ad-actor-sys-prio 65535']},
'bond-ad-sys-mac-addr': 'bond-ad-sys-mac-addr':
{'help' : '802.3ad system mac address', {'help' : '802.3ad system mac address',
'validvals' : ['<mac>',],
'default' : '00:00:00:00:00:00', 'default' : '00:00:00:00:00:00',
'example' : ['bond-ad-sys-mac-addr 00:00:00:00:00:00'], 'example' : ['bond-ad-sys-mac-addr 00:00:00:00:00:00'],
'deprecated' : True, 'deprecated' : True,
'new-attribute' : 'bond-ad-actor-system'}, 'new-attribute' : 'bond-ad-actor-system'},
'bond-ad-actor-system': 'bond-ad-actor-system':
{'help' : '802.3ad system mac address', {'help' : '802.3ad system mac address',
'validvals' : ['<mac>',],
'default' : '00:00:00:00:00:00', 'default' : '00:00:00:00:00:00',
'example' : ['bond-ad-actor-system 00:00:00:00:00:00'],}, 'example' : ['bond-ad-actor-system 00:00:00:00:00:00'],},
'bond-lacp-bypass-allow': 'bond-lacp-bypass-allow':
@ -91,6 +96,7 @@ class bond(moduleBase):
'bond-slaves' : 'bond-slaves' :
{'help' : 'bond slaves', {'help' : 'bond slaves',
'required' : True, 'required' : True,
'multivalue' : True,
'example' : ['bond-slaves swp1 swp2', 'example' : ['bond-slaves swp1 swp2',
'bond-slaves glob swp1-2', 'bond-slaves glob swp1-2',
'bond-slaves regex (swp[1|2)']}}} 'bond-slaves regex (swp[1|2)']}}}

View File

@ -35,9 +35,11 @@ class bridge(moduleBase):
{'help' : 'vlan aware bridge. Setting this ' + {'help' : 'vlan aware bridge. Setting this ' +
'attribute to yes enables vlan filtering' + 'attribute to yes enables vlan filtering' +
' on the bridge', ' on the bridge',
'validvals' : ['yes', 'no'],
'example' : ['bridge-vlan-aware yes/no']}, 'example' : ['bridge-vlan-aware yes/no']},
'bridge-ports' : 'bridge-ports' :
{'help' : 'bridge ports', {'help' : 'bridge ports',
'multivalue' : True,
'required' : True, 'required' : True,
'example' : ['bridge-ports swp1.100 swp2.100 swp3.100', 'example' : ['bridge-ports swp1.100 swp2.100 swp3.100',
'bridge-ports glob swp1-3.100', 'bridge-ports glob swp1-3.100',
@ -49,109 +51,137 @@ class bridge(moduleBase):
'default' : 'no'}, 'default' : 'no'},
'bridge-bridgeprio' : 'bridge-bridgeprio' :
{'help': 'bridge priority', {'help': 'bridge priority',
'validrange' : ['0', '65535'],
'example' : ['bridge-bridgeprio 32768'], 'example' : ['bridge-bridgeprio 32768'],
'default' : '32768'}, 'default' : '32768'},
'bridge-ageing' : 'bridge-ageing' :
{'help': 'bridge ageing', {'help': 'bridge ageing',
'validrange' : ['0', '65535'],
'example' : ['bridge-ageing 300'], 'example' : ['bridge-ageing 300'],
'default' : '300'}, 'default' : '300'},
'bridge-fd' : 'bridge-fd' :
{ 'help' : 'bridge forward delay', { 'help' : 'bridge forward delay',
'validrange' : ['0', '255'],
'example' : ['bridge-fd 15'], 'example' : ['bridge-fd 15'],
'default' : '15'}, 'default' : '15'},
'bridge-gcint' : 'bridge-gcint' :
# XXX: recheck values # XXX: recheck values
{ 'help' : 'bridge garbage collection interval in secs', { 'help' : 'bridge garbage collection interval in secs',
'validrange' : ['0', '255'],
'example' : ['bridge-gcint 4'], 'example' : ['bridge-gcint 4'],
'default' : '4', 'default' : '4',
'compat' : True, 'compat' : True,
'deprecated': True}, 'deprecated': True},
'bridge-hello' : 'bridge-hello' :
{ 'help' : 'bridge set hello time', { 'help' : 'bridge set hello time',
'validrange' : ['0', '255'],
'example' : ['bridge-hello 2'], 'example' : ['bridge-hello 2'],
'default' : '2'}, 'default' : '2'},
'bridge-maxage' : 'bridge-maxage' :
{ 'help' : 'bridge set maxage', { 'help' : 'bridge set maxage',
'validrange' : ['0', '255'],
'example' : ['bridge-maxage 20'], 'example' : ['bridge-maxage 20'],
'default' : '20'}, 'default' : '20'},
'bridge-pathcosts' : 'bridge-pathcosts' :
{ 'help' : 'bridge set port path costs', { 'help' : 'bridge set port path costs',
'example' : ['bridge-pathcosts swp1=100 swp2=100'], 'validrange' : ['0', '65535'],
'example' : ['under the bridge: bridge-pathcosts swp1=100 swp2=100',
'under the port (recommended): bridge-pathcosts 100'],
'default' : '100'}, 'default' : '100'},
'bridge-portprios' : 'bridge-portprios' :
{ 'help' : 'bridge port prios', { 'help' : 'bridge port prios',
'example' : ['bridge-portprios swp1=32 swp2=32'], 'validrange' : ['0', '65535'],
'example' : ['under the bridge: bridge-portprios swp1=32 swp2=32',
'under the port (recommended): bridge-portprios 32'],
'default' : '32'}, 'default' : '32'},
'bridge-mclmc' : 'bridge-mclmc' :
{ 'help' : 'set multicast last member count', { 'help' : 'set multicast last member count',
'validrange' : ['0', '255'],
'example' : ['bridge-mclmc 2'], 'example' : ['bridge-mclmc 2'],
'default' : '2'}, 'default' : '2'},
'bridge-mcrouter' : 'bridge-mcrouter' :
{ 'help' : 'set multicast router', { 'help' : 'set multicast router',
'validvals' : ['0', '1'],
'default' : '1', 'default' : '1',
'example' : ['bridge-mcrouter 1']}, 'example' : ['bridge-mcrouter 1']},
'bridge-mcsnoop' : 'bridge-mcsnoop' :
{ 'help' : 'set multicast snooping', { 'help' : 'set multicast snooping',
'validvals' : ['0', '1'],
'default' : '1', 'default' : '1',
'example' : ['bridge-mcsnoop 1']}, 'example' : ['bridge-mcsnoop 1']},
'bridge-mcsqc' : 'bridge-mcsqc' :
{ 'help' : 'set multicast startup query count', { 'help' : 'set multicast startup query count',
'validrange' : ['0', '255'],
'default' : '2', 'default' : '2',
'example' : ['bridge-mcsqc 2']}, 'example' : ['bridge-mcsqc 2']},
'bridge-mcqifaddr' : 'bridge-mcqifaddr' :
{ 'help' : 'set multicast query to use ifaddr', { 'help' : 'set multicast query to use ifaddr',
'validvals' : ['0', '1'],
'default' : '0', 'default' : '0',
'example' : ['bridge-mcqifaddr 0']}, 'example' : ['bridge-mcqifaddr 0']},
'bridge-mcquerier' : 'bridge-mcquerier' :
{ 'help' : 'set multicast querier', { 'help' : 'set multicast querier',
'validvals' : ['0', '1'],
'default' : '0', 'default' : '0',
'example' : ['bridge-mcquerier 0']}, 'example' : ['bridge-mcquerier 0']},
'bridge-hashel' : 'bridge-hashel' :
{ 'help' : 'set hash elasticity', { 'help' : 'set hash elasticity',
'validrange' : ['0', '4096'],
'default' : '4096', 'default' : '4096',
'example' : ['bridge-hashel 4096']}, 'example' : ['bridge-hashel 4096']},
'bridge-hashmax' : 'bridge-hashmax' :
{ 'help' : 'set hash max', { 'help' : 'set hash max',
'validrange' : ['0', '4096'],
'default' : '4096', 'default' : '4096',
'example' : ['bridge-hashmax 4096']}, 'example' : ['bridge-hashmax 4096']},
'bridge-mclmi' : 'bridge-mclmi' :
{ 'help' : 'set multicast last member interval (in secs)', { 'help' : 'set multicast last member interval (in secs)',
'validrange' : ['0', '255'],
'default' : '1', 'default' : '1',
'example' : ['bridge-mclmi 1']}, 'example' : ['bridge-mclmi 1']},
'bridge-mcmi' : 'bridge-mcmi' :
{ 'help' : 'set multicast membership interval (in secs)', { 'help' : 'set multicast membership interval (in secs)',
'validrange' : ['0', '255'],
'default' : '260', 'default' : '260',
'example' : ['bridge-mcmi 260']}, 'example' : ['bridge-mcmi 260']},
'bridge-mcqpi' : 'bridge-mcqpi' :
{ 'help' : 'set multicast querier interval (in secs)', { 'help' : 'set multicast querier interval (in secs)',
'validrange' : ['0', '255'],
'default' : '255', 'default' : '255',
'example' : ['bridge-mcqpi 255']}, 'example' : ['bridge-mcqpi 255']},
'bridge-mcqi' : 'bridge-mcqi' :
{ 'help' : 'set multicast query interval (in secs)', { 'help' : 'set multicast query interval (in secs)',
'validrange' : ['0', '255'],
'default' : '125', 'default' : '125',
'example' : ['bridge-mcqi 125']}, 'example' : ['bridge-mcqi 125']},
'bridge-mcqri' : 'bridge-mcqri' :
{ 'help' : 'set multicast query response interval (in secs)', { 'help' : 'set multicast query response interval (in secs)',
'validrange' : ['0', '255'],
'default' : '10', 'default' : '10',
'example' : ['bridge-mcqri 10']}, 'example' : ['bridge-mcqri 10']},
'bridge-mcsqi' : 'bridge-mcsqi' :
{ 'help' : 'set multicast startup query interval (in secs)', { 'help' : 'set multicast startup query interval (in secs)',
'validrange' : ['0', '255'],
'default' : '31', 'default' : '31',
'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',
'validvals' : ['<number-ipv4-list>', ],
'multivalue' : True,
'compat' : True, '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',
'validvals' : ['0', '1'],
'default' : '1', 'default' : '1',
'example' : ['under the bridge: bridge-portmcrouter swp1=1 swp2=1', 'example' : ['under the bridge: bridge-portmcrouter swp1=1 swp2=1',
'under the port: bridge-portmcrouter 1']}, 'under the port (recommended): bridge-portmcrouter 1']},
'bridge-portmcfl' : 'bridge-portmcfl' :
{ 'help' : 'port multicast fast leave.', { 'help' : 'port multicast fast leave.',
'validrange' : ['0', '65535'],
'default' : '0', 'default' : '0',
'example' : ['under the bridge: bridge-portmcfl swp1=0 swp2=0', 'example' : ['under the bridge: bridge-portmcfl swp1=0 swp2=0',
'under the port: bridge-portmcfl 0']}, 'under the port (recommended): 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,' +
@ -170,6 +200,7 @@ class bridge(moduleBase):
'forwarding status, doesn\'t allow factional ' + 'forwarding status, doesn\'t allow factional ' +
'part. If it is equal to 0 then no waiting' + 'part. If it is equal to 0 then no waiting' +
' is done', ' is done',
'validrange' : ['0', '255'],
'default' : '0', 'default' : '0',
'example' : ['bridge-maxwait 3']}, 'example' : ['bridge-maxwait 3']},
'bridge-vids' : 'bridge-vids' :
@ -177,22 +208,25 @@ class bridge(moduleBase):
'under the bridge or under the port. ' + 'under the bridge or under the port. ' +
'If specified under the bridge the ports ' + 'If specified under the bridge the ports ' +
'inherit it unless overridden by a ' + 'inherit it unless overridden by a ' +
'bridge-vids attribuet under the port', 'bridge-vids attribute under the port',
'example' : ['bridge-vids 4000', 'example' : ['bridge-vids 4000',
'bridge-vids 2000 2200-3000']}, 'bridge-vids 2000 2200-3000']},
'bridge-pvid' : 'bridge-pvid' :
{ 'help' : 'bridge port pvid. Must be specified under' + { 'help' : 'bridge port pvid. Must be specified under' +
' the bridge port', ' the bridge port',
'validrange' : ['0', '4096'],
'example' : ['bridge-pvid 1']}, 'example' : ['bridge-pvid 1']},
'bridge-access' : 'bridge-access' :
{ 'help' : 'bridge port access vlan. Must be ' + { 'help' : 'bridge port access vlan. Must be ' +
'specified under the bridge port', 'specified under the bridge port',
'validrange' : ['0', '4096'],
'example' : ['bridge-access 300']}, 'example' : ['bridge-access 300']},
'bridge-allow-untagged' : 'bridge-allow-untagged' :
{ 'help' : 'indicate if the bridge port accepts ' + { 'help' : 'indicate if the bridge port accepts ' +
'untagged packets or not. Must be ' + 'untagged packets or not. Must be ' +
'specified under the bridge port. ' + 'specified under the bridge port. ' +
'Default is \'yes\'', 'Default is \'yes\'',
'validvals' : ['yes', 'no'],
'example' : ['bridge-allow-untagged yes'], 'example' : ['bridge-allow-untagged yes'],
'default' : 'yes'}, 'default' : 'yes'},
'bridge-port-vids' : 'bridge-port-vids' :

View File

@ -8,6 +8,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
from ifupdownaddons.bridgeutils import brctl from ifupdownaddons.bridgeutils import brctl
from ipaddr import IPv4Address
import ifupdown.ifupdownflags as ifupdownflags import ifupdown.ifupdownflags as ifupdownflags
import logging import logging
@ -24,6 +25,7 @@ class bridgevlan(moduleBase):
'bridge-igmp-querier-src' : 'bridge-igmp-querier-src' :
{ 'help' : 'bridge igmp querier src. Must be ' + { 'help' : 'bridge igmp querier src. Must be ' +
'specified under the vlan interface', 'specified under the vlan interface',
'validvals' : [IPv4Address, ],
'example' : ['bridge-igmp-querier-src 172.16.101.1']}}} 'example' : ['bridge-igmp-querier-src 172.16.101.1']}}}
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):

View File

@ -25,6 +25,7 @@ class ethtool(moduleBase,utilsBase):
'attrs': { 'attrs': {
'link-speed' : 'link-speed' :
{'help' : 'set link speed', {'help' : 'set link speed',
'validvals' : ['100', '1000', '10000', '40000', '100000'],
'example' : ['link-speed 1000'], 'example' : ['link-speed 1000'],
'default' : 'varies by platform and port'}, 'default' : 'varies by platform and port'},
'link-duplex' : 'link-duplex' :

View File

@ -17,6 +17,7 @@ class link(moduleBase):
'attrs' : { 'attrs' : {
'link-type' : 'link-type' :
{'help' : 'type of link as in \'ip link\' command.', {'help' : 'type of link as in \'ip link\' command.',
'validvals' : ['dummy', 'veth'],
'example' : ['link-type <dummy|veth>']}}} 'example' : ['link-type <dummy|veth>']}}}
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):

View File

@ -30,6 +30,7 @@ class mstpctl(moduleBase):
'new-attribute': 'bridge-ports'}, 'new-attribute': 'bridge-ports'},
'mstpctl-stp' : 'mstpctl-stp' :
{'help': 'bridge stp yes/no', {'help': 'bridge stp yes/no',
'validvals' : ['yes', 'no'],
'compat' : True, 'compat' : True,
'default' : 'no', 'default' : 'no',
'deprecated': True, 'deprecated': True,
@ -42,47 +43,56 @@ class mstpctl(moduleBase):
'example' : ['mstpctl-treeprio 32768']}, 'example' : ['mstpctl-treeprio 32768']},
'mstpctl-ageing' : 'mstpctl-ageing' :
{'help': 'ageing time', {'help': 'ageing time',
'validrange' : ['0', '4096'],
'default' : '300', 'default' : '300',
'required' : False, 'required' : False,
'example' : ['mstpctl-ageing 300']}, 'example' : ['mstpctl-ageing 300']},
'mstpctl-maxage' : 'mstpctl-maxage' :
{ 'help' : 'max message age', { 'help' : 'max message age',
'validrange' : ['0', '255'],
'default' : '20', 'default' : '20',
'required' : False, 'required' : False,
'example' : ['mstpctl-maxage 20']}, 'example' : ['mstpctl-maxage 20']},
'mstpctl-fdelay' : 'mstpctl-fdelay' :
{ 'help' : 'set forwarding delay', { 'help' : 'set forwarding delay',
'validrange' : ['0', '255'],
'default' : '15', 'default' : '15',
'required' : False, 'required' : False,
'example' : ['mstpctl-fdelay 15']}, 'example' : ['mstpctl-fdelay 15']},
'mstpctl-maxhops' : 'mstpctl-maxhops' :
{ 'help' : 'bridge max hops', { 'help' : 'bridge max hops',
'validrange' : ['0', '255'],
'default' : '15', 'default' : '15',
'required' : False, 'required' : False,
'example' : ['mstpctl-maxhops 15']}, 'example' : ['mstpctl-maxhops 15']},
'mstpctl-txholdcount' : 'mstpctl-txholdcount' :
{ 'help' : 'bridge transmit holdcount', { 'help' : 'bridge transmit holdcount',
'validrange' : ['0', '255'],
'default' : '6', 'default' : '6',
'required' : False, 'required' : False,
'example' : ['mstpctl-txholdcount 6']}, 'example' : ['mstpctl-txholdcount 6']},
'mstpctl-forcevers' : 'mstpctl-forcevers' :
{ 'help' : 'bridge force stp version', { 'help' : 'bridge force stp version',
'validvals' : ['rstp', ],
'default' : 'rstp', 'default' : 'rstp',
'required' : False, 'required' : False,
'example' : ['mstpctl-forcevers rstp']}, 'example' : ['mstpctl-forcevers rstp']},
'mstpctl-portpathcost' : 'mstpctl-portpathcost' :
{ 'help' : 'bridge port path cost', { 'help' : 'bridge port path cost',
'validrange' : ['0', '65535'],
'default' : '0', 'default' : '0',
'jsonAttr' : 'adminExtPortCost', 'jsonAttr' : 'adminExtPortCost',
'required' : False, 'required' : False,
'example' : ['mstpctl-portpathcost swp1=0 swp2=1']}, 'example' : ['under the bridge: mstpctl-portpathcost swp1=0 swp2=1',
'under the port (recommended): mstpctl-portpathcost 0']},
'mstpctl-portp2p' : 'mstpctl-portp2p' :
{ 'help' : 'bridge port p2p detection mode', { 'help' : 'bridge port p2p detection mode',
'default' : 'auto', 'default' : 'auto',
'jsonAttr' : 'adminPointToPoint', 'jsonAttr' : 'adminPointToPoint',
'validvals' : ['yes', 'no', 'auto'], 'validvals' : ['yes', 'no', 'auto'],
'required' : False, 'required' : False,
'example' : ['mstpctl-portp2p swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-portp2p swp1=yes swp2=no',
'under the port (recommended): mstpctl-portp2p yes']},
'mstpctl-portrestrrole' : 'mstpctl-portrestrrole' :
{ 'help' : { 'help' :
'enable/disable port ability to take root role of the port', 'enable/disable port ability to take root role of the port',
@ -90,7 +100,8 @@ class mstpctl(moduleBase):
'jsonAttr' : 'restrictedRole', 'jsonAttr' : 'restrictedRole',
'validvals' : ['yes', 'no'], 'validvals' : ['yes', 'no'],
'required' : False, 'required' : False,
'example' : ['mstpctl-portrestrrole swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-portrestrrole swp1=yes swp2=no',
'under the port (recommended): mstpctl-portrestrrole yes']},
'mstpctl-portrestrtcn' : 'mstpctl-portrestrtcn' :
{ 'help' : { 'help' :
'enable/disable port ability to propagate received topology change notification of the port', 'enable/disable port ability to propagate received topology change notification of the port',
@ -98,7 +109,8 @@ class mstpctl(moduleBase):
'jsonAttr' : 'restrictedTcn', 'jsonAttr' : 'restrictedTcn',
'validvals' : ['yes', 'no'], 'validvals' : ['yes', 'no'],
'required' : False, 'required' : False,
'example' : ['mstpctl-portrestrtcn swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-portrestrtcn swp1=yes swp2=no',
'under the port (recommended): mstpctl-portrestrtcn yes']},
'mstpctl-bpduguard' : 'mstpctl-bpduguard' :
{ 'help' : { 'help' :
'enable/disable bpduguard', 'enable/disable bpduguard',
@ -106,16 +118,19 @@ class mstpctl(moduleBase):
'jsonAttr' : 'bpduGuardPort', 'jsonAttr' : 'bpduGuardPort',
'validvals' : ['yes', 'no'], 'validvals' : ['yes', 'no'],
'required' : False, 'required' : False,
'example' : ['mstpctl-bpduguard swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-bpduguard swp1=yes swp2=no',
'under the port (recommended): mstpctl-bpduguard yes']},
'mstpctl-treeportprio' : 'mstpctl-treeportprio' :
{ 'help' : { 'help' :
'port priority for MSTI instance', 'port priority for MSTI instance',
'default' : '128', 'default' : '128',
'validrange' : ['0', '240'], 'validrange' : ['0', '240'],
'required' : False, 'required' : False,
'example' : ['mstpctl-treeportprio swp1=128 swp2=128']}, 'example' : ['under the bridge: mstpctl-treeportprio swp1=128 swp2=128',
'under the port (recommended): mstpctl-treeportprio 128']},
'mstpctl-hello' : 'mstpctl-hello' :
{ 'help' : 'set hello time', { 'help' : 'set hello time',
'validrange' : ['0', '255'],
'default' : '2', 'default' : '2',
'required' : False, 'required' : False,
'example' : ['mstpctl-hello 2']}, 'example' : ['mstpctl-hello 2']},
@ -125,23 +140,27 @@ class mstpctl(moduleBase):
'default' : 'no', 'default' : 'no',
'jsonAttr' : 'networkPort', 'jsonAttr' : 'networkPort',
'required' : False, 'required' : False,
'example' : ['mstpctl-portnetwork swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-portnetwork swp1=yes swp2=no',
'under the port (recommended): mstpctl-portnetwork yes']},
'mstpctl-portadminedge' : 'mstpctl-portadminedge' :
{ 'help' : 'enable/disable initial edge state of the port', { 'help' : 'enable/disable initial edge state of the port',
'validvals' : ['yes', 'no'], 'validvals' : ['yes', 'no'],
'default' : 'no', 'default' : 'no',
'jsonAttr' : 'adminEdgePort', 'jsonAttr' : 'adminEdgePort',
'required' : False, 'required' : False,
'example' : ['mstpctl-portadminedge swp1=no swp2=no']}, 'example' : ['under the bridge: mstpctl-portadminedge swp1=yes swp2=no',
'under the port (recommended): mstpctl-portadminedge yes']},
'mstpctl-portautoedge' : 'mstpctl-portautoedge' :
{ 'help' : 'enable/disable auto transition to/from edge state of the port', { 'help' : 'enable/disable auto transition to/from edge state of the port',
'validvals' : ['yes', 'no'], 'validvals' : ['yes', 'no'],
'default' : 'yes', 'default' : 'yes',
'jsonAttr' : 'autoEdgePort', 'jsonAttr' : 'autoEdgePort',
'required' : False, 'required' : False,
'example' : ['mstpctl-portautoedge swp1=yes swp2=yes']}, 'example' : ['under the bridge: mstpctl-portautoedge swp1=yes swp2=no',
'under the port (recommended): mstpctl-portautoedge yes']},
'mstpctl-treeportcost' : 'mstpctl-treeportcost' :
{ 'help' : 'port tree cost', { 'help' : 'port tree cost',
'validrange' : ['0', '255'],
'required' : False}, 'required' : False},
'mstpctl-portbpdufilter' : 'mstpctl-portbpdufilter' :
{ 'help' : 'enable/disable bpdu filter on a port. ' + { 'help' : 'enable/disable bpdu filter on a port. ' +

View File

@ -15,17 +15,23 @@ class usercmds(ifupdownaddons.modulebase.moduleBase):
_modinfo = {'mhelp' : 'user commands for interfaces', _modinfo = {'mhelp' : 'user commands for interfaces',
'attrs' : { 'attrs' : {
'pre-up' : 'pre-up' :
{'help' : 'run command before bringing the interface up'}, {'help' : 'run command before bringing the interface up',
'multiline' : True},
'up' : 'up' :
{'help' : 'run command at interface bring up'}, {'help' : 'run command at interface bring up',
'multiline' : True},
'post-up' : 'post-up' :
{'help' : 'run command after interface bring up'}, {'help' : 'run command after interface bring up',
'multiline' : True},
'pre-down' : 'pre-down' :
{'help' : 'run command before bringing the interface down'}, {'help' : 'run command before bringing the interface down',
'multiline' : True},
'down' : 'down' :
{'help' : 'run command at interface down'}, {'help' : 'run command at interface down',
'multiline' : True},
'post-down' : 'post-down' :
{'help' : 'run command after bringing interface down'}}} {'help' : 'run command after bringing interface down',
'multiline' : True}}}
def _run_command(self, ifaceobj, op): def _run_command(self, ifaceobj, op):
cmd_list = ifaceobj.get_attr_value(op) cmd_list = ifaceobj.get_attr_value(op)

View File

@ -24,9 +24,11 @@ class vlan(moduleBase):
'attributes', 'attributes',
'attrs' : { 'attrs' : {
'vlan-raw-device' : 'vlan-raw-device' :
{'help' : 'vlan raw device'}, {'help' : 'vlan raw device',
'validvals' : ['<interface>' ,]},
'vlan-id' : 'vlan-id' :
{'help' : 'vlan id'}}} {'help' : 'vlan id',
'validrange' : ['0', '4096']}}}
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):

View File

@ -27,12 +27,15 @@ class vrrpd(moduleBase):
'attrs': { 'attrs': {
'vrrp-id' : 'vrrp-id' :
{'help' : 'vrrp instance id', {'help' : 'vrrp instance id',
'validrange' : ['1', '4096'],
'example' : ['vrrp-id 1']}, 'example' : ['vrrp-id 1']},
'vrrp-priority' : 'vrrp-priority' :
{'help': 'set vrrp priority', {'help': 'set vrrp priority',
'validrange' : ['0', '255'],
'example' : ['vrrp-priority 20']}, 'example' : ['vrrp-priority 20']},
'vrrp-virtual-ip' : 'vrrp-virtual-ip' :
{'help': 'set vrrp virtual ip', {'help': 'set vrrp virtual ip',
'validvals' : [IPv4Address, ],
'example' : ['vrrp-virtual-ip 10.0.1.254']}}} 'example' : ['vrrp-virtual-ip 10.0.1.254']}}}
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):

View File

@ -5,6 +5,7 @@ from ifupdownaddons.modulebase import moduleBase
from ifupdownaddons.iproute2 import iproute2 from ifupdownaddons.iproute2 import iproute2
from ifupdownaddons.systemutils import systemUtils from ifupdownaddons.systemutils import systemUtils
from ifupdown.netlink import netlink from ifupdown.netlink import netlink
from ipaddr import IPv4Address
import ifupdown.ifupdownflags as ifupdownflags import ifupdown.ifupdownflags as ifupdownflags
import logging import logging
import os import os
@ -15,23 +16,29 @@ class vxlan(moduleBase):
'attrs' : { 'attrs' : {
'vxlan-id' : 'vxlan-id' :
{'help' : 'vxlan id', {'help' : 'vxlan id',
'validrange' : ['0', '4096'],
'required' : True, 'required' : True,
'example': ['vxlan-id 100']}, 'example': ['vxlan-id 100']},
'vxlan-local-tunnelip' : 'vxlan-local-tunnelip' :
{'help' : 'vxlan local tunnel ip', {'help' : 'vxlan local tunnel ip',
'validvals' : [IPv4Address, ],
'example': ['vxlan-local-tunnelip 172.16.20.103']}, 'example': ['vxlan-local-tunnelip 172.16.20.103']},
'vxlan-svcnodeip' : 'vxlan-svcnodeip' :
{'help' : 'vxlan id', {'help' : 'vxlan id',
'validvals' : [IPv4Address, ],
'example': ['vxlan-svcnodeip 172.16.22.125']}, 'example': ['vxlan-svcnodeip 172.16.22.125']},
'vxlan-remoteip' : 'vxlan-remoteip' :
{'help' : 'vxlan remote ip', {'help' : 'vxlan remote ip',
'validvals' : [IPv4Address, ],
'example': ['vxlan-remoteip 172.16.22.127']}, 'example': ['vxlan-remoteip 172.16.22.127']},
'vxlan-learning' : 'vxlan-learning' :
{'help' : 'vxlan learning on/off', {'help' : 'vxlan learning on/off',
'validvals' : ['on', 'off'],
'example': ['vxlan-learning off'], 'example': ['vxlan-learning off'],
'default': 'on'}, 'default': 'on'},
'vxlan-ageing' : 'vxlan-ageing' :
{'help' : 'vxlan aging timer', {'help' : 'vxlan aging timer',
'validrange' : ['0', '4096'],
'example': ['vxlan-ageing 300'], 'example': ['vxlan-ageing 300'],
'default': '300'}, 'default': '300'},
}} }}

View File

@ -29,6 +29,12 @@ class moduleBase(object):
# here so that all modules can use it # here so that all modules can use it
self.vrf_exec_cmd_prefix = policymanager.policymanager_api.get_module_globals('vrf', attr='vrf-exec-cmd-prefix') self.vrf_exec_cmd_prefix = policymanager.policymanager_api.get_module_globals('vrf', attr='vrf-exec-cmd-prefix')
# explanations are shown in parse_glob
self.glob_regexs = [re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\]([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)"),
re.compile(r"([A-Za-z0-9\-]+[A-Za-z])(\d+)\-(\d+)(.*)"),
re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)")]
def log_warn(self, str, ifaceobj=None): def log_warn(self, str, ifaceobj=None):
""" log a warning if err str is not one of which we should ignore """ """ log a warning if err str is not one of which we should ignore """
if not self.ignore_error(str): if not self.ignore_error(str):
@ -93,15 +99,21 @@ class moduleBase(object):
raise Exception('%s: error searching regex \'%s\' in %s (%s)' raise Exception('%s: error searching regex \'%s\' in %s (%s)'
%(ifacename, expr, ifacename, str(e))) %(ifacename, expr, ifacename, str(e)))
def ifname_is_glob(self, ifname):
"""
Used by iface where ifname could be swp7 or swp[1-10].300
"""
if (self.glob_regexs[0].match(ifname) or
self.glob_regexs[1].match(ifname) or
self.glob_regexs[2].match(ifname)):
return True
return False
def parse_glob(self, ifacename, expr): def parse_glob(self, ifacename, expr):
errmsg = ('error parsing glob expression \'%s\'' %expr + errmsg = ('error parsing glob expression \'%s\'' %expr +
' (supported glob syntax: swp1-10.300 or swp[1-10].300' + ' (supported glob syntax: swp1-10.300 or swp[1-10].300' +
' or swp[1-10]sub[0-4].300') ' or swp[1-10]sub[0-4].300')
regexs = self.glob_regexs
# explanations are shown below in each if clause
regexs = [re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\]([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)"),
re.compile(r"([A-Za-z0-9\-]+[A-Za-z])(\d+)\-(\d+)(.*)"),
re.compile(r"([A-Za-z0-9\-]+)\[(\d+)\-(\d+)\](.*)")]
if regexs[0].match(expr): if regexs[0].match(expr):
# the first regex checks for exactly two levels of ranges defined only with square brackets # the first regex checks for exactly two levels of ranges defined only with square brackets