Skip to content

Commit e9ab130

Browse files
committed
Use CouchDB provided uuid for host identification
1 parent bf72f1c commit e9ab130

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ers/api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""
22
ers.api
33
4-
Provides class ERS implementing API to Entity Rgistry System.
4+
Provides class ERS implementing API to Entity Registry System.
55
66
"""
77
import re
88
import sys
9-
import uuid
109

1110
from hashlib import md5
1211
from socket import gethostname
@@ -34,14 +33,18 @@ def __init__(self,
3433
self._init_host_urn()
3534

3635
def _init_host_urn(self):
37-
fingerprint = md5(gethostname()).hexdigest()
38-
self.host_urn = "urn:ers:host:{}".format(fingerprint)
36+
# Use uuid provided by CouchDB 1.3+, fallback to hostname fingerprint
37+
try:
38+
uid = self.store.info()['uuid']
39+
except KeyError:
40+
uid = md5(gethostname()).hexdigest()
41+
self.host_urn = "urn:ers:host:{}".format(uid)
3942

4043
def get_machine_uuid(self):
4144
'''
4245
@return a unique identifier for this ERS node
4346
'''
44-
return str(uuid.getnode())
47+
return self.host_urn.split(':')[-1]
4548

4649
def _is_failing(self, url):
4750
"""

0 commit comments

Comments
 (0)