|
33 |
import sys |
33 |
import sys |
34 |
import optparse |
34 |
import optparse |
35 |
import netifaces |
35 |
import netifaces |
36 |
import subprocess |
|
|
37 |
import univention.config_registry |
36 |
import univention.config_registry |
38 |
import univention.uldap |
37 |
import univention.uldap |
39 |
|
38 |
|
|
|
39 |
from univention.lib.umc import Client, HTTPError, ConnectionError |
40 |
|
40 |
|
41 |
|
41 |
def register_iface(configRegistry, iface, verbose): |
42 |
def register_iface(configRegistry, iface, verbose): |
42 |
# is fallback different from current address? |
43 |
try: |
43 |
p1 = subprocess.Popen(['/usr/sbin/umc-command', '-U', '%s$' % configRegistry.get('hostname'), '-y', '/etc/machine.secret', '-s', configRegistry.get('ldap/master'), 'ip/change', '-o', 'ip=%s' % configRegistry.get('interfaces/%s/address' % iface), '-o', 'oldip=%s' % configRegistry.get('interfaces/%s/fallback/address' % iface), '-o', 'netmask=%s' % configRegistry.get('interfaces/%s/netmask' % iface), '-o', 'role=%s' % configRegistry.get('server/role')], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
44 |
client = Client() |
44 |
res = p1.communicate() |
45 |
client.authenticate_with_machine_account() |
45 |
if p1.returncode != 0: |
46 |
return client.umc_command('ip/change', { |
46 |
print 'ERROR: IP registration for %s failed with code %s' % (iface, p1.returncode) |
47 |
'ip': configRegistry.get('interfaces/%s/address' % iface), |
|
|
48 |
'oldip': configRegistry.get('interfaces/%s/fallback/address' % iface), |
49 |
'netmask': configRegistry.get('interfaces/%s/netmask' % iface), |
50 |
'role': configRegistry.get('server/role') |
51 |
}).result.get('success', True) |
52 |
except (HTTPError, ConnectionError) as exc: |
47 |
if verbose: |
53 |
if verbose: |
48 |
print 'More information: %s\n%s' % (res[1], res[0]) |
54 |
print '%s: %s' % (type(exc).__name__, exc) |
49 |
return False |
55 |
return False |
50 |
return True |
|
|
51 |
|
56 |
|
52 |
|
57 |
|
53 |
if __name__ == '__main__': |
58 |
if __name__ == '__main__': |