28
28
29
29
30
30
class ConfigureHostMetering (actions .Action ):
31
- """Configure host metering on a machine if it's needed.
32
-
33
- env_var: str
34
- Content of CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable.
35
- """
31
+ """Configure host metering on a machine if it's needed."""
36
32
37
33
id = "CONFIGURE_HOST_METERING_IF_NEEDED"
38
34
39
35
def run (self ):
40
36
"""
41
- Decide whether to install, enable and start host-metering on the system based on the
42
- CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable .
37
+ Decide whether to install, enable and start host-metering on the system based on the setting of
38
+ 'configure_host_metering' in /etc/convert2rhel.ini .
43
39
44
- Behavior can be controlled CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable :
40
+ The behavior can be controlled via the 'configure_host_metering' as follows :
45
41
- "auto": host-metering will be configured based on the above conditions
46
42
- "force": forces configuration of host-metering (e.g., even if not running on a hyperscaler)
47
43
- any other value: Will be ignored and host metering will not be configured.
@@ -53,7 +49,7 @@ def run(self):
53
49
super (ConfigureHostMetering , self ).run ()
54
50
55
51
warn_deprecated_env ("CONVERT2RHEL_CONFIGURE_HOST_METERING" )
56
- if not self ._check_env_var ():
52
+ if not self ._check_host_metering_configuration ():
57
53
return False
58
54
59
55
if system_info .version .major != 7 and tool_opts .configure_host_metering == "auto" :
@@ -62,7 +58,7 @@ def run(self):
62
58
level = "INFO" ,
63
59
id = "CONFIGURE_HOST_METERING_SKIP" ,
64
60
title = "Did not perform host metering configuration." ,
65
- description = "Host metering is supportted only for RHEL 7." ,
61
+ description = "Host metering is supported only for RHEL 7." ,
66
62
)
67
63
return False
68
64
@@ -134,52 +130,58 @@ def run(self):
134
130
135
131
return service_running
136
132
137
- def _check_env_var (self ):
138
- """Check if the env var is set and if it has the right content. If the
139
- content is auto|force, the hostmetering should be configued on the system.
133
+ def _check_host_metering_configuration (self ):
134
+ """Check if host metering has been configured by the user and if the configuration option has the right value.
135
+ If the value is auto|force, the host metering should be configured on the system.
140
136
141
137
:return: Return True if the value is equal to auto|force, otherwise False
142
138
:rtype: bool
143
139
"""
144
140
if tool_opts .configure_host_metering is None :
145
- logger .debug ("CONVERT2RHEL_CONFIGURE_HOST_METERING was not set . Skipping it." )
141
+ logger .debug ("Configuration of host metering has not been enabled . Skipping it." )
146
142
self .add_message (
147
143
level = "INFO" ,
148
144
id = "CONFIGURE_HOST_METERING_SKIP" ,
149
145
title = "Did not perform host metering configuration." ,
150
- description = "CONVERT2RHEL_CONFIGURE_HOST_METERING was not set." ,
146
+ description = "Configuration of host metering has been skipped." ,
147
+ diagnosis = "We haven't detected 'configure_host_metering' in the convert2rhel.ini config file nor" \
148
+ " the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable." ,
151
149
)
152
150
return False
153
151
154
152
if tool_opts .configure_host_metering not in ("force" , "auto" ):
155
- logger .debug ("Value for environment variable not recognized: {}" .format (tool_opts .configure_host_metering ))
153
+ logger .debug ("Unexpected value of 'configure_host_metering' in convert2rhel.ini or the"
154
+ " CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: {}"
155
+ .format (tool_opts .configure_host_metering ))
156
156
self .add_message (
157
157
level = "WARNING" ,
158
158
id = "UNRECOGNIZED_OPTION_CONFIGURE_HOST_METERING" ,
159
- title = "Unrecognized option in CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable." ,
160
- description = "Environment variable {env_var} not recognized." .format (
161
- env_var = tool_opts .configure_host_metering
162
- ),
163
- remediations = "Set the option to `auto` value if you want to configure host metering." ,
159
+ title = "Unexpected value of the host metering setting." ,
160
+ diagnosis = "Unexpected value of 'configure_host_metering' in convert2rhel.ini or the" \
161
+ " CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable: {}"
162
+ .format (tool_opts .configure_host_metering ),
163
+ description = "Host metering will not be configured." ,
164
+ remediations = "Set the option to 'auto' or 'force' if you want to configure host metering." ,
164
165
)
165
166
return False
166
167
167
168
if tool_opts .configure_host_metering == "force" :
168
169
logger .warning (
169
- "The `force' option has been used for the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable ."
170
+ "You've set the host metering setting to 'force' ."
170
171
" Please note that this option is mainly used for testing and will configure host-metering unconditionally. "
171
172
" For generic usage please use the 'auto' option."
172
173
)
173
174
self .add_message (
174
175
level = "WARNING" ,
175
176
id = "FORCED_CONFIGURE_HOST_METERING" ,
176
- title = "The `force' option has been used for the CONVERT2RHEL_CONFIGURE_HOST_METERING environment variable. " ,
177
+ title = "Configuration of host metering set to 'force' " ,
177
178
description = "Please note that this option is mainly used for testing and"
178
179
" will configure host-metering unconditionally."
179
180
" For generic usage please use the 'auto' option." ,
180
181
)
181
182
elif tool_opts .configure_host_metering == "auto" :
182
- logger .debug ("Automatic detection of host hyperscaler and configuration." )
183
+ logger .debug ("Configuration of host metering set to 'auto' - host-metering will be enabled based on"
184
+ " a detected hyperscaler." )
183
185
184
186
return True
185
187
0 commit comments