@@ -483,10 +483,100 @@ def appendPostDown(self, cmd):
483483 cmd = cmd .split ()
484484 self ._ensure_list (self ._ifAttributes , "post-down" , cmd )
485485
486+ def setBondMaster (self , master_adapter_name ):
487+ """Set bond-master reference on slave.
488+
489+ Args:
490+ master_adapter_name (str): name of master iface
491+ """
492+ self ._ifAttributes ['bond-master' ] = master_adapter_name
493+
494+ def setBondMode (self , mode ):
495+ """Set bond-mode.
496+
497+ Args:
498+ mode (str, int): mode of bonding
499+ """
500+ if isinstance (mode , str ):
501+ mode = mode .lower ().replace ('_' , '-' )
502+ self ._ifAttributes ['bond-mode' ] = mode
503+
504+ def setBondMiimon (self , miimon ):
505+ """Set bond-miimon parameter.
506+ Specifies the MII link monitoring frequency in milliseconds.
507+
508+ Args:
509+ miimon (int): miimon
510+ """
511+ self ._ifAttributes ['bond-miimon' ] = miimon
512+
513+ def setBondUpDelay (self , delay ):
514+ """Set bond-updelay parameter.
515+ Specifies the time, in milliseconds, to wait before enabling a slave after a link recovery has been detected.
516+ This option is only valid for the miimon link monitor. The updelay value should be a multiple of the miimon value.
517+
518+ Args:
519+ delay (int): delay in milliseconds
520+ """
521+ miimon = self ._ifAttributes .get ('bond-miimon' , 0 )
522+ if miimon and delay % miimon != 0 :
523+ raise ValueError ("Updelay should be multiple of miimon value" )
524+ self ._ifAttributes ['bond-updelay' ] = delay
525+
526+ def setBondDownDelay (self , delay ):
527+ """Set bond-downdelay parameter.
528+ Specifies the time, in milliseconds, to wait before disabling a slave after a link failure has been detected.
529+ This option is only valid for the miimon link monitor. The updelay value should be a multiple of the miimon value.
530+
531+ Args:
532+ delay (int): delay in milliseconds
533+ """
534+ miimon = self ._ifAttributes .get ('bond-miimon' , 0 )
535+ if miimon and delay % miimon != 0 :
536+ raise ValueError ("Downdelay should be multiple of miimon value" )
537+ self ._ifAttributes ['bond-downdelay' ] = delay
538+
539+ def setBondPrimary (self , primary_name ):
540+ """Set bond-primary parameter.
541+ A string specifying which slave is the primary device.
542+ The specified device will always be the active slave while it is available.
543+ Only when the primary is off-line will alternate devices be used.
544+ This is useful when one slave is preferred over another, e.g., when one slave has higher throughput than another.
545+ The primary option is only valid for active-backup (1) mode.
546+
547+ Args:
548+ primary_name (str): name of primary slave
549+ """
550+ self ._ifAttributes ['bond-primary' ] = primary_name
551+
552+ def setBondSlaves (self , slaves ):
553+ """Set bond-primary parameter.
554+ Slave interfaces names
555+
556+ Args:
557+ slaves (list, optional): names of slaves
558+ """
559+ if not isinstance (slaves , list ):
560+ slaves = [slaves ]
561+ self ._ifAttributes ['bond-slaves' ] = slaves
562+
486563 def setUnknown (self , key , val ):
487564 # type: (str, tp.Any)->None
488565 """Stores uncommon options as there are with no special handling
489566 It's impossible to know about all available options
567+ Format key with lower case. Replaces '_' with '-'
568+
569+ Args:
570+ key (str): the option name
571+ val (any): the option value
572+ """
573+ key = key .lower ().replace ('_' , '-' )
574+ self .setUnknownUnformatted (key , val )
575+
576+ def setUnknownUnformatted (self , key , val ):
577+ """Stores uncommon options as there are with no special handling
578+ It's impossible to know about all available options
579+ Stores key as is
490580 WARNING: duplicated directives are overwriten. TODO better
491581
492582 Args:
@@ -607,6 +697,13 @@ def set_options(self, options):
607697 'dns-search' : self .setDnsSearch ,
608698 'nameservers' : self .setNameservers ,
609699 'wpa-conf' : self .setWpaConf ,
700+ 'bond-master' : self .setBondMaster ,
701+ 'bond-slaves' : self .setBondSlaves ,
702+ 'bond-miimon' : self .setBondMiimon ,
703+ 'bond-mode' : self .setBondMode ,
704+ 'bond-updelay' : self .setBondUpDelay ,
705+ 'bond-downdelay' : self .setBondDownDelay ,
706+ 'bond-primary' : self .setBondPrimary
610707 } # type: tp.Dict[str, tp.Callable[[tp.Any], None]]
611708 for key , value in options .items ():
612709 if key in roseta :
0 commit comments