get the name of a cluster node, parsing the yaml
[mirror/dsa-puppet.git] / modules / debian-org / lib / facter / cluster.rb
index 84066de..c8a2ac4 100644 (file)
@@ -1,17 +1,19 @@
-Facter.add('cluster') do
-  setcode do
-    if FileTest.exist?('/usr/sbin/gnt-cluster')
-      if system('/usr/sbin/gnt-cluster getmaster >/dev/null')
-        require 'json'
-        config = '/var/lib/ganeti/config.data'
-        if FileTest.exist?(config)
-          JSON.parse(File.read(config))['cluster']['cluster_name']
-        else
-          ''
-        end
-      end
-    else
-      ''
-    end
-  end
+if FileTest.exist?('/usr/sbin/gnt-cluster') and FileTest.exist?('/var/lib/ganeti/config.data')
+       begin
+               if system('/usr/sbin/gnt-cluster getmaster >/dev/null')
+                       require 'yaml'
+                       yaml = YAML.load_file('/var/lib/ganeti/config.data')
+                       Facter.add('cluster') do
+                               setcode do
+                                       yaml['cluster']['cluster_name']
+                               end
+                               end
+                               Facter.add('cluster_nodes') do
+                               setcode do
+                                       yaml['nodes']['name'].keys.join(' ')
+                               end
+                       end
+               end
+       rescue Exception => e
+       end
 end