-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgluster_params_handler.py
More file actions
105 lines (96 loc) · 3.21 KB
/
gluster_params_handler.py
File metadata and controls
105 lines (96 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
This module contains one class - ParamsHandler,
which contains APIs for configuration parameter
parsing.
"""
from gluster_test_parser import Parser
class ParamsHandler:
"""
This class contains all the APIs required for fetching
the values of all the configuration parameters.
"""
@classmethod
def get_config_hashmap(cls, filepath: str):
"""
Gets the configuration hashmap generated from the
api in Parser class and sets the reuired class variable.
The config_hashmap class variable can be accessed
throughout the class.
Args:
filepath (str): Path for config file
"""
cls.config_hashmap = Parser.generate_config_hashmap(filepath)
@classmethod
def get_server_ip(cls, server_name: str) -> str:
"""
Gives the server ip given the server name
Args:
server_name: name of the server as in config file.
example: server_vm1
Returns:
ip address of the given server
Example:
get_server_ip("server_vm1")
"""
index = server_name[9:]
server_ip = cls.config_hashmap['servers'][int(index)-1]
return server_ip
@classmethod
def get_client_ip(cls, client_name: str) -> str:
"""
Gives the client ip given the client name
Args:
client_name: name of the client as in config file.
example: client_vm1
Returns:
ip address of the given client
Example:
get_client_ip("client_vm1")
"""
index = client_name[9:]
client_ip = cls.config_hashmap['clients'][int(index)-1]
return client_ip
@classmethod
def get_server_ip_list(cls) -> list:
"""
Gives the list of all server ip
Returns:
list of all server ip address
"""
server_ip_list = cls.config_hashmap['servers']
return server_ip_list
@classmethod
def get_client_ip_list(cls) -> list:
"""
Gives the list of all client ip
Returns:
list of all client ip address
"""
client_ip_list = cls.config_hashmap['clients']
return client_ip_list
@classmethod
def get_brick_root_list(cls, server_name: str) -> list:
"""
Returns the list of brick root given the server name
Args:
server_name (str): name of the server as in config file.
example: server_vm1
Returns:
ilist of brick root of the given server
Example:
get_brick_root_list("server_vm1")
"""
server_ip = cls.get_server_ip(server_name)
servers_info = cls.config_hashmap['servers_info']
brick_root_list = servers_info[server_ip]['brick_root']
return brick_root_list
@classmethod
def volume_create_force_option(cls) -> bool:
"""
Returns the flag for volume_create_force option
Returns:
flag value(True/False) for volume_create_force option
"""
gluster_info = cls.config_hashmap['gluster']
volume_create_force = gluster_info['volume_create_force']
return volume_create_force