Class: PuppetAgentMgr::V2::Manager
- Inherits:
-
Object
- Object
- PuppetAgentMgr::V2::Manager
- Defined in:
- lib/puppet_agent_mgr/v2/manager.rb
Instance Method Summary collapse
-
#disable!(msg = nil) ⇒ Object
disable the puppet agent, on version 2.x the message is ignored.
-
#disabled? ⇒ Boolean
is the agent disabled.
-
#enable! ⇒ Object
enables the puppet agent, it can now start applying catalogs again.
-
#initialize(testing = false) ⇒ Manager
constructor
A new instance of Manager.
-
#lastrun ⇒ Object
epoch time when the last catalog was applied.
-
#load_summary ⇒ Object
loads the summary file and makes sure that some keys are always present.
-
#lock_message ⇒ Object
the current lock message, always “” on 2.0.
-
#managed_resources ⇒ Object
all the managed resources.
Methods included from Unix
#applying?, #daemon_present?, #has_process_for_pid?, #signal_running_daemon
Methods included from Common
#atomic_file, #create_common_puppet_cli, #enabled?, #idling?, #managed_resources_count, #managing_resource?, #run_in_background, #run_in_foreground, #runonce!, #seconds_to_human, #since_lastrun, #status, #stopped?, #validate_name
Constructor Details
#initialize(testing = false) ⇒ Manager
Returns a new instance of Manager.
13 14 15 16 17 18 19 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 13 def initialize(testing=false) unless testing $puppet_application_mode = Puppet::Util::RunMode[:agent] Puppet.settings.use :main, :agent Puppet.parse_config end end |
Instance Method Details
#disable!(msg = nil) ⇒ Object
disable the puppet agent, on version 2.x the message is ignored
28 29 30 31 32 33 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 28 def disable!(msg=nil) raise "Already disabled" unless enabled? File.open(Puppet[:puppetdlockfile], "w") { } "" end |
#disabled? ⇒ Boolean
is the agent disabled
58 59 60 61 62 63 64 65 66 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 58 def disabled? if File.exist?(Puppet[:puppetdlockfile]) if File::Stat.new(Puppet[:puppetdlockfile]).zero? return true end end false end |
#enable! ⇒ Object
enables the puppet agent, it can now start applying catalogs again
22 23 24 25 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 22 def enable! raise "Already enabled" if enabled? File.unlink(Puppet[:puppetdlockfile]) end |
#lastrun ⇒ Object
epoch time when the last catalog was applied
46 47 48 49 50 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 46 def lastrun summary = load_summary Integer(summary["time"].fetch("last_run", 0)) end |
#load_summary ⇒ Object
loads the summary file and makes sure that some keys are always present
69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 69 def load_summary summary = {"changes" => {}, "time" => {}, "resources" => {}, "version" => {}, "events" => {}} summary.merge!(YAML.load_file(Puppet[:lastrunfile])) if File.exist?(Puppet[:lastrunfile]) summary["resources"] = {"failed"=>0, "changed"=>0, "total"=>0, "restarted"=>0, "out_of_sync"=>0}.merge!(summary["resources"]) summary end |
#lock_message ⇒ Object
the current lock message, always “” on 2.0
53 54 55 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 53 def "" end |
#managed_resources ⇒ Object
all the managed resources
36 37 38 39 40 41 42 43 |
# File 'lib/puppet_agent_mgr/v2/manager.rb', line 36 def managed_resources # need to add some caching here based on mtime of the resources file return [] unless File.exist?(Puppet[:resourcefile]) File.readlines(Puppet[:resourcefile]).map do |resource| resource.chomp end end |