Class: Chef::Provider::Env::Windows

Inherits:
Chef::Provider::Env show all
Includes:
Mixin::WindowsEnvHelper
Defined in:
lib/chef/provider/env/windows.rb

Constant Summary

Constants included from Mixin::WindowsEnvHelper

Mixin::WindowsEnvHelper::HWND_BROADCAST, Mixin::WindowsEnvHelper::SMTO_ABORTIFHUNG, Mixin::WindowsEnvHelper::SMTO_BLOCK, Mixin::WindowsEnvHelper::SMTO_NOTIMEOUTIFNOTHUNG, Mixin::WindowsEnvHelper::WM_SETTINGCHANGE

Constants included from ReservedNames::Win32::API::System

ReservedNames::Win32::API::System::PRODUCT_BUSINESS, ReservedNames::Win32::API::System::PRODUCT_BUSINESS_N, ReservedNames::Win32::API::System::PRODUCT_CLUSTER_SERVER, ReservedNames::Win32::API::System::PRODUCT_DATACENTER_SERVER, ReservedNames::Win32::API::System::PRODUCT_DATACENTER_SERVER_CORE, ReservedNames::Win32::API::System::PRODUCT_DATACENTER_SERVER_CORE_V, ReservedNames::Win32::API::System::PRODUCT_DATACENTER_SERVER_V, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_E, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_N, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_SERVER, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_SERVER_CORE, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_SERVER_CORE_V, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_SERVER_IA64, ReservedNames::Win32::API::System::PRODUCT_ENTERPRISE_SERVER_V, ReservedNames::Win32::API::System::PRODUCT_HOME_BASIC, ReservedNames::Win32::API::System::PRODUCT_HOME_BASIC_E, ReservedNames::Win32::API::System::PRODUCT_HOME_BASIC_N, ReservedNames::Win32::API::System::PRODUCT_HOME_PREMIUM, ReservedNames::Win32::API::System::PRODUCT_HOME_PREMIUM_E, ReservedNames::Win32::API::System::PRODUCT_HOME_PREMIUM_N, ReservedNames::Win32::API::System::PRODUCT_HOME_PREMIUM_SERVER, ReservedNames::Win32::API::System::PRODUCT_HOME_SERVER, ReservedNames::Win32::API::System::PRODUCT_HYPERV, ReservedNames::Win32::API::System::PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT, ReservedNames::Win32::API::System::PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING, ReservedNames::Win32::API::System::PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY, ReservedNames::Win32::API::System::PRODUCT_PROFESSIONAL, ReservedNames::Win32::API::System::PRODUCT_PROFESSIONAL_E, ReservedNames::Win32::API::System::PRODUCT_PROFESSIONAL_N, ReservedNames::Win32::API::System::PRODUCT_SB_SOLUTION_SERVER, ReservedNames::Win32::API::System::PRODUCT_SERVER_FOR_SMALLBUSINESS, ReservedNames::Win32::API::System::PRODUCT_SERVER_FOR_SMALLBUSINESS_V, ReservedNames::Win32::API::System::PRODUCT_SERVER_FOUNDATION, ReservedNames::Win32::API::System::PRODUCT_SMALLBUSINESS_SERVER, ReservedNames::Win32::API::System::PRODUCT_SOLUTION_EMBEDDEDSERVER, ReservedNames::Win32::API::System::PRODUCT_STANDARD_SERVER, ReservedNames::Win32::API::System::PRODUCT_STANDARD_SERVER_CORE, ReservedNames::Win32::API::System::PRODUCT_STANDARD_SERVER_CORE_V, ReservedNames::Win32::API::System::PRODUCT_STANDARD_SERVER_V, ReservedNames::Win32::API::System::PRODUCT_STARTER, ReservedNames::Win32::API::System::PRODUCT_STARTER_E, ReservedNames::Win32::API::System::PRODUCT_STARTER_N, ReservedNames::Win32::API::System::PRODUCT_STORAGE_ENTERPRISE_SERVER, ReservedNames::Win32::API::System::PRODUCT_STORAGE_EXPRESS_SERVER, ReservedNames::Win32::API::System::PRODUCT_STORAGE_STANDARD_SERVER, ReservedNames::Win32::API::System::PRODUCT_STORAGE_WORKGROUP_SERVER, ReservedNames::Win32::API::System::PRODUCT_ULTIMATE, ReservedNames::Win32::API::System::PRODUCT_ULTIMATE_E, ReservedNames::Win32::API::System::PRODUCT_ULTIMATE_N, ReservedNames::Win32::API::System::PRODUCT_UNDEFINED, ReservedNames::Win32::API::System::PRODUCT_WEB_SERVER, ReservedNames::Win32::API::System::PRODUCT_WEB_SERVER_CORE, ReservedNames::Win32::API::System::SM_SERVERR2, ReservedNames::Win32::API::System::VER_NT_DOMAIN_CONTROLLER, ReservedNames::Win32::API::System::VER_NT_SERVER, ReservedNames::Win32::API::System::VER_NT_WORKSTATION, ReservedNames::Win32::API::System::VER_SUITE_BACKOFFICE, ReservedNames::Win32::API::System::VER_SUITE_BLADE, ReservedNames::Win32::API::System::VER_SUITE_COMPUTE_SERVER, ReservedNames::Win32::API::System::VER_SUITE_DATACENTER, ReservedNames::Win32::API::System::VER_SUITE_EMBEDDEDNT, ReservedNames::Win32::API::System::VER_SUITE_ENTERPRISE, ReservedNames::Win32::API::System::VER_SUITE_PERSONAL, ReservedNames::Win32::API::System::VER_SUITE_SINGLEUSERTS, ReservedNames::Win32::API::System::VER_SUITE_SMALLBUSINESS, ReservedNames::Win32::API::System::VER_SUITE_SMALLBUSINESS_RESTRICTED, ReservedNames::Win32::API::System::VER_SUITE_STORAGE_SERVER, ReservedNames::Win32::API::System::VER_SUITE_TERMINAL, ReservedNames::Win32::API::System::VER_SUITE_WH_SERVER

Instance Attribute Summary

Attributes inherited from Chef::Provider::Env

#key_exists

Attributes inherited from Chef::Provider

#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context

Instance Method Summary collapse

Methods included from Mixin::WindowsEnvHelper

#broadcast_env_change, #expand_path

Methods included from Mixin::WideString

#utf8_to_wide, #wide_to_utf8, #wstring

Methods inherited from Chef::Provider::Env

#action_create, #action_delete, #action_modify, #current_values, #delete_element, #env_key_exists, #initialize, #load_current_resource, #modify_env, #new_values, #requires_modify_or_create?

Methods inherited from Chef::Provider

action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #define_resource_requirements, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #load_current_resource, #node, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use_inline_resources, #whyrun_mode?

Methods included from Mixin::Provides

#provided_as, #provides, #provides?

Methods included from Mixin::DescendantsTracker

#descendants, descendants, #direct_descendants, direct_descendants, #find_descendants_by_name, find_descendants_by_name, #inherited, store_inherited

Methods included from Mixin::LazyModuleInclude

#descendants, #include, #included

Methods included from Mixin::NotifyingBlock

#notifying_block, #subcontext_block

Methods included from DSL::DeclareResource

#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #with_run_context

Methods included from Mixin::ShellOut

#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!

Methods included from Mixin::PathSanity

#enforce_path_sanity, #sanitized_path

Methods included from Mixin::PowershellOut

#powershell_out, #powershell_out!

Methods included from Mixin::WindowsArchitectureHelper

#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory

Methods included from DSL::PlatformIntrospection

#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family

Constructor Details

This class inherits a constructor from Chef::Provider::Env

Instance Method Details

#create_envObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/provider/env/windows.rb', line 33

def create_env
  obj = env_obj(@new_resource.key_name)
  unless obj
    obj = WIN32OLE.connect("winmgmts://").get("Win32_Environment").spawninstance_
    obj.name = @new_resource.key_name
    obj.username = "<System>"
  end
  obj.variablevalue = @new_resource.value
  obj.put_
  value = @new_resource.value
  value = expand_path(value) if @new_resource.key_name.casecmp("PATH") == 0
  ENV[@new_resource.key_name] = value
  broadcast_env_change
end

#delete_envObject


48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/provider/env/windows.rb', line 48

def delete_env
  obj = env_obj(@new_resource.key_name)
  if obj
    obj.delete_
    broadcast_env_change
  end
  if ENV[@new_resource.key_name]
    ENV.delete(@new_resource.key_name)
  end
end

#env_obj(key_name) ⇒ Object


64
65
66
67
68
69
70
71
# File 'lib/chef/provider/env/windows.rb', line 64

def env_obj(key_name)
  wmi = WmiLite::Wmi.new
  # Note that by design this query is case insensitive with regard to key_name
  environment_variables = wmi.query("select * from Win32_Environment where name = '#{key_name}'")
  if environment_variables && environment_variables.length > 0
    environment_variables[0].wmi_ole_object
  end
end

#env_value(key_name) ⇒ Object


59
60
61
62
# File 'lib/chef/provider/env/windows.rb', line 59

def env_value(key_name)
  obj = env_obj(key_name)
  obj ? obj.variablevalue : ENV[key_name]
end

#whyrun_supported?Boolean


29
30
31
# File 'lib/chef/provider/env/windows.rb', line 29

def whyrun_supported?
  false
end