summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-09-04 12:05:25 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-09-19 12:48:08 -0700
commite473325de679718ab0695d4d3177eeeef20dc994 (patch)
tree87450c0f1e85094ab75cdcf354072202ade9ee52 /lib/chef
parentce46528db4c9a7f06a34d16ee37017a59e8aab73 (diff)
downloadchef-e473325de679718ab0695d4d3177eeeef20dc994.tar.gz
DscScript resource will raise an error if dsc is not available
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/exceptions.rb2
-rw-r--r--lib/chef/platform/query_helpers.rb6
-rw-r--r--lib/chef/resource/dsc_script.rb19
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index ea053cae64..7298f1f4d1 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -181,6 +181,8 @@ class Chef
class ChildConvergeError < RuntimeError; end
+ class NoProviderAvailable < RuntimeError; end
+
class MissingRole < RuntimeError
NULL = Object.new
diff --git a/lib/chef/platform/query_helpers.rb b/lib/chef/platform/query_helpers.rb
index f6f5309de5..334ab278d1 100644
--- a/lib/chef/platform/query_helpers.rb
+++ b/lib/chef/platform/query_helpers.rb
@@ -45,7 +45,11 @@ class Chef
is_server_2003
end
- end
+ def supports_dsc?(node)
+ node[:languages] && node[:languages][:powershell] &&
+ node[:languages][:powershell][:version].to_i >= 4
+ end
+ end
end
end
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index 37546c3b6a..2972ace1aa 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require 'chef/exceptions'
+
class Chef
class Resource
class DscScript < Chef::Resource
@@ -26,7 +28,12 @@ class Chef
super
@allowed_actions.push(:run)
@action = :run
- provider(Chef::Provider::DscScript)
+ if(run_context && Chef::Platform.supports_dsc?(run_context.node))
+ @provider = Chef::Provider::DscScript
+ else
+ raise Chef::Exceptions::NoProviderAvailable,
+ "#{powershell_info_str(run_context)}\nPowershell 4.0 or higher was not detected on your system and is required to use the dsc_script resource."
+ end
end
def code(arg=nil)
@@ -118,6 +125,16 @@ class Chef
:kind_of => [ Integer ]
)
end
+
+ private
+
+ def powershell_info_str(run_context)
+ if run_context && run_context.node[:languages] && run_context.node[:languages][:powershell]
+ install_info = "Powershell #{run_context.node[:languages][:powershell][:version]} was found on the system."
+ else
+ install_info = 'Powershell was not found.'
+ end
+ end
end
end
end