|
34 |
import optparse |
34 |
import optparse |
35 |
import netifaces |
35 |
import netifaces |
36 |
import subprocess |
36 |
import subprocess |
|
|
37 |
import httplib |
37 |
import univention.config_registry |
38 |
import univention.config_registry |
38 |
import univention.uldap |
39 |
import univention.uldap |
|
|
40 |
from univention.lib.umc_connection import UMCConnection |
39 |
|
41 |
|
40 |
|
42 |
|
41 |
def register_iface(configRegistry, iface, verbose): |
43 |
def register_iface(configRegistry, iface, verbose): |
42 |
# is fallback different from current address? |
44 |
# is fallback different from current address? |
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) |
45 |
def err(error): |
44 |
res = p1.communicate() |
|
|
45 |
if p1.returncode != 0: |
46 |
print 'ERROR: IP registration for %s failed with code %s' % (iface,p1.returncode) |
47 |
if verbose: |
46 |
if verbose: |
48 |
print 'More information: %s\n%s' % (res[1], res[0]) |
47 |
print error |
|
|
48 |
try: |
49 |
connection = UMCConnection.get_machine_connection(err) |
50 |
return connection.request('ip/change', { |
51 |
'ip': configRegistry.get('interfaces/%s/address' % iface), |
52 |
'oldip': configRegistry.get('interfaces/%s/fallback/address' % iface), |
53 |
'netmask': configRegistry.get('interfaces/%s/netmask' % iface), |
54 |
'role': configRegistry.get('server/role') |
55 |
}).get('success', True) |
56 |
except (RuntimeError, ValueError, EnvironmentError, httplib.HTTPException) as exc: |
57 |
if verbose: |
58 |
print '%s: %s' % (type(exc).__name__, exc) |
49 |
return False |
59 |
return False |
50 |
return True |
|
|
51 |
|
60 |
|
52 |
|
61 |
|
53 |
if __name__ == '__main__': |
62 |
if __name__ == '__main__': |