|
|
@@ -72,13 +72,38 @@ def configure():
|
|
|
print 'group_id should be numeric'
|
|
|
config.set('client', 'group_id', group_id)
|
|
|
|
|
|
- print 'getting a brand new server id'
|
|
|
+ print 'checking existing servers'
|
|
|
try:
|
|
|
- url = '%s/v1/%s/register_server' % (default_api_server, group_id)
|
|
|
- r = urllib2.urlopen(url, json.dumps({'hostname': socket.getfqdn()}))
|
|
|
- server_id = json.load(r)['server_id']
|
|
|
+ url = '%s/v1/%s/servers' % (default_api_server, group_id)
|
|
|
+ r = urllib2.urlopen(url)
|
|
|
+ servers = json.load(r)
|
|
|
except Exception as e:
|
|
|
- sys.exit('an error occurred while getting the new server id:\n%r' % e)
|
|
|
+ sys.exit('an error occurred while fetching existing servers:\n%r' % e)
|
|
|
+ our_hostname = socket.getfqdn()
|
|
|
+ server_id = None
|
|
|
+ matches = 0
|
|
|
+ for server in servers:
|
|
|
+ if server['hostname'] == our_hostname:
|
|
|
+ server_id = server['id']
|
|
|
+ matches += 1
|
|
|
+ if matches == 0:
|
|
|
+ print 'no hostname matches found'
|
|
|
+ elif matches == 1:
|
|
|
+ print '1 hostname match found (%s, server id %d)' % (our_hostname, server_id)
|
|
|
+ if raw_input('take over this server id? (only do this if the old host is dead) [y/N] ') != 'y':
|
|
|
+ server_id = None
|
|
|
+ else:
|
|
|
+ print 'found %d servers with the same hostname... hopefully this is ok...' % matches
|
|
|
+ server_id = None
|
|
|
+
|
|
|
+ if server_id is None:
|
|
|
+ print 'getting a brand new server id'
|
|
|
+ try:
|
|
|
+ url = '%s/v1/%s/register_server' % (default_api_server, group_id)
|
|
|
+ r = urllib2.urlopen(url, json.dumps({'hostname': our_hostname}))
|
|
|
+ server_id = json.load(r)['server_id']
|
|
|
+ except Exception as e:
|
|
|
+ sys.exit('an error occurred while getting the new server id:\n%r' % e)
|
|
|
config.set('client', 'server_id', server_id)
|
|
|
|
|
|
print 'writing config to', cfg_path
|