summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorAliasgar16 <aliasgar.batterywala@msystechnologies.com>2017-01-23 21:12:37 +0530
committerBryan McLellan <btm@loftninjas.org>2017-01-23 10:42:37 -0500
commit0d7aac70c39aae2456ca5eba76af2f80057324ad (patch)
treee7559232dbd5886d70c1630847e0739712253248 /lib/chef/provider
parent85a6e0f72ef098b6ef47dac3b2833ea66e51f3e1 (diff)
downloadchef-0d7aac70c39aae2456ca5eba76af2f80057324ad.tar.gz
Added module_version attribute for dsc_resource. (#5701)
* Added module_version attribute for dsc_resource. Signed-off-by: aliasgar16 <aliasgar.batterywala@msystechnologies.com>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/dsc_resource.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb
index 0f25065925..026d2ef104 100644
--- a/lib/chef/provider/dsc_resource.rb
+++ b/lib/chef/provider/dsc_resource.rb
@@ -29,6 +29,7 @@ class Chef
super
@new_resource = new_resource
@module_name = new_resource.module_name
+ @module_version = new_resource.module_version
@reboot_resource = nil
end
@@ -65,6 +66,13 @@ class Chef
a.whyrun err + ["Assuming a previous resource sets the RefreshMode."]
a.block_action!
end
+ requirements.assert(:run) do |a|
+ a.assertion { module_usage_valid? }
+ err = ["module_name must be supplied along with module_version."]
+ a.failure_message Chef::Exceptions::DSCModuleNameMissing,
+ err
+ a.block_action!
+ end
end
protected
@@ -92,6 +100,10 @@ class Chef
Chef::Platform.supports_refresh_mode_enabled?(node)
end
+ def module_usage_valid?
+ !(!@module_name && @module_version)
+ end
+
def generate_description
@converge_description
end
@@ -148,10 +160,14 @@ class Chef
end
end
+ def module_info_object
+ @module_version.nil? ? module_name : "@{ModuleName='#{module_name}';ModuleVersion='#{@module_version}'}"
+ end
+
def invoke_resource(method, output_format = :object)
properties = translate_type(@new_resource.properties)
switches = "-Method #{method} -Name #{@new_resource.resource}"\
- " -Property #{properties} -Module #{module_name} -Verbose"
+ " -Property #{properties} -Module #{module_info_object} -Verbose"
cmdlet = Chef::Util::Powershell::Cmdlet.new(
node,
"Invoke-DscResource #{switches}",