Class: Ridley::CommandContext::WindowsUpdateOmnibus
- Inherits:
-
Windows
- Object
- Base
- Windows
- Ridley::CommandContext::WindowsUpdateOmnibus
show all
- Defined in:
- lib/ridley-connectors/command_context/windows_update_omnibus.rb
Overview
Context class for generating an upgrade command for an Omnibus Chef installation on Windows based OSes
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
command, #command, template_file
Constructor Details
Returns a new instance of WindowsUpdateOmnibus.
16
17
18
19
20
21
22
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 16
def initialize(options = {})
super(options)
options = options.reverse_merge(chef_version: "latest", prerelease: false)
@chef_version = options[:chef_version]
@prerelease = options[:prerelease]
@direct_url = options[:direct_url]
end
|
Instance Attribute Details
#chef_version ⇒ String
8
9
10
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 8
def chef_version
@chef_version
end
|
#direct_url ⇒ String
14
15
16
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 14
def direct_url
@direct_url
end
|
#prerelease ⇒ Boolean
11
12
13
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 11
def prerelease
@prerelease
end
|
Instance Method Details
#chef_apply_command ⇒ String
55
56
57
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 55
def chef_apply_command
"chef-apply #{recipe_path}"
end
|
#chef_solo_command ⇒ String
50
51
52
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 50
def chef_solo_command
"chef-solo -c #{upgrade_solo_rb_path} -o upgrade_omnibus"
end
|
#recipe_code ⇒ String
Writes a recipe that uses remote_file to download the appropriate Chef MSI file
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 63
def recipe_code
code = "chef_version = '\#{chef_version}'\nprerelease = \#{prerelease}\n\nplatform = node[:platform]\nplatform_version = if node[:product_type] == 1 # Not server\n case node[:platform_version]\n when /6\\.1\\./\n \"7\"\n when /6\\.2\\./\n \"8\"\n end\nelse # server\n case node[:platform_version]\n when /5\\.2\\.3/\n \"2003r2\"\n when /6\\.0\\./\n \"2008\"\n when /6\\.1\\./\n \"2008r2\"\n when /6\\.2\\./\n \"2012\"\n when /6\\.3\\./\n \"2012r2\"\n end\nend\n\nmachine = node[:kernel][:machine]\nnightlies = false\n\nurl = 'http://www.opscode.com/chef/download'\nurl_args = [ \"p=\\\#{platform}\", \"pv=\\\#{platform_version}\", \"m=\\\#{machine}\", \"v=\\\#{chef_version}\", \"prerelease=\\\#{prerelease}\", \"nightlies=\\\#{nightlies}\" ]\n\ncomposed_url = \"\\\#{url}?\\\#{url_args.join '&'}\"\n\n\#{direct_url.nil? ? \"full_url = composed_url\" : \"full_url = \\\"\#{direct_url}\\\"\"}\nrequest = Chef::REST::RESTRequest.new(:head, URI.parse(full_url), nil)\nresult = request.call\n\nif result.kind_of?(Net::HTTPRedirection)\n full_url = result['location']\nend\n\nfile_name = ::File.basename(full_url)\nfile_download_path = \"C:\\\\\\\\chef\\\\\\\\update\\\\\\\\\\\#{file_name}\"\n\nremote_file file_download_path do\n source full_url\n backup false\n action :create_if_missing\nend\n\nfile_extension = ::File.extname(file_name)\n\n"
escape_and_echo(code)
end
|
#recipe_path ⇒ String
30
31
32
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 30
def recipe_path
"#{update_dir}\\default.rb"
end
|
#tmp_cookbook_path ⇒ String
35
36
37
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 35
def tmp_cookbook_path
"#{update_dir}\\cookbooks\\upgrade_omnibus"
end
|
#tmp_recipes_path ⇒ String
40
41
42
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 40
def tmp_recipes_path
"#{tmp_cookbook_path}\\recipes"
end
|
#uninstall_chef ⇒ String
Uses powershell to find a Chef installation and uninstalls it
125
126
127
128
129
130
131
132
133
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 125
def uninstall_chef
win_uninstall_chef = "$productName = \"Chef\"\n$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match $productName }\nIf ($app) { $app.Uninstall() }\n UNIN_PS\n\n escape_and_echo(win_uninstall_chef)\nend\n"
|
#update_dir ⇒ String
25
26
27
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 25
def update_dir
"C:\\chef\\update"
end
|
#upgrade_solo_rb_path ⇒ String
45
46
47
|
# File 'lib/ridley-connectors/command_context/windows_update_omnibus.rb', line 45
def upgrade_solo_rb_path
"#{update_dir}\\upgrade_solo.rb"
end
|