Top Level Namespace
Defined Under Namespace
Classes: DNSEntry, DNSZone, IPAddr
Constant Summary
- NODESET_BIN =
'/usr/bin/nodeset'
Instance Method Summary (collapse)
- - (Object) add_entries(local_zone, reverse_zones, hostname, fqdn, ip)
- - (Object) decryptor(file, password, scheme = 'AES-256-CBC')
- - (Object) find_reverse_zone(zones, ip)
- - (Object) get_cluster_prefix
- - (Object) get_domain
- - (Object) get_hiera(key)
- - (Object) get_host_vip_notify_scripts(hostname)
- - (Object) get_host_vips(hostname)
- - (Object) get_host_vservs(hostname)
- - (Object) get_hosts_by_profile(profile)
- - (Object) get_hosts_by_role(role)
- - (Object) get_master_network
- - (Object) get_network_topology
-
- (Object) get_networks_reverse_zones(nets_topo)
Returns the array of IPAddr to consider for reverse zones out of the network topology given in parameter.
- - (Object) get_profiles_by_role(role)
-
- (Object) get_reverse_zone_name(ip)
Returns the reverse zone name corresponding to an ipaddr.
-
- (Object) get_reverse_zone_owner(ip, net)
Returns the reverse zone entry owner inside the network.
- - (Object) get_role_by_hostname(hostname)
- - (Object) get_role_index_for_name(hostname, prefix)
-
- (Object) get_vips
Return the vips hash found in hiera.
-
- (Object) hpc_atoh(array)
Transform the array into hash with empty values.
-
- (Object) hpc_dns_zones
A hash of DNS zones hashes of the cluster.
-
- (Object) hpc_ha_vip_notify_scripts
A hash of VIP notify scripts hash for the current host.
-
- (Object) hpc_ha_vips
A hash of VIP hash for the current host.
-
- (Object) hpc_ha_vservs
A list of vserv hash for the current host.
-
- (Object) hpc_hmap(hash, key)
Transform a hash of values into a hash of hash.
- - (Object) hpc_nodeset_exec(params)
- - (Object) hpc_nodeset_expand(nodeset)
- - (Object) hpc_nodeset_fold(nodes_array)
-
- (Object) hpc_roles_nodeset(roles = nil)
A hash with role names as keys and nodeset expression as value.
-
- (Object) hpc_roles_single_nodeset(roles = nil)
A nodeset expression with all the hosts having selected roles.
-
- (Object) hpc_shorewall_interfaces
A hash with interfaces has key and a hash
{ 'zone' => '<firewall_zone'}
as value. - - (Object) hpc_source_file(source)
- - (Object) roles
Instance Method Details
Method: #add_entries
- Defined in:
- lib/hpc/dns.rb
- (Object) add_entries(local_zone, reverse_zones, hostname, fqdn, ip)
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/hpc/dns.rb', line 224 def add_entries(local_zone, reverse_zones, hostname, fqdn, ip) local_zone.add_entry(hostname, 'IN', 'A', ip.to_s) reverse_zone = find_reverse_zone(reverse_zones, ip) if reverse_zone.nil? puts("unable to find reverse zone for IP #{ip.to_s}") # do nothing else owner = get_reverse_zone_owner(ip, reverse_zone.net) reverse_zone.add_entry(owner, 'IN', 'PTR', fqdn) end end |
Method: #decryptor
- Defined in:
- lib/puppet/parser/functions/decrypt.rb
- (Object) decryptor(file, password, scheme = 'AES-256-CBC')
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 |
# File 'lib/puppet/parser/functions/decrypt.rb', line 5 def decryptor(file, password, scheme='AES-256-CBC') ### Define key and iv lenght according to the RC4 encryption scheme ### case scheme when 'AES-256-CBC' keylength=32 ivlength=16 when 'AES-192-CBC' keylength=24 ivlength=16 when 'AES-128-CBC' keylength=16 ivlength=16 end encrypted_data = hpc_source_file(file) if encrypted_data == '' raise "Failed to read encrypted data from any source: #{file}" end if encrypted_data.length > 16 or encrypted_data[0, 8] == 'Salted__' # the unpack/pack trick is here to avoid an encoding issue # when using the salt in the MD5::digest. Not sufficiently # an expert on ruby string encoding to entirely understand # what's going on here. encrypted_data = encrypted_data.unpack('c*').pack('c*') salt = encrypted_data[8, 8] encrypted_data_without_salt = encrypted_data[16..-1] totsize = keylength + ivlength keyivdata = '' temp = '' while keyivdata.length < totsize do temp = Digest::MD5.digest(temp + password + salt) keyivdata << temp end key = keyivdata[0, keylength] iv = keyivdata[keylength, ivlength] ### Decrypt data ### decipher = OpenSSL::Cipher::Cipher.new(scheme) decipher.decrypt decipher.key = key decipher.iv = iv result = decipher.update(encrypted_data_without_salt) + decipher.final return result else raise "Invalid encrypted data read from file: #{file}" end end |
Method: #find_reverse_zone
- Defined in:
- lib/hpc/dns.rb
- (Object) find_reverse_zone(zones, ip)
215 216 217 218 219 220 221 222 |
# File 'lib/hpc/dns.rb', line 215 def find_reverse_zone(zones, ip) zones.each do |zone| if zone.net.include?(ip) return zone end end return nil end |
Method: #get_cluster_prefix
- Defined in:
- lib/hpc/profiles.rb
- (Object) get_cluster_prefix
50 51 52 53 54 55 56 57 58 |
# File 'lib/hpc/profiles.rb', line 50 def get_cluster_prefix() key = 'cluster_prefix' prefix = $hiera.lookup(key, $options[:default], $options[:scope], nil, $options[:resolution_type]) return prefix end |
Method: #get_domain
- Defined in:
- lib/hpc/dns.rb
- (Object) get_domain
157 158 159 |
# File 'lib/hpc/dns.rb', line 157 def get_domain() return get_hiera('domain') end |
Method: #get_hiera
- Defined in:
- lib/hpc/dns.rb
- (Object) get_hiera(key)
149 150 151 152 153 154 155 |
# File 'lib/hpc/dns.rb', line 149 def get_hiera(key) return $hiera.lookup(key, $options[:default], $options[:scope], nil, $options[:resolution_type]) end |
Method: #get_host_vip_notify_scripts
- Defined in:
- lib/hpc/ha.rb
- (Object) get_host_vip_notify_scripts(hostname)
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/hpc/ha.rb', line 111 def get_host_vip_notify_scripts(hostname) # This function returns a hash that could be given in parameters of: # create_resources(hpc_ha::vip_notify_script, $result) # # It implies that the items in the hashes composing this hash must correspond # to the parameters of the hpc_ha::vip_notify_script class. host_vip_notify_scripts = Hash.new # Iterate over all VIPs found in hiera. For each of them, if hostname is # member, add to host_vips all_vips = get_vips() # if no vip found in hiera, stop here return nil if all_vips.nil? all_vips.each do |vip_name, vip_items| members = (vip_items['members']) if members.include?(hostname) and vip_items.key?('notify') notify_conf = vip_items['notify'] # If the notify element is a simple string, consider the value is the # source of a script in common part. if notify_conf.instance_of? String new_script = Hash.new new_script['vip_name'] = vip_name new_script['part'] = 'common' source = vip_items['notify'] basename = File.basename(source) new_script['source'] = source host_vip_notify_scripts["#{vip_name}-common-#{basename}"] = new_script else # Otherwise (not a string), the notify element must a a hash, with parts # as keys, of list of script sources. notify_conf.each do |part, scripts| scripts.each do |source| new_script = Hash.new new_script['vip_name'] = vip_name new_script['part'] = part basename = File.basename(source) new_script['source'] = source host_vip_notify_scripts["#{vip_name}-#{part}-#{basename}"] = new_script end end end end end return nil unless host_vip_notify_scripts.length return host_vip_notify_scripts end |
Method: #get_host_vips
- Defined in:
- lib/hpc/ha.rb
- (Object) get_host_vips(hostname)
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 106 107 108 109 |
# File 'lib/hpc/ha.rb', line 63 def get_host_vips(hostname) # This function returns a hash that could be given in parameters of: # create_resources(hpc_ha::vip, $result) host_vips = Hash.new prefix = get_cluster_prefix() # Iterate over all VIPs found in hiera. For each of them, if hostname is # member, add to host_vips all_vips = get_vips() # if no vip found in hiera, stop here return nil if all_vips.nil? all_vips.each do |vip_group, vip_items| members = (vip_items['members']) if members.include?(hostname) is_master = vip_items['master'] == hostname priority = is_master ? 100 : 50 new_vip = Hash.new # The items in this hash must correspond to the parameters of the # hpc_ha::vip class new_vip['prefix'] = prefix new_vip['master'] = is_master new_vip['priority'] = priority new_vip['net_id'] = vip_items['network'] new_vip['router_id'] = vip_items['router_id'] new_vip['ip_address'] = vip_items['ip'] new_vip['auth_secret'] = vip_items['secret'] # Enable generic notify_script if notify scripts are set on VIP or a vserv # is defined with a port. If a vserv is configured, a notify script is # systematically deployed with a template by the hpc_ha module. new_vip['notify_script'] = vip_items.key?('notify') || vip_items.key?('port') if vip_items.key?('advert_int') new_vip['advert_int'] = vip_items['advert_int'] end host_vips[vip_group] = new_vip end end return nil unless host_vips.length return host_vips end |
Method: #get_host_vservs
- Defined in:
- lib/hpc/ha.rb
- (Object) get_host_vservs(hostname)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/hpc/ha.rb', line 167 def get_host_vservs(hostname) # This function returns a hash that could be given in parameters of: # create_resources(hpc_ha::vservs, $result) host_vservs = Hash.new # Find prefix for construct real hostname, for example if VIP is on "wan" real hostname isn't eofront1 but rineofront1 net_topology = Facter.value(:net_topology) # Iterate over all VIPs found in hiera. For each of them, if hostname is # member, add to host_vips all_vservs = get_vips() # if no vip found in hiera, stop here return nil if all_vservs.nil? all_vservs.each do |vservs_group, vservs_items| members = (vservs_items['members']) network_type = vservs_items['network'] netmask = net_topology[network_type]['prefix_length'] ip = vservs_items['ip'] ip2 = "#{ip}#{netmask}" if members.include?(hostname) and vservs_items.key?('port') new_vservs = Hash.new # The items in this hash must correspond to the parameters of the # hpc_ha::vserv class new_vservs['vip_name'] = vservs_group new_vservs['ip_address'] = ip2 new_vservs['port'] = vservs_items['port'] new_vservs['real_server_hosts'] = members new_vservs['delay_loop'] = vservs_items['delay_loop'] new_vservs['persistence_timeout'] = vservs_items['persistence_timeout'] new_vservs['protocol'] = vservs_items['protocol'] new_vservs['options'] = Hash.new new_vservs['options'] = vservs_items['options'] new_vservs['network'] = vservs_items['network'] new_vservs['prefixes'] = net_topology[network_type]['prefixes'] host_vservs[vservs_group] = new_vservs end end return nil unless host_vservs.length return host_vservs end |
Method: #get_hosts_by_profile
- Defined in:
- lib/hpc/profiles.rb
- (Object) get_hosts_by_profile(profile)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/hpc/profiles.rb', line 112 def get_hosts_by_profile(profile) # To get the list of hosts having a particular profile, the function iterates # over the list of roles. For each role, it checks if the role includes the # given profile. If yes, the hosts of the role are appending to the resuling # array. hosts = Array.new roles = roles() full_profile_name = 'profiles::' + profile roles.each do |role| profiles = get_profiles_by_role(role) if not profiles.nil? and profiles.include?(full_profile_name) hosts += get_hosts_by_role(role) end end # remove duplicates in the resulting array return hosts.uniq end |
Method: #get_hosts_by_role
- Defined in:
- lib/hpc/profiles.rb
- (Object) get_hosts_by_role(role)
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hpc/profiles.rb', line 101 def get_hosts_by_role(role) # FIXME: ruby functions should not depend on facts hostlist = Facter.value('hostfile') hosts = Array.new hostlist.each do |host| hostname = host[0] hosts.push(hostname) if get_role_by_hostname(hostname) == role end return hosts end |
Method: #get_master_network
- Defined in:
- lib/hpc/dns.rb
- (Object) get_master_network
161 162 163 |
# File 'lib/hpc/dns.rb', line 161 def get_master_network() return get_hiera('master_network') end |
Method: #get_network_topology
- Defined in:
- lib/hpc/dns.rb
- (Object) get_network_topology
165 166 167 |
# File 'lib/hpc/dns.rb', line 165 def get_network_topology() return get_hiera('net_topology') end |
Method: #get_networks_reverse_zones
- Defined in:
- lib/hpc/dns.rb
- (Object) get_networks_reverse_zones(nets_topo)
Returns the array of IPAddr to consider for reverse zones out of the network topology given in parameter.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/hpc/dns.rb', line 171 def get_networks_reverse_zones(nets_topo) networks = Array.new nets_topo.each do |net_name, params| addr = params['ipnetwork'] # get cidr prefix length w/o leading slash and convert to int prefix = params['prefix_length'][1..-1] cidr = "#{addr}/#{prefix}" ipnet = IPAddr.new(cidr) # get all /24 subnets of this network subnets = ipnet.subnets subnets.each do |subnet| # Check if network is not already included in any other networks add_network = true networks.each do |network| add_network = false if network.include?(subnet) end networks << subnet if add_network end end return networks end |
Method: #get_profiles_by_role
- Defined in:
- lib/hpc/profiles.rb
- (Object) get_profiles_by_role(role)
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hpc/profiles.rb', line 88 def get_profiles_by_role(role) key = 'profiles' # clone the default cope from $options and add the role in parameter scope = $options[:scope].clone scope['puppet_role'] = role profiles = $hiera.lookup(key, $options[:default], scope, nil, $options[:resolution_type]) return profiles end |
Method: #get_reverse_zone_name
- Defined in:
- lib/hpc/dns.rb
- (Object) get_reverse_zone_name(ip)
Returns the reverse zone name corresponding to an ipaddr. Ex: 192.168.0.0/16 -> 168.192.in-addr.arpa 192.168.3.1/24 - 1.168.192.in-addr.arpa
202 203 204 205 |
# File 'lib/hpc/dns.rb', line 202 def get_reverse_zone_name(ip) leading_null = (32 - ip.prefix) / 8 return ip.reverse.split('.')[leading_null..-1].join('.') end |
Method: #get_reverse_zone_owner
- Defined in:
- lib/hpc/dns.rb
- (Object) get_reverse_zone_owner(ip, net)
Returns the reverse zone entry owner inside the network. Ex: ip = 192.168.1.3 and net = 192.168.0.0/16 -> 3.1 ip = 192.168.1.3 and net = 192.168.1.0/24 -> 3
210 211 212 213 |
# File 'lib/hpc/dns.rb', line 210 def get_reverse_zone_owner(ip, net) trailing_bytes = (32 - net.prefix) / 8 return ip.to_s.split('.').reverse[0..trailing_bytes-1].join('.') end |
Method: #get_role_by_hostname
- Defined in:
- lib/hpc/profiles.rb
- (Object) get_role_by_hostname(hostname)
65 66 67 68 69 70 71 |
# File 'lib/hpc/profiles.rb', line 65 def get_role_by_hostname(hostname) if hostname =~ /^#{$CLUSTER_PREFIX}([a-z]+)[0-9]+$/ return $1 else return 'default' end end |
Method: #get_role_index_for_name
- Defined in:
- lib/facter/role.rb
- (Object) get_role_index_for_name(hostname, prefix)
16 17 18 19 20 21 22 23 |
# File 'lib/facter/role.rb', line 16 def get_role_index_for_name(hostname, prefix) #(prefix)(role)XYZ if hostname =~ /^#{prefix}([a-z]+[a-z0-9]*[a-z]+)([0-9])+$/ return [$1, $2] else return ['default', '0'] end end |
Method: #get_vips
- Defined in:
- lib/hpc/ha.rb
- (Object) get_vips
Return the vips hash found in hiera
53 54 55 56 57 58 59 60 61 |
# File 'lib/hpc/ha.rb', line 53 def get_vips() key = 'vips' vips = $hiera.lookup(key, $options[:default], $options[:scope], nil, $options[:resolution_type]) return vips end |
Method: #hpc_atoh
- Defined in:
-
lib/hpc/hmap.rb,
lib/puppet/parser/functions/hpc_atoh.rb
- (Object) hpc_atoh(array)
Returns transform the array into hash with empty values
27 28 29 30 31 32 33 |
# File 'lib/hpc/hmap.rb', line 27 def hpc_atoh(array) result = Hash.new() array.each do |value| result[value] = Hash.new() end return result end |
Method: #hpc_dns_zones
- Defined in:
-
lib/puppet/parser/functions/hpc_dns_zones.rb,
lib/hpc/dns.rb