|
Lines 46-54
ucr.load()
Link Here
|
| 46 |
|
46 |
|
| 47 |
_ = Translation('univention-management-console-module-setup').translate |
47 |
_ = Translation('univention-management-console-module-setup').translate |
| 48 |
|
48 |
|
| 49 |
RE_INTERFACE = re.compile(r'^interfaces/(?!(?:primary|restart/auto|handler)$)([^/_]+)(_[0-9]+)?/') |
49 |
RE_INTERFACE = re.compile(r'^interfaces/(?!(?:primary|restart/auto|handler)$)([^/]+?)(_[0-9]+)?/') |
| 50 |
RE_IPV6_ID = re.compile(r'^[a-zA-Z0-9]+\Z') |
50 |
RE_IPV6_ID = re.compile(r'^[a-zA-Z0-9]+\Z') |
| 51 |
VALID_NAME_RE = re.compile(r'^[^/ \t\n\r\f]{1,16}\Z') |
51 |
VALID_NAME_RE = re.compile(r'^(?![.]{1,2})[^/ \t\n\r\f]{1,15}\Z') |
| 52 |
|
52 |
|
| 53 |
PHYSICAL_INTERFACES = [dev['name'] for dev in detect_interfaces()] |
53 |
PHYSICAL_INTERFACES = [dev['name'] for dev in detect_interfaces()] |
| 54 |
|
54 |
|
|
Lines 80-100
class IP6Set(set):
Link Here
|
| 80 |
class Interfaces(dict): |
80 |
class Interfaces(dict): |
| 81 |
"""All network interfaces""" |
81 |
"""All network interfaces""" |
| 82 |
|
82 |
|
| 83 |
@property |
|
|
| 84 |
def primary(self): |
| 85 |
"""Returns the primary network interface if exists else None""" |
| 86 |
for device in self.values(): |
| 87 |
if device.primary: |
| 88 |
return device |
| 89 |
|
| 90 |
@primary.setter |
| 91 |
def primary(self, primary=None): |
| 92 |
"""Removes the primary flag from all devices and sets it to the new device if exists""" |
| 93 |
for device in self.values(): |
| 94 |
device.primary = False |
| 95 |
if primary in self: |
| 96 |
self[primary].primary = True |
| 97 |
|
| 98 |
def __init__(self, *args, **kwargs): |
83 |
def __init__(self, *args, **kwargs): |
| 99 |
"""Loads all network devices from UCR variables""" |
84 |
"""Loads all network devices from UCR variables""" |
| 100 |
super(Interfaces, self).__init__(*args, **kwargs) |
85 |
super(Interfaces, self).__init__(*args, **kwargs) |
|
Lines 102-108
class Interfaces(dict):
Link Here
|
| 102 |
ucr.load() |
87 |
ucr.load() |
| 103 |
|
88 |
|
| 104 |
# get all available interfaces |
89 |
# get all available interfaces |
| 105 |
interfaces = set(RE_INTERFACE.match(key).group(1) for key in ucr if RE_INTERFACE.match(key)) |
90 |
interfaces = set(_.group(1) for _ in (RE_INTERFACE.match(key) for key in ucr) if _) |
| 106 |
for name in interfaces: |
91 |
for name in interfaces: |
| 107 |
device = Device(name, self) |
92 |
device = Device(name, self) |
| 108 |
device.parse_ucr() |
93 |
device.parse_ucr() |
|
Lines 113-119
class Interfaces(dict):
Link Here
|
| 113 |
ucr.load() |
98 |
ucr.load() |
| 114 |
|
99 |
|
| 115 |
# remove old devices |
100 |
# remove old devices |
| 116 |
to_remove = set(self.keys()).difference(set(interfaces.keys())) |
101 |
to_remove = set(self.keys()) - set(interfaces.keys()) |
| 117 |
for name in to_remove: |
102 |
for name in to_remove: |
| 118 |
device = _RemovedDevice(name, self) |
103 |
device = _RemovedDevice(name, self) |
| 119 |
self[device.name] = device |
104 |
self[device.name] = device |
|
Lines 131-137
class Interfaces(dict):
Link Here
|
| 131 |
"""Returns a UCR representation of all interfaces""" |
116 |
"""Returns a UCR representation of all interfaces""" |
| 132 |
ucr.load() |
117 |
ucr.load() |
| 133 |
|
118 |
|
| 134 |
ucrv = {'interfaces/primary': None} |
119 |
ucrv = {} # 'interfaces/primary' is handled in util.py |
| 135 |
for device in self.values(): |
120 |
for device in self.values(): |
| 136 |
ucrv.update(device.to_ucr()) |
121 |
ucrv.update(device.to_ucr()) |
| 137 |
|
122 |
|
|
Lines 261-269
class Device(object):
Link Here
|
| 261 |
self.ip4dynamic = False |
246 |
self.ip4dynamic = False |
| 262 |
self.ip6dynamic = False |
247 |
self.ip6dynamic = False |
| 263 |
|
248 |
|
| 264 |
# flag indicating that this interface is the primary network interface of the system |
|
|
| 265 |
self.primary = False |
| 266 |
|
| 267 |
# flag indicating that this interface should automatically start at system startup |
249 |
# flag indicating that this interface should automatically start at system startup |
| 268 |
self.start = None |
250 |
self.start = None |
| 269 |
|
251 |
|
|
Lines 420-427
class Device(object):
Link Here
|
| 420 |
pattern = re.compile(r'^interfaces/%s(?:_[0-9]+)?/' % re.escape(name)) |
402 |
pattern = re.compile(r'^interfaces/%s(?:_[0-9]+)?/' % re.escape(name)) |
| 421 |
vals = dict((key, ucr[key]) for key in ucr if pattern.match(key)) |
403 |
vals = dict((key, ucr[key]) for key in ucr if pattern.match(key)) |
| 422 |
|
404 |
|
| 423 |
self.primary = ucr.get('interfaces/primary') == name |
|
|
| 424 |
|
| 425 |
self.start = ucr.is_true(value=vals.pop('interfaces/%s/start' % (name), None)) |
405 |
self.start = ucr.is_true(value=vals.pop('interfaces/%s/start' % (name), None)) |
| 426 |
|
406 |
|
| 427 |
self.type = vals.pop('interfaces/%s/type' % (name), None) |
407 |
self.type = vals.pop('interfaces/%s/type' % (name), None) |
|
Lines 473-481
class Device(object):
Link Here
|
| 473 |
for key, val in self._leftover: |
453 |
for key, val in self._leftover: |
| 474 |
vals[key] = val |
454 |
vals[key] = val |
| 475 |
|
455 |
|
| 476 |
if self.primary: |
|
|
| 477 |
vals['interfaces/primary'] = name |
| 478 |
|
| 479 |
if self.start is not None: |
456 |
if self.start is not None: |
| 480 |
vals['interfaces/%s/start' % (name)] = str(bool(self.start)).lower() |
457 |
vals['interfaces/%s/start' % (name)] = str(bool(self.start)).lower() |
| 481 |
|
458 |
|
|
Lines 558-564
class Device(object):
Link Here
|
| 558 |
class _RemovedDevice(Device): |
535 |
class _RemovedDevice(Device): |
| 559 |
"""Internal class representing that a device have to be removed from UCR""" |
536 |
"""Internal class representing that a device have to be removed from UCR""" |
| 560 |
def to_ucr(self): |
537 |
def to_ucr(self): |
| 561 |
return dict((key, None) for key in ucr.iterkeys() if RE_INTERFACE.match(key)) |
538 |
to_remove = {} |
|
|
539 |
for key in ucr.iterkeys(): |
| 540 |
match = RE_INTERFACE.match(key) |
| 541 |
if match and self.name == match.group(1): |
| 542 |
to_remove[key] = None |
| 543 |
return to_remove |
| 562 |
|
544 |
|
| 563 |
def validate(self): |
545 |
def validate(self): |
| 564 |
return True |
546 |
return True |
|
Lines 823-829
class Bridge(Device):
Link Here
|
| 823 |
try: |
805 |
try: |
| 824 |
self.bridge_fd = int(value) |
806 |
self.bridge_fd = int(value) |
| 825 |
except ValueError: |
807 |
except ValueError: |
| 826 |
# invalid value |
|
|
| 827 |
pass |
808 |
pass |
| 828 |
else: |
809 |
else: |
| 829 |
options.append(option) |
810 |
options.append(option) |