Permalink
Browse files

white space fix

  • Loading branch information...
1 parent 8ae3f04 commit 938db5f07874b456c38b267c495d3bf16c1f04f2 @ripienaar committed Nov 9, 2012
View
@@ -1,100 +1,91 @@
module MCollective
- module Agent
- class Provision<RPC::Agent
- metadata :name => "Server Provisioning Agent",
- :description => "Agent to assist in provisioning new servers",
- :author => "R.I.Pienaar",
- :license => "Apache 2.0",
- :version => "2.0",
- :url => "http://www.devco.net/",
- :timeout => 360
-
-
- def startup_hook
- config = Config.instance
-
- certname = PluginManager["facts_plugin"].get_fact("fqdn")
- certname = config.identity unless certname
-
- @puppetcert = config.pluginconf["provision.certfile"] || "/var/lib/puppet/ssl/certs/#{certname}.pem"
- @lockfile = config.pluginconf["provision.lockfile"] || "/tmp/mcollective_provisioner_lock"
- @puppetd = config.pluginconf["provision.puppetd"] || "/usr/sbin/puppetd"
- end
+ module Agent
+ class Provision<RPC::Agent
+ def startup_hook
+ config = Config.instance
+
+ certname = PluginManager["facts_plugin"].get_fact("fqdn")
+ certname = config.identity unless certname
- action "set_puppet_host" do
- validate :ipaddress, :ipv4address
+ @puppetcert = config.pluginconf["provision.certfile"] || "/var/lib/puppet/ssl/certs/#{certname}.pem"
+ @lockfile = config.pluginconf["provision.lockfile"] || "/tmp/mcollective_provisioner_lock"
+ @puppetd = config.pluginconf["provision.puppetd"] || "/usr/sbin/puppetd"
+ end
- begin
- hosts = File.readlines("/etc/hosts")
+ action "set_puppet_host" do
+ validate :ipaddress, :ipv4address
- File.open("/etc/hosts", "w") do |hosts_file|
- hosts.each do |host|
- hosts_file.puts host unless host =~ /puppet/
- end
+ begin
+ hosts = File.readlines("/etc/hosts")
- hosts_file.puts "#{request[:ipaddress]}\tpuppet"
- end
- rescue Exception => e
- fail "Could not add hosts entry: #{e}"
- end
+ File.open("/etc/hosts", "w") do |hosts_file|
+ hosts.each do |host|
+ hosts_file.puts host unless host =~ /puppet/
end
- # does a run of puppet with --tags no_such_tag_here
- action "request_certificate" do
- reply[:output] = %x[#{@puppetd} --test --tags no_such_tag_here --color=none --summarize]
- reply[:exitcode] = $?.exitstatus
+ hosts_file.puts "#{request[:ipaddress]}\tpuppet"
+ end
+ rescue Exception => e
+ fail "Could not add hosts entry: #{e}"
+ end
+ end
- # dont fail here if exitcode isnt 0, it'll always be non zero
- end
+ # does a run of puppet with --tags no_such_tag_here
+ action "request_certificate" do
+ reply[:output] = %x[#{@puppetd} --test --tags no_such_tag_here --color=none --summarize]
+ reply[:exitcode] = $?.exitstatus
- # does a run of puppet with --environment bootstrap or similar
- action "bootstrap_puppet" do
- reply[:output] = %x[#{@puppetd} --test --environment bootstrap --color=none --summarize]
- reply[:exitcode] = $?.exitstatus
+ # dont fail here if exitcode isnt 0, it'll always be non zero
+ end
- fail "Puppet returned #{reply[:exitcode]}" if [4,6].include?(reply[:exitcode])
- end
+ # does a run of puppet with --environment bootstrap or similar
+ action "bootstrap_puppet" do
+ reply[:output] = %x[#{@puppetd} --test --environment bootstrap --color=none --summarize]
+ reply[:exitcode] = $?.exitstatus
- # does a normal puppet run
- action "run_puppet" do
- reply[:output] = %x[#{@puppetd} --test --color=none --summarize]
- reply[:exitcode] = $?.exitstatus
+ fail "Puppet returned #{reply[:exitcode]}" if [4,6].include?(reply[:exitcode])
+ end
- fail "Puppet returned #{reply[:exitcode]}" if [4,6].include?(reply[:exitcode])
- end
+ # does a normal puppet run
+ action "run_puppet" do
+ reply[:output] = %x[#{@puppetd} --test --color=none --summarize]
+ reply[:exitcode] = $?.exitstatus
- action "has_cert" do
- reply[:has_cert] = has_cert?
- end
+ fail "Puppet returned #{reply[:exitcode]}" if [4,6].include?(reply[:exitcode])
+ end
- action "lock_deploy" do
- reply.fail! "Already locked" if locked?
+ action "has_cert" do
+ reply[:has_cert] = has_cert?
+ end
- File.open(@lockfile, "w") {|f| f.puts Time.now}
+ action "lock_deploy" do
+ reply.fail! "Already locked" if locked?
- reply[:lockfile] = @lockfile
+ File.open(@lockfile, "w") {|f| f.puts Time.now}
- reply.fail! "Failed to lock the install" unless locked?
- end
+ reply[:lockfile] = @lockfile
- action "is_locked" do
- reply[:locked] = locked?
- end
+ reply.fail! "Failed to lock the install" unless locked?
+ end
- action "unlock_deploy" do
- File.unlink(@lockfile)
- reply[:unlocked] = locked?
- reply.fail! "Failed to unlock the install" if locked?
- end
+ action "is_locked" do
+ reply[:locked] = locked?
+ end
- private
- def has_cert?
- File.exist?(@puppetcert)
- end
+ action "unlock_deploy" do
+ File.unlink(@lockfile)
+ reply[:unlocked] = locked?
+ reply.fail! "Failed to unlock the install" if locked?
+ end
- def locked?
- File.exist?(@lockfile)
- end
- end
+ private
+ def has_cert?
+ File.exist?(@puppetcert)
+ end
+
+ def locked?
+ File.exist?(@lockfile)
+ end
end
+ end
end
View
@@ -6,51 +6,51 @@
include MCollective::RPC
module MCProvision
- autoload :Config, "mcprovision/config"
- autoload :PuppetMaster, "mcprovision/puppetmaster"
- autoload :Nodes, "mcprovision/nodes"
- autoload :Node, "mcprovision/node"
- autoload :Util, "mcprovision/util"
- autoload :Runner, "mcprovision/runner"
- autoload :Notifier, "mcprovision/notifier"
-
- VERSION = "1.0.0"
-
- def self.logfile(logfile, loglevel)
- @@logfile = logfile
- @@logger = Logger.new(logfile, 5, 102400)
-
- case loglevel
- when "debug"
- @@logger.level = Logger::DEBUG
- when "warn"
- @@logger.level = Logger::WARN
- else
- @@logger.level = Logger::INFO
- end
+ autoload :Config, "mcprovision/config"
+ autoload :PuppetMaster, "mcprovision/puppetmaster"
+ autoload :Nodes, "mcprovision/nodes"
+ autoload :Node, "mcprovision/node"
+ autoload :Util, "mcprovision/util"
+ autoload :Runner, "mcprovision/runner"
+ autoload :Notifier, "mcprovision/notifier"
+
+ VERSION = "1.0.0"
+
+ def self.logfile(logfile, loglevel)
+ @@logfile = logfile
+ @@logger = Logger.new(logfile, 5, 102400)
+
+ case loglevel
+ when "debug"
+ @@logger.level = Logger::DEBUG
+ when "warn"
+ @@logger.level = Logger::WARN
+ else
+ @@logger.level = Logger::INFO
end
+ end
- def self.version
- VERSION
- end
+ def self.version
+ VERSION
+ end
- def self.warn(msg)
- MCProvision.log(Logger::WARN, msg)
- end
+ def self.warn(msg)
+ MCProvision.log(Logger::WARN, msg)
+ end
- def self.info(msg)
- MCProvision.log(Logger::INFO, msg)
- end
+ def self.info(msg)
+ MCProvision.log(Logger::INFO, msg)
+ end
- def self.debug(msg)
- MCProvision.log(Logger::DEBUG, msg)
- end
+ def self.debug(msg)
+ MCProvision.log(Logger::DEBUG, msg)
+ end
- def self.log(severity, msg)
- begin
- from = File.basename(caller[1])
- @@logger.add(severity) { "#{$$} #{from}: #{msg}" }
- rescue Exception => e
- end
+ def self.log(severity, msg)
+ begin
+ from = File.basename(caller[1])
+ @@logger.add(severity) { "#{$$} #{from}: #{msg}" }
+ rescue Exception => e
end
+ end
end
@@ -1,16 +1,16 @@
module MCProvision
- class Config
- attr_reader :settings
+ class Config
+ attr_reader :settings
- def initialize(configfile = "/etc/mcollective/provisioner.yaml")
- Util.log("Loading config from #{configfile}")
- @settings = YAML.load_file(configfile)
+ def initialize(configfile = "/etc/mcollective/provisioner.yaml")
+ Util.log("Loading config from #{configfile}")
+ @settings = YAML.load_file(configfile)
- if @settings.include?("logfile") && @settings.include?("loglevel")
- MCProvision.logfile(@settings["logfile"], @settings["loglevel"])
- else
- MCProvision.logfile("/dev/stderr", "debug")
- end
- end
+ if @settings.include?("logfile") && @settings.include?("loglevel")
+ MCProvision.logfile(@settings["logfile"], @settings["loglevel"])
+ else
+ MCProvision.logfile("/dev/stderr", "debug")
+ end
end
+ end
end
Oops, something went wrong.

0 comments on commit 938db5f

Please sign in to comment.