Class: RightScale::PowershellProviderBase
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- RightScale::PowershellProviderBase
- Defined in:
- lib/chef/windows/powershell_provider_base.rb
Overview
Base class to dynamically generated Powershell Chef providers
Class Method Summary collapse
-
.init(node) ⇒ Object
Initialize Powershell host, should be called before :run and :terminate.
-
.run_script(script) ⇒ Object
Run powershell script in associated Powershell instance.
-
.terminate ⇒ Object
Terminate Powershell process if it was started.
Instance Method Summary collapse
-
#initialize(new_resource, run_context) ⇒ PowershellProviderBase
constructor
A new instance of PowershellProviderBase.
-
#load_current_resource ⇒ Object
Must override Chef’s load_current_resource.
Constructor Details
#initialize(new_resource, run_context) ⇒ PowershellProviderBase
Returns a new instance of PowershellProviderBase.
28 29 30 31 32 33 |
# File 'lib/chef/windows/powershell_provider_base.rb', line 28 def initialize(new_resource, run_context) super(new_resource, run_context) self.class.init(@run_context.node) # Have to wait until the Chef node server has been initialized before setting the new resource RightScale::Windows::ChefNodeServer.instance.new_resource = @new_resource end |
Class Method Details
.init(node) ⇒ Object
Initialize Powershell host, should be called before :run and :terminate
Return
- true
-
If init script must be run
- false
-
Otherwise
40 41 42 43 44 |
# File 'lib/chef/windows/powershell_provider_base.rb', line 40 def self.init(node) run_init = @ps_instance.nil? @ps_instance = PowershellHost.new(:node => node, :provider_name => self.to_s.gsub("::", "_")) unless @ps_instance run_init end |
.run_script(script) ⇒ Object
Run powershell script in associated Powershell instance
Parameters
- script(String)
-
Fully qualified path to Powershell script
Return
- true
-
Always return true
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef/windows/powershell_provider_base.rb', line 53 def self.run_script(script) if @ps_instance res = @ps_instance.run(script) # the powershell provider script the host runs will return exit code of 100 if the last action threw an exception. if res && res[:exit_code] && res[:exit_code] != 0 = "Unexpected exit code from action. Expected 0 but returned #{res[:exit_code]}. Script: #{script}\n" += "#{res[:error_msg]}" raise RightScale::Exceptions::Exec, end end true end |
.terminate ⇒ Object
Terminate Powershell process if it was started
Return
- true
-
Always return true
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chef/windows/powershell_provider_base.rb', line 72 def self.terminate if @ps_instance begin @ps_instance.terminate ensure @ps_instance = nil end end true end |
Instance Method Details
#load_current_resource ⇒ Object
Must override Chef’s load_current_resource
Return
- true
-
Always return true
87 88 89 |
# File 'lib/chef/windows/powershell_provider_base.rb', line 87 def load_current_resource # Dummy end |