diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-07 18:51:51 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-03-20 14:38:04 -0700 |
commit | af4a97f05ae08f2c9e437b92bdbbde0c2256d610 (patch) | |
tree | 822f35d0fb03ab099d6195457ed09cac6a95c72b /lib | |
parent | 4eada072f98f877cb071918f6430de6cee3f4daa (diff) | |
download | chef-af4a97f05ae08f2c9e437b92bdbbde0c2256d610.tar.gz |
Update dsc_resource provider to work with 3rd party resources
An example resource:
```ruby
dsc_resource "xSmbShare" do
resource :xSmbShare
property :Name, 'SMBShare1'
property :Path, 'C:\Users\vagrant'
property :Ensure, 'Present'
end
```
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/dsc_resource.rb | 21 | ||||
-rw-r--r-- | lib/chef/util/dsc/resource_store.rb | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index c85b4ae075..fa4901552a 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -19,6 +19,7 @@ require 'chef/util/powershell/cmdlet' require 'chef/util/dsc/local_configuration_manager' require 'chef/mixin/powershell_type_coercions' +require 'chef/util/dsc/resource_store' class Chef class Provider @@ -78,6 +79,10 @@ class Chef ) end + def resource_store + Chef::Util::DSC::ResourceStore.instance + end + def supports_dsc_invoke_resource? run_context && Chef::Platform.supports_dsc_invoke_resource?(node) end @@ -86,6 +91,17 @@ class Chef "Converge dsc resource" end + def module_name + @module_name ||= begin + r = resource_store.resource(@new_resource.resource.to_s) + if r['Module'] + r['Module']['Name'] + else + :none + end + end + end + def test_resource result = invoke_resource(:test) result.return_value[0]["InDesiredState"] @@ -99,6 +115,11 @@ class Chef def invoke_resource(method, output_format=:object) properties = translate_type(@new_resource.properties) switches = "-Method #{method.to_s} -Name #{@new_resource.resource} -Property #{properties}" + + if module_name != :none + switches += " -Module #{module_name}" + end + cmdlet = Chef::Util::Powershell::Cmdlet.new( node, "Invoke-DscResource #{switches}", diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb index 3adc763483..e28a146afd 100644 --- a/lib/chef/util/dsc/resource_store.rb +++ b/lib/chef/util/dsc/resource_store.rb @@ -78,7 +78,7 @@ class DSC def find_resources(name, module_name, rs) found = rs.find_all do |r| - name_matches = r['FriendlyName'].casecmp(name) == 0 + name_matches = r['Name'].casecmp(name) == 0 if name_matches module_name == nil || (r['Module'] and r['Module']['Name'].casecmp(module_name) == 0) else |