diff --git a/base/univention-network-manager/univention-register-network-address b/base/univention-network-manager/univention-register-network-address index b5bf5e1..90bb8bc 100755 --- a/base/univention-network-manager/univention-register-network-address +++ b/base/univention-network-manager/univention-register-network-address @@ -33,21 +33,26 @@ import sys import optparse import netifaces -import subprocess import univention.config_registry import univention.uldap +from univention.lib.umc import Client, HTTPError, ConnectionError + 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) + try: + client = Client() + client.authenticate_with_machine_account() + return client.umc_command('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') + }).result.get('success', True) + except (HTTPError, ConnectionError) as exc: if verbose: - print 'More information: %s\n%s' % (res[1], res[0]) - return False - return True + print '%s: %s' % (type(exc).__name__, exc) + return False if __name__ == '__main__':