glusterfs

Форк
0
/
generate-epoch.py 
48 строк · 1.5 Кб
1
#!/usr/bin/python3
2
#
3
# Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
4
# This file is part of GlusterFS.
5
#
6
# This file is licensed to you under your choice of the GNU Lesser
7
# General Public License, version 3 or any later version (LGPLv3 or
8
# later), or the GNU General Public License, version 2 (GPLv2), in all
9
# cases as published by the Free Software Foundation.
10
#
11
# Generates unique epoch value on each gluster node to be used by
12
# nfs-ganesha service on that node.
13
#
14
# Configure 'EPOCH_EXEC' option to this script path in
15
# '/etc/sysconfig/ganesha' file used by nfs-ganesha service.
16
#
17
# Construct epoch as follows -
18
#        first 32-bit contains the now() time
19
#        rest 32-bit value contains the local glusterd node uuid
20

21
import time
22
import binascii
23

24
# Calculate the now() time into a 64-bit integer value
25
def epoch_now():
26
        epoch_time = int(time.mktime(time.localtime())) << 32
27
        return epoch_time
28

29
# Read glusterd UUID and extract first 32-bit of it
30
def epoch_uuid():
31
        file_name = '/var/lib/glusterd/glusterd.info'
32

33
        for line in open(file_name):
34
                if "UUID" in line:
35
                        glusterd_uuid = line.split('=')[1].strip()
36

37
        uuid_bin = binascii.unhexlify(glusterd_uuid.replace("-",""))
38

39
        epoch_uuid = int(binascii.hexlify(uuid_bin), 32) & 0xFFFF0000
40
        return epoch_uuid
41

42
# Construct epoch as follows -
43
#        first 32-bit contains the now() time
44
#        rest 32-bit value contains the local glusterd node uuid
45
epoch = (epoch_now() | epoch_uuid())
46
print((str(epoch)))
47

48
exit(0)
49

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.