diff --git a/base/univention-network-manager/univention-register-network-address b/base/univention-network-manager/univention-register-network-address index 89898c1..dec515d 100755 --- a/base/univention-network-manager/univention-register-network-address +++ b/base/univention-network-manager/univention-register-network-address @@ -34,20 +34,29 @@ import sys import optparse import netifaces import subprocess +import httplib import univention.config_registry import univention.uldap +from univention.lib.umc_connection import UMCConnection def register_iface(configRegistry, iface, verbose): # is fallback different from current address? - 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) - res = p1.communicate() - if p1.returncode != 0: - print 'ERROR: IP registration for %s failed with code %s' % (iface,p1.returncode) + def err(error): if verbose: - print 'More information: %s\n%s' % (res[1], res[0]) + print error + try: + connection = UMCConnection.get_machine_connection(err) + return connection.request('ip/change', { + 'ip': configRegistry.get('interfaces/%s/address' % iface), + 'oldip': configRegistry.get('interfaces/%s/fallback/address' % iface), + 'netmask': configRegistry.get('interfaces/%s/netmask' % iface), + 'role': configRegistry.get('server/role') + }).get('success', True) + except (RuntimeError, ValueError, EnvironmentError, httplib.HTTPException) as exc: + if verbose: + print '%s: %s' % (type(exc).__name__, exc) return False - return True if __name__ == '__main__':