Module: Exec::CheckParameter
- Defined in:
- lib/exec/check_parameter.rb
Overview
Module who gather all methods whoch check synthax of parameter
Instance Method Summary collapse
-
#check_ambari_host_name(str) ⇒ Object
Check ambari host name.
-
#check_cluster_name(str) ⇒ Object
Check cluster name format.
-
#check_cpu_weight(str) ⇒ Object
Check cpu weight format.
-
#check_crowbar_node_name(str) ⇒ Object
Check crowbar node name format.
-
#check_hadoop_component_name(str) ⇒ Object
Check hadoop component name.
-
#check_hadoop_service_name(str) ⇒ Object
Check hadoop service name.
-
#check_network_address(str) ⇒ Object
Check network address.
-
#check_param_for_bios(str) ⇒ Object
Check raid name format.
-
#check_param_for_raid(str) ⇒ Object
Check raid name format.
-
#check_ram_size(str) ⇒ Object
Check ram size format.
-
#check_request_id(str) ⇒ Object
Check request id.
-
#check_type_conf(str) ⇒ Object
Check type name format of the configuration about a ambari cluster.
-
#check_vlan_id(str) ⇒ Object
Check vlan id format.
-
#match_regex(str, regexp, msg_if_nok) ⇒ Boolean, String
private
Check if a string matches a regex.
Instance Method Details
#check_ambari_host_name(str) ⇒ Object
returns allways true for the moment.
Check ambari host name
181 182 183 |
# File 'lib/exec/check_parameter.rb', line 181 def (str) return true, "" end |
#check_cluster_name(str) ⇒ Object
Check cluster name format. It has to be a string of alphanumric down case char.
15 16 17 |
# File 'lib/exec/check_parameter.rb', line 15 def check_cluster_name(str) return match_regex(str, /^[a-z0-9]+$/, "The vcluser name #{str} is not valid. It should be an alphanumeric (down case) string.") end |
#check_cpu_weight(str) ⇒ Object
Check cpu weight format. It has to be a positive integer.
81 82 83 |
# File 'lib/exec/check_parameter.rb', line 81 def check_cpu_weight(str) return match_regex(str, /^[1-9]+[0-9]*$/, "CPU value '#{str}' is not valid. It should be a positive integer.") end |
#check_crowbar_node_name(str) ⇒ Object
Check crowbar node name format. It has to be a string of any characters.
33 34 35 |
# File 'lib/exec/check_parameter.rb', line 33 def (str) return match_regex(str, /^[A-Z0-9a-z\-]+$/, "The Node name #{str} is not valid.") end |
#check_hadoop_component_name(str) ⇒ Object
Check hadoop component name. It has to be a known component name.
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/exec/check_parameter.rb', line 166 def check_hadoop_component_name(str) hadoop_components = Common::ServicesDescription.get_components_list valid = true msg = "" unless hadoop_components.include?(str) valid = false msg = "Component name parameter has to be known Hadoop component." end return valid, msg end |
#check_hadoop_service_name(str) ⇒ Object
Check hadoop service name. It has to be a known hadoop service.
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/exec/check_parameter.rb', line 151 def check_hadoop_service_name(str) hadoop_services = Common::ServicesDescription.get_services_list valid = true msg = "" unless hadoop_services.include?(str) valid = false msg = "Service name parameter has to be known Hadoop service." end return valid, msg end |
#check_network_address(str) ⇒ Object
Check network address. Exemple of network format : 10.0.0.0/8 Network adress must have 1 octet in order to have a CIDR equals to 8 Network adress must have 2 octet in order to have a CIDR equals to 16 Network adress must have 3 octet in order to have a CIDR equals to 24
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/exec/check_parameter.rb', line 90 def check_network_address(str) msg = "" valid = true if str == nil valid = false msg = "Network adress and mask is missing" return valid, msg end network = str.split("/").first cidr = str.split("/").last if network == nil valid = false msg = "Network adress is missing" return valid, msg end if cidr == nil valid = false msg = "cidr mask is missing " return valid, msg end if cidr != "24" && cidr != "16" && cidr != "8" valid = false msg = "cidr is only valid if equal 8 , 16 , 24 " return valid, msg end unless IPAddress.valid?(network) valid = false msg = "Network adress is not valid " return valid, msg end octet1 = network.split(".").first octet2 = network.split(".").at(1) octet3 = network.split(".").at(2) octet4 = network.split(".").last if cidr == "8" if octet1 == "0" || octet2 != "0" || octet3 != "0" || octet4 !="0" valid = false msg = "Network adress is not valid " return valid, msg end elsif cidr == "16" if octet1 == "0" || octet3 != "0" || octet4 !="0" valid = false msg = "Network adress is not valid " return valid, msg end elsif cidr == "24" if octet1 == "0" || octet4 != "0" valid = false msg = "Network adress is not valid " return valid, msg end end return valid, msg end |
#check_param_for_bios(str) ⇒ Object
Check raid name format. It has to be a string of alphanumric down case char.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/exec/check_parameter.rb', line 39 def check_param_for_bios(str) msg = "" valid = true if str.strip() != "Hadoop" && str.strip() != "HadoopInfra" && str.strip() != "Storage" && str.strip() != "Virtualization" valid = false msg = "The Bios name must be only \"Hadoop\", \"HadoopInfra\", \"Storage\" or \"Virtualization\"" return valid, msg end return valid, msg end |
#check_param_for_raid(str) ⇒ Object
Check raid name format. It has to be a string of alphanumric down case char.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/exec/check_parameter.rb', line 52 def check_param_for_raid(str) msg = "" valid = true if str.strip() != "JBODOnly" && str.strip() != "Raid10" valid = false msg = "The Raid name must be only \"JBODOnly\" or \"Raid10\"" return valid, msg end return valid, msg end |
#check_ram_size(str) ⇒ Object
Check ram size format. It has to be an integer followed by ‘g’ charatcter.
75 76 77 |
# File 'lib/exec/check_parameter.rb', line 75 def check_ram_size(str) return match_regex(str, /^[1-9]+[0-9]*g$/, "RAM value #{str} is not valid. It should be a positive integer followed by.") end |
#check_request_id(str) ⇒ Object
Check request id. It has to be an integer.
187 188 189 |
# File 'lib/exec/check_parameter.rb', line 187 def check_request_id(str) return match_regex(str, /^[0-9]*$/, "Request id has to be a positive integer.") end |
#check_type_conf(str) ⇒ Object
Check type name format of the configuration about a ambari cluster. It has to be a string of alphanumric down case char.
21 22 23 |
# File 'lib/exec/check_parameter.rb', line 21 def check_type_conf(str) return match_regex(str, /^[a-z0-9]+$/, "The type name #{str} of the configuration is not valid. It should be an alphanumeric (down case) string.") end |
#check_vlan_id(str) ⇒ Object
Check vlan id format. It has to be a positive integer.
65 66 67 68 69 70 71 |
# File 'lib/exec/check_parameter.rb', line 65 def check_vlan_id(str) if str.to_i >= 10 && str.to_i <= 4096 return match_regex(str.to_s, /^[1-9][0-9]+$/, "ID Vlan '#{str}' is not a correct number.") else return false, "ID Vlan '#{str}' is not a correct number." end end |
#match_regex(str, regexp, msg_if_nok) ⇒ Boolean, String (private)
Check if a string matches a regex
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/exec/check_parameter.rb', line 197 def match_regex(str, regexp, msg_if_nok) msg = "" valid = true regex=Regexp.new(regexp) unless str.match(regex) valid = false msg = msg_if_nok end return valid, msg end |