Lines 200-205
class Interfaces(dict):
|
Link Here
|
---|
|
200 |
# set device order |
200 |
# set device order |
201 |
device.order = i |
201 |
device.order = i |
202 |
i += 1 |
202 |
i += 1 |
|
|
203 |
device.start = True |
203 |
|
204 |
|
204 |
devices = dict((device, (subdevs - leave)) for device, subdevs in devices.iteritems() if device not in leave) |
205 |
devices = dict((device, (subdevs - leave)) for device, subdevs in devices.iteritems() if device not in leave) |
205 |
|
206 |
|
Lines 290-299
class Device(object):
|
Link Here
|
---|
|
290 |
self._remove_old_fallback_variables() |
291 |
self._remove_old_fallback_variables() |
291 |
|
292 |
|
292 |
self.order = None |
293 |
self.order = None |
293 |
self.start = True |
294 |
self.start = False |
294 |
|
295 |
self.type = 'manual' |
295 |
if self.ip4dynamic: |
|
|
296 |
self.type = 'dhcp' |
297 |
|
296 |
|
298 |
def _remove_old_fallback_variables(self): |
297 |
def _remove_old_fallback_variables(self): |
299 |
# removes deprecated UCR variables from UCS <= 3.1-1... can be removed in future |
298 |
# removes deprecated UCR variables from UCS <= 3.1-1... can be removed in future |
Lines 304-309
class Device(object):
|
Link Here
|
---|
|
304 |
self.validate_name() |
303 |
self.validate_name() |
305 |
self.validate_ip4() |
304 |
self.validate_ip4() |
306 |
self.validate_ip6() |
305 |
self.validate_ip6() |
|
|
306 |
if self.ip4dynamic: |
307 |
self.type = 'dhcp' |
308 |
elif self.ipv4 or self.ipv6: |
309 |
self.type = 'static' |
307 |
|
310 |
|
308 |
def validate_name(self): |
311 |
def validate_name(self): |
309 |
""" |
312 |
""" |
Lines 414-422
class Device(object):
|
Link Here
|
---|
|
414 |
|
417 |
|
415 |
self.start = ucr.is_true(value=vals.pop('interfaces/%s/start' % (name), None)) |
418 |
self.start = ucr.is_true(value=vals.pop('interfaces/%s/start' % (name), None)) |
416 |
|
419 |
|
417 |
type_ = vals.pop('interfaces/%s/type' % (name), None) |
420 |
self.type = vals.pop('interfaces/%s/type' % (name), None) |
418 |
if type_ is not None: |
|
|
419 |
self.type = type_ |
420 |
|
421 |
|
421 |
order = vals.pop('interfaces/%s/order' % (name), "") |
422 |
order = vals.pop('interfaces/%s/order' % (name), "") |
422 |
if order.isdigit(): |
423 |
if order.isdigit(): |
Lines 428-438
class Device(object):
|
Link Here
|
---|
|
428 |
address, netmask = vals.pop('interfaces/%s/address' % (name), ''), vals.pop('interfaces/%s/netmask' % (name), '24') |
429 |
address, netmask = vals.pop('interfaces/%s/address' % (name), ''), vals.pop('interfaces/%s/netmask' % (name), '24') |
429 |
if address: |
430 |
if address: |
430 |
self.ip4.append((address, netmask)) |
431 |
self.ip4.append((address, netmask)) |
431 |
# a link local address indicates that this interface is DHCP |
432 |
# a link-local address probably from a failed DHCP |
432 |
if address.startswith('169.254.'): |
433 |
if address.startswith('169.254.'): |
433 |
self.type = 'dhcp' |
434 |
self.type = 'dhcp' |
|
|
435 |
# FIXME PMH: the above look wrong: a manually configured lla is |
436 |
# still valid and may be preferred to an ever changing address when |
437 |
# dhcp fails. |
434 |
|
438 |
|
435 |
self.ip4dynamic = 'dhcp' == self.type |
439 |
self.ip4dynamic = self.type in ('dhcp', 'dynamic') |
436 |
self.ip6dynamic = ucr.is_true(value=vals.pop('interfaces/%s/ipv6/acceptRA' % (name), None)) |
440 |
self.ip6dynamic = ucr.is_true(value=vals.pop('interfaces/%s/ipv6/acceptRA' % (name), None)) |
437 |
|
441 |
|
438 |
for key in vals.copy(): |
442 |
for key in vals.copy(): |
Lines 456-462
class Device(object):
|
Link Here
|
---|
|
456 |
self.options.sort() |
460 |
self.options.sort() |
457 |
self._leftover.sort() |
461 |
self._leftover.sort() |
458 |
|
462 |
|
459 |
def to_ucr(self): |
463 |
def to_ucr(self, extra_options=None): |
460 |
"""Returns a dict of UCR variables to set or unset. |
464 |
"""Returns a dict of UCR variables to set or unset. |
461 |
Values which are None should be unset. |
465 |
Values which are None should be unset. |
462 |
""" |
466 |
""" |
Lines 474-481
class Device(object):
|
Link Here
|
---|
|
474 |
if self.start is not None: |
478 |
if self.start is not None: |
475 |
vals['interfaces/%s/start' % (name)] = str(bool(self.start)).lower() |
479 |
vals['interfaces/%s/start' % (name)] = str(bool(self.start)).lower() |
476 |
|
480 |
|
477 |
if isinstance(self.type, str): |
481 |
if isinstance(self.type, basestring): |
478 |
if self.type not in ('static', 'manual', 'dhcp', 'appliance-mode-temporary'): |
482 |
if self.type not in ('static', 'manual', 'dhcp', 'dynamic', 'appliance-mode-temporary'): |
479 |
MODULE.warn('Unknown interfaces/%s/type: %r' % (self.name, self.type)) |
483 |
MODULE.warn('Unknown interfaces/%s/type: %r' % (self.name, self.type)) |
480 |
vals['interfaces/%s/type' % (name)] = self.type |
484 |
vals['interfaces/%s/type' % (name)] = self.type |
481 |
|
485 |
|
Lines 506-512
class Device(object):
|
Link Here
|
---|
|
506 |
|
510 |
|
507 |
vals['interfaces/%s/ipv6/acceptRA' % (name)] = str(bool(self.ip6dynamic)).lower() |
511 |
vals['interfaces/%s/ipv6/acceptRA' % (name)] = str(bool(self.ip6dynamic)).lower() |
508 |
|
512 |
|
509 |
for i, option in enumerate(self.options): |
513 |
for i, option in enumerate(self.options + (extra_options or [])): |
510 |
vals['interfaces/%s/options/%d' % (name, i)] = option |
514 |
vals['interfaces/%s/options/%d' % (name, i)] = option |
511 |
|
515 |
|
512 |
return vals |
516 |
return vals |
|
606 |
super(VLAN, self).validate_name() |
610 |
super(VLAN, self).validate_name() |
607 |
if not '.' in self.name: |
611 |
if not '.' in self.name: |
608 |
raise DeviceError(_('Invalid device name: %r') % (self.name,)) |
612 |
raise DeviceError(_('Invalid device name: %r') % (self.name,)) |
609 |
if not (1 <= self.vlan_id <= 4096): |
613 |
if not (1 <= self.vlan_id <= 4095): |
610 |
raise DeviceError(_('Invalid VLAN ID. Must be between 1 and 4096.'), self.name) |
614 |
raise DeviceError(_('Invalid VLAN ID. Must be between 1 and 4095.'), self.name) |
611 |
|
615 |
|
612 |
@property |
616 |
@property |
613 |
def dict(self): |
617 |
def dict(self): |
|
618 |
)) |
622 |
)) |
619 |
return d |
623 |
return d |
620 |
|
624 |
|
|
|
625 |
def parse_ucr(self): |
626 |
super(Bond, self).parse_ucr() |
627 |
options = [] |
628 |
for option in self.options: |
629 |
try: |
630 |
name, value = option.split(None, 1) |
631 |
except ValueError: |
632 |
name, value = option, '' |
633 |
|
634 |
if name == 'vlan-raw-device': |
635 |
pass |
636 |
else: |
637 |
options.append(option) |
638 |
self.options = options |
639 |
|
640 |
def to_ucr(self): |
641 |
options = [ |
642 |
'vlan-raw-device %s' % (self.parent_device,), |
643 |
] |
644 |
return super(Bond, self).to_ucr(options) |
645 |
|
621 |
|
646 |
|
622 |
class Bond(Device): |
647 |
class Bond(Device): |
623 |
"""A network bonding interface""" |
648 |
"""A network bonding interface""" |
|
649 |
# make sure that used interfaces does not have any IPv4 or IPv6 address |
674 |
# make sure that used interfaces does not have any IPv4 or IPv6 address |
650 |
idevice.disable_ips() |
675 |
idevice.disable_ips() |
651 |
|
676 |
|
652 |
self.type = 'manual' |
|
|
653 |
|
654 |
def validate(self): |
677 |
def validate(self): |
655 |
super(Bond, self).validate() |
678 |
super(Bond, self).validate() |
656 |
|
679 |
|
|
731 |
'bond-slaves %s' % (' '.join(self.bond_slaves),), |
754 |
'bond-slaves %s' % (' '.join(self.bond_slaves),), |
732 |
'bond-mode %s' % (self.bond_mode,), |
755 |
'bond-mode %s' % (self.bond_mode,), |
733 |
] |
756 |
] |
734 |
if self.bond_primary: |
757 |
if self.bind_mode == 1 and self.bond_primary: |
735 |
options.append('bond-primary %s' % (' '.join(self.bond_primary),)) |
758 |
options.append('bond-primary %s' % (' '.join(self.bond_primary),)) |
736 |
if self.miimon is not None: |
759 |
if self.miimon is not None: |
737 |
options.append('miimon %s' % (self.miimon,)) |
760 |
options.append('miimon %s' % (self.miimon,)) |
738 |
|
761 |
|
739 |
vals = super(Bond, self).to_ucr() |
762 |
return super(Bond, self).to_ucr(options) |
740 |
for i, option in enumerate(options, start=len(self.options)): |
|
|
741 |
vals['interfaces/%s/options/%d' % (self.name, i)] = option |
742 |
return vals |
743 |
|
763 |
|
744 |
|
764 |
|
745 |
class Bridge(Device): |
765 |
class Bridge(Device): |
Lines 763-770
class Bridge(Device):
|
Link Here
|
---|
|
763 |
# make sure that used interfaces does not have any IPv4 or IPv6 address |
783 |
# make sure that used interfaces does not have any IPv4 or IPv6 address |
764 |
idevice.disable_ips() |
784 |
idevice.disable_ips() |
765 |
|
785 |
|
766 |
self.type = 'manual' |
|
|
767 |
|
768 |
def validate(self): |
786 |
def validate(self): |
769 |
super(Bridge, self).validate() |
787 |
super(Bridge, self).validate() |
770 |
|
788 |
|
Lines 812-821
class Bridge(Device):
|
Link Here
|
---|
|
812 |
'bridge_fd %d' % (self.bridge_fd,), |
830 |
'bridge_fd %d' % (self.bridge_fd,), |
813 |
] |
831 |
] |
814 |
|
832 |
|
815 |
vals = super(Bridge, self).to_ucr() |
833 |
return super(Bridge, self).to_ucr(options) |
816 |
for i, option in enumerate(options, start=len(self.options)): |
|
|
817 |
vals['interfaces/%s/options/%d' % (self.name, i)] = option |
818 |
return vals |
819 |
|
834 |
|
820 |
|
835 |
|
821 |
if __name__ == '__main__': |
836 |
if __name__ == '__main__': |