Lines 109-118
class Interfaces(dict):
|
Link Here
|
---|
|
109 |
device = Device.from_dict(values, self) |
109 |
device = Device.from_dict(values, self) |
110 |
self[device.name] = device |
110 |
self[device.name] = device |
111 |
|
111 |
|
112 |
# def finalize(self): |
|
|
113 |
# self.check_consistency() |
114 |
# return self.to_ucr() |
115 |
|
116 |
def to_ucr(self): |
112 |
def to_ucr(self): |
117 |
"""Returns a UCR representation of all interfaces""" |
113 |
"""Returns a UCR representation of all interfaces""" |
118 |
ucr.load() |
114 |
ucr.load() |
|
636 |
class Bond(Device): |
632 |
class Bond(Device): |
637 |
"""A network bonding interface""" |
633 |
"""A network bonding interface""" |
638 |
|
634 |
|
639 |
modes = { |
635 |
MODES = { |
640 |
'balance-rr': 0, |
636 |
'balance-rr': 0, |
641 |
'active-backup': 1, |
637 |
'active-backup': 1, |
642 |
'balance-xor': 2, |
638 |
'balance-xor': 2, |
|
645 |
'balance-tlb': 5, |
641 |
'balance-tlb': 5, |
646 |
'balance-alb': 6 |
642 |
'balance-alb': 6 |
647 |
} |
643 |
} |
648 |
modes_r = dict((v, k) for k, v in modes.iteritems()) |
644 |
MODES_R = dict((v, k) for k, v in MODES.iteritems()) |
649 |
|
645 |
|
650 |
def clear(self): |
646 |
def clear(self): |
651 |
super(Bond, self).clear() |
647 |
super(Bond, self).clear() |
|
696 |
self.check_unique_interface_usage() |
692 |
self.check_unique_interface_usage() |
697 |
|
693 |
|
698 |
def validate_bond_mode(self): |
694 |
def validate_bond_mode(self): |
699 |
if self.bond_mode is not None: |
695 |
if self.bond_mode is None: |
700 |
try: |
696 |
return |
701 |
bond_mode = int(self.bond_mode) |
697 |
if self.bond_mode in self.MODES: |
702 |
if bond_mode not in self.modes_r and bond_mode not in self.modes: |
698 |
return |
703 |
raise ValueError |
699 |
try: |
704 |
except ValueError: |
700 |
self.MODES_R[int(self.bond_mode)] |
705 |
raise DeviceError(_('Invalid bond-mode: %r') % (self.bond_mode), self.name) |
701 |
except (ValueError, KeyError): |
|
|
702 |
raise DeviceError(_('Invalid bond-mode: %r') % (self.bond_mode,), self.name) |
706 |
|
703 |
|
707 |
@property |
704 |
@property |
708 |
def subdevice_names(self): |
705 |
def subdevice_names(self): |
|
726 |
self.bond_mode = int(value) |
723 |
self.bond_mode = int(value) |
727 |
except ValueError: |
724 |
except ValueError: |
728 |
try: |
725 |
try: |
729 |
self.bond_mode = self.modes[value.strip()] |
726 |
self.bond_mode = self.MODES[value.strip()] |
730 |
except KeyError: |
727 |
except KeyError: |
731 |
pass # invalid mode |
728 |
pass # invalid mode |
732 |
elif name in ('bond-miimon', 'miimon'): |
729 |
elif name in ('bond-miimon', 'miimon'): |
|
744 |
'bond-slaves %s' % (' '.join(self.bond_slaves),), |
741 |
'bond-slaves %s' % (' '.join(self.bond_slaves),), |
745 |
'bond-mode %s' % (self.bond_mode,), |
742 |
'bond-mode %s' % (self.bond_mode,), |
746 |
] |
743 |
] |
747 |
if self.bond_mode == 1 and self.bond_primary: |
744 |
if self.bond_mode in (1, '1') and self.bond_primary: |
748 |
options.append('bond-primary %s' % (' '.join(self.bond_primary),)) |
745 |
options.append('bond-primary %s' % (' '.join(self.bond_primary),)) |
749 |
if self.miimon is not None: |
746 |
if self.miimon is not None: |
750 |
options.append('bond-miimon %s' % (self.miimon,)) |
747 |
options.append('bond-miimon %s' % (self.miimon,)) |
751 |
- |
|
|