Class: Mixlibrary::Core::Windows::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlibrary/core/windows/features.rb

Instance Method Summary collapse

Constructor Details

#initialize(feature_name) ⇒ Features

Returns a new instance of Features.



9
10
11
12
13
14
15
16
# File 'lib/mixlibrary/core/windows/features.rb', line 9

def initialize(feature_name)
  if feature_name.to_s.strip.length == 0
    # It's nil, empty, or just whitespace

    raise "Feature name cannot be empty or just white space"
  end

  @feature_name=feature_name
end

Instance Method Details

#install_featureObject



28
29
30
31
32
33
34
35
36
# File 'lib/mixlibrary/core/windows/features.rb', line 28

def install_feature()
  Chef::Log.info("Installing feature:#{@feature_name}")
  script= "    import-module ServerManager;\n    Add-WindowsFeature -Name \"\#{@feature_name}\"\n  EOF\n\n  procobj = Mixlibrary::Core::Shell.windows_script_out!(:powershell, script)\nend\n"

#is_feature_available?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mixlibrary/core/windows/features.rb', line 38

def is_feature_available?()
  Chef::Log.info("Is feature available:#{@feature_name}")
  script= "    import-module ServerManager;\n    $myvar=@(get-WindowsFeature -Name \#{@feature_name})\n\n    if($myvar.Count -eq 0){\n        write-host \"Found no matching features\"\n        exit 6\n    }\n\n  write-host \"Printing Matching Features\"\n  foreach($myfeature in $myvar){\n    $myfeature | ft -Property FeatureType,DisplayName,Name,InstallState,Installed | Out-Host\n  }\n\n  exit 5\n\n  EOF\n\n  procobj = Mixlibrary::Core::Shell.windows_script_out(:powershell, script)\n\n  return procobj.stderr.empty? && procobj.stdout !~ /Removed/i && procobj.exitstatus==5\nend\n"

#is_installed?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mixlibrary/core/windows/features.rb', line 63

def is_installed?
  Chef::Log.info("Is feature installed:#{@feature_name}")
  #Need to handle this use case: Get-WindowsFeature Web* | Select Installed | % { Write-Host $_.Installed }

  #(cmd.stdout =~ /true/i) != nil ---There needs to be one true

  #(cmd.stdout =~ /False/i) == nil ---There needs to be no false

  #And no standard error

  script= "      import-module ServerManager;\n      Get-WindowsFeature -Name \#{@feature_name} | Select Installed | % { Write-Host $_.Installed }\n  EOF\n\n  procobj = Mixlibrary::Core::Shell.windows_script_out!(:powershell, script)\n  procobj.stderr.empty? && (procobj.stdout =~ /False/i) == nil && (procobj.stdout =~ /true/i) != nil\n\nend\n"

#remove_featureObject



18
19
20
21
22
23
24
25
26
# File 'lib/mixlibrary/core/windows/features.rb', line 18

def remove_feature()
  Chef::Log.info("Removing feature:#{@feature_name}")
  script= "    import-module ServerManager;\n    Remove-WindowsFeature -Name \"\#{@feature_name}\"\n  EOF\n\n  procobj = Mixlibrary::Core::Shell.windows_script_out!(:powershell, script)\nend\n"