Top Level Namespace

Defined Under Namespace

Classes: DNSEntry, DNSZone, IPAddr

Constant Summary

NODESET_BIN =
'/usr/bin/nodeset'

Instance Method Summary (collapse)

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 = hpc_nodeset_expand(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 = hpc_nodeset_expand(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 = hpc_nodeset_expand(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

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

- (Object) hpc_dns_zones

Returns A hash of DNS zones hashes of the cluster

Returns:

  • A hash of DNS zones hashes of the cluster



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
# File 'lib/puppet/parser/functions/hpc_dns_zones.rb', line 20

def hpc_dns_zones()

  domain = get_domain()
  local_zone = DNSZone.new(domain)
  reverse_zones = Array.new

  net_topo = get_network_topology()
  networks = get_networks_reverse_zones(net_topo)

  # add NS to zone
  hostname = Facter.value(:hostname)
  fqdn = "#{hostname}.#{domain}."
  local_zone.add_entry('@', 'IN', 'NS', fqdn)
  local_zone.add_entry('@', 'IN', 'A', '127.0.0.1')

  # create a reverse zone for each network

  networks.each do |network|
    zone_name = get_reverse_zone_name(network)
    reverse_zone = DNSZone.new(zone_name)
    reverse_zone.net = network
    reverse_zone.add_entry('@', 'IN', 'NS', fqdn)
    reverse_zones << reverse_zone
  end

  # add cluster hosts to zones

  mn = get_master_network()
  
  mn.each do |host, details|
    netifs = details['networks']
    netifs.each do |network, params|
      hostname = params['hostname']
      ip = IPAddr.new(params['IP'])
      # On the WAN network, take the FQDN of the node instead of its
      # hostname+domain for the reverse in order to get same response
      # with DNS servers inside and outside the cluster.
      if network == 'wan'
        fqdn = "#{details['fqdn']}."
      else
        fqdn = "#{hostname}.#{domain}."
      end
      add_entries(local_zone, reverse_zones, hostname, fqdn, ip)
    end
  end

  # add vips to zones

  vips = get_vips()

  vips.each do |vip, params|
    hostname = params['hostname']
    ip = IPAddr.new(params['ip'])
    fqdn = "#{hostname}.#{domain}."
    add_entries(local_zone, reverse_zones, hostname, fqdn, ip)
  end

  # dump everything into zones big hash

  zones = Hash.new
  zones[local_zone.base] = local_zone.dump
  reverse_zones.each do |reverse_zone|
    zones[reverse_zone.base] = reverse_zone.dump
  end

  return zones

end

Method: #hpc_ha_vip_notify_scripts

Defined in:
lib/puppet/parser/functions/hpc_ha_vip_notify_scripts.rb,
lib/hpc/ha.rb

- (Object) hpc_ha_vip_notify_scripts

Returns A hash of VIP notify scripts hash for the current host

Returns:

  • A hash of VIP notify scripts hash for the current host



20
21
22
23
# File 'lib/puppet/parser/functions/hpc_ha_vip_notify_scripts.rb', line 20

def hpc_ha_vip_notify_scripts()
  hostname = Facter.value(:hostname)
  return get_host_vip_notify_scripts(hostname)
end

Method: #hpc_ha_vips

Defined in:
lib/puppet/parser/functions/hpc_ha_vips.rb,
lib/hpc/ha.rb

- (Object) hpc_ha_vips

Returns A hash of VIP hash for the current host

Returns:

  • A hash of VIP hash for the current host



20
21
22
23
# File 'lib/puppet/parser/functions/hpc_ha_vips.rb', line 20

def hpc_ha_vips()
  hostname = Facter.value(:hostname)
  return get_host_vips(hostname)
end

Method: #hpc_ha_vservs

Defined in:
lib/puppet/parser/functions/hpc_ha_vservs.rb,
lib/hpc/ha.rb

- (Object) hpc_ha_vservs

Returns A list of vserv hash for the current host

Returns:

  • A list of vserv hash for the current host



20
21
22
23
# File 'lib/puppet/parser/functions/hpc_ha_vservs.rb', line 20

def hpc_ha_vservs()
  hostname = Facter.value(:hostname)
  return get_host_vservs(hostname)
end

Method: #hpc_hmap

Defined in:
lib/hpc/hmap.rb,
lib/puppet/parser/functions/hpc_hmap.rb

- (Object) hpc_hmap(hash, key)

Returns Transform a hash of values into a hash of hash

Returns:

  • Transform a hash of values into a hash of hash



45
46
47
48
49
50
51
# File 'lib/hpc/hmap.rb', line 45

def hpc_hmap(hash, key)
  result = Hash.new()
  hash.each do |xkey, value|
    result[xkey] = { key => value }
  end
  return result
end

Method: #hpc_nodeset_exec

Defined in:
lib/hpc/nodeset.rb

- (Object) hpc_nodeset_exec(params)



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hpc/nodeset.rb', line 11

def hpc_nodeset_exec(params)
  if not File.executable?(NODESET_BIN)
    raise "Nodeset check_bin failed, #{NODESET_BIN} is not executable."
  end
  command = "#{NODESET_BIN} #{params}"
  out, err, status = Open3.capture3(command)
  if status.exitstatus != 0
    raise "Nodeset call with params(#{params}) failed with " +
      "status (#{status.exitstatus}). Error:\n" + err
  end
  return out
end

Method: #hpc_nodeset_expand

Defined in:
lib/hpc/nodeset.rb

- (Object) hpc_nodeset_expand(nodeset)



36
37
38
39
40
41
42
# File 'lib/hpc/nodeset.rb', line 36

def hpc_nodeset_expand(nodeset)
  if nodeset == ""
    return Array.new()
  end
  output = hpc_nodeset_exec("-e #{nodeset}")
  return output.strip().split(' ')
end

Method: #hpc_nodeset_fold

Defined in:
lib/hpc/nodeset.rb

- (Object) hpc_nodeset_fold(nodes_array)



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hpc/nodeset.rb', line 24

def hpc_nodeset_fold(nodes_array)
  if not nodes_array.kind_of?(Array)
    raise "Parameter nodes_array should be an array."
  end
  if nodes_array.length == 0
    return ""
  end
  nodes_list = nodes_array.join(' ')
  nodeset = hpc_nodeset_exec("-f #{nodes_list}")
  return nodeset.strip()
end

Method: #hpc_roles_nodeset

Defined in:
lib/puppet/parser/functions/hpc_roles_nodeset.rb,
lib/puppet/parser/functions/hpc_roles_nodeset.rb

- (Object) hpc_roles_nodeset(roles = nil)

Returns A hash with role names as keys and nodeset expression as value

Parameters:

  • roles (defaults to: nil)

    Array of roles to return, if nil, all roles are returnes

Returns:

  • A hash with role names as keys and nodeset expression as value



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/parser/functions/hpc_roles_nodeset.rb', line 26

def hpc_roles_nodeset(roles = nil)
  # Retrieve facts 
  hosts_by_role = lookupvar('hosts_by_role')

  if not roles 
    roles = hosts_by_role.keys()
  end

  nodesets = Hash.new()
  roles.each do |role|
    if not hosts_by_role.has_key?(role)
      debug "Role #{role} has no host"
      next
    end
    nodeset = hpc_nodeset_fold(hosts_by_role[role])
    nodesets[role] = nodeset
  end
  
  return nodesets
end

Method: #hpc_roles_single_nodeset

Defined in:
lib/puppet/parser/functions/hpc_roles_single_nodeset.rb,
lib/puppet/parser/functions/hpc_roles_single_nodeset.rb

- (Object) hpc_roles_single_nodeset(roles = nil)

Returns A nodeset expression with all the hosts having selected roles

Parameters:

  • roles (defaults to: nil)

    A list of roles to select, if nil, all roles are selected

Returns:

  • A nodeset expression with all the hosts having selected roles



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppet/parser/functions/hpc_roles_single_nodeset.rb', line 26

def hpc_roles_single_nodeset(roles = nil)
  # Retrieve facts 
  hosts_by_role = lookupvar('hosts_by_role')

  if not roles 
    roles = hosts_by_role.keys()
  end

  nodes = Array.new()
  roles.each do |role|
    if not hosts_by_role.has_key?(role)
      debug "Role #{role} has no host"
      next
    end
    role_nodes = hosts_by_role[role]
    nodes = nodes + role_nodes
  end
  
  return hpc_nodeset_fold(nodes)
end

Method: #hpc_shorewall_interfaces

Defined in:
lib/puppet/parser/functions/hpc_shorewall_interfaces.rb,
lib/puppet/parser/functions/hpc_shorewall_interfaces.rb

- (Object) hpc_shorewall_interfaces

Returns A hash with interfaces has key and a hash { 'zone' => '<firewall_zone'} as value

Returns:

  • A hash with interfaces has key and a hash { 'zone' => '<firewall_zone'} as value



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/parser/functions/hpc_shorewall_interfaces.rb', line 25

def hpc_shorewall_interfaces()
  # Retrieve facts
  #  HPC cluster networks
  topo = function_hiera(['net_topology'])
  #  Networks connected to this host
  mytopo = lookupvar('mynet_topology')

  interfaces = Hash.new()
  mytopo.each do |net_name, mynet|
    if not topo[net_name].has_key?('firewall_zone')
      next
    end
    mynet['interfaces'].each do |interface_name|
      interface = Hash.new()
      interface['zone'] =  topo[net_name]['firewall_zone']
      interfaces[interface_name] = interface
    end
  end
  
  return interfaces

end

Method: #hpc_source_file

Defined in:
lib/hpc/source.rb

- (Object) hpc_source_file(source)



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
# File 'lib/hpc/source.rb', line 3

def hpc_source_file(source)

  if source.kind_of?(Array)
    source_array = source
  else
    source_array = [source]
  end

  # First, try to read the file with the puppet function 
  # file, it handles fallback natively and paths like:
  # * <module>/<filename>
  # * Absolute file name
  data = nil
  begin
    data = function_file(source_array)
  rescue
    debug("function_file failed to read #{source_array}.")
  end

  if not data
    source_array.each do |current_file|
      begin
        # Remove the 'file://' part
        uri = current_file.sub(%r{^file://}, '')
        data = open(uri, 'rb') { |f| f.read }
      rescue => e 
          debug("IO module failed to read #{current_file}: #{e}")
      end
    end
  end

  if not data
    raise "Failed to get data for sources: #{source}"
  end

  return data

end

Method: #roles

Defined in:
lib/hpc/profiles.rb

- (Object) roles



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hpc/profiles.rb', line 73

def roles()
  # FIXME: ruby functions should not depend on facts
  hostlist = Facter.value('hostfile')
  roles = Array.new
  hostlist.each do |host|
    hostname = host[0]
    role = get_role_by_hostname(hostname)
    # ignore the default role
    if role != 'default'
      roles.push(role) unless roles.include?(role)
    end
  end
  return roles
end