vagrant-uplift 0.2.1902.19 → 0.2.1902.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.replica.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.users.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/_sp2013_image_packages.dsc.ps1 +40 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2013.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2013.post_setup.dsc.ps1 +3 -3
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.dsc.ps1 +1 -1
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.farm-minimal-services.dsc.ps1 +279 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.farm-only.dsc.ps1 +34 -128
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.post_setup.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup2.dsc.ps1 +2 -2
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1 +98 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1 +56 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sql-accounts.dsc.ps1 +106 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.web-application.dsc.ps1 +117 -0
- data/lib/scripts/vagrant/uplift.vagrant.sharepoint/tests/sp2016.minimal-services.Tests.ps1 +47 -0
- data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.dsc.ps1 +1 -1
- data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.optimize.dsc.ps1 +3 -2
- data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.prepare.dsc.ps1 +1 -1
- data/lib/scripts/vagrant/uplift.vagrant.win12soe/soe.shortcuts.dsc.ps1 +58 -4
- data/lib/vagrant-uplift/appinsights.rb +173 -0
- data/lib/vagrant-uplift/config_builder.rb +1231 -819
- data/lib/vagrant-uplift/log.rb +15 -4
- data/lib/vagrant-uplift/version.rb +1 -1
- metadata +13 -5
@@ -13,7 +13,7 @@ $sqlSysAdminAccounts = (Get-UpliftEnvVariable "UPLF_SQL_SYS_ADMIN_ACCOUNTS").Spl
|
|
13
13
|
|
14
14
|
Configuration Install_SQL
|
15
15
|
{
|
16
|
-
Import-DscResource -ModuleName 'xSQLServer'
|
16
|
+
Import-DscResource -ModuleName 'xSQLServer' -ModuleVersion "9.1.0.0"
|
17
17
|
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
|
18
18
|
|
19
19
|
Node localhost {
|
@@ -8,9 +8,10 @@ Write-UpliftEnv
|
|
8
8
|
|
9
9
|
Configuration Optimize_SQL
|
10
10
|
{
|
11
|
-
Import-DscResource -ModuleName 'xSQLServer'
|
12
11
|
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
|
13
12
|
|
13
|
+
Import-DscResource -ModuleName 'SqlServerDsc' -ModuleVersion "12.2.0.0"
|
14
|
+
|
14
15
|
Node localhost {
|
15
16
|
|
16
17
|
SqlServerMemory SQLServerMaxMemory
|
@@ -36,7 +37,7 @@ $config = @{
|
|
36
37
|
RetryIntervalSec = 30
|
37
38
|
|
38
39
|
ServerName = Get-UpliftEnvVariable "UPLF_SQL_SERVER_NAME" "" (hostname)
|
39
|
-
InstanceName = Get-UpliftEnvVariable "
|
40
|
+
InstanceName = Get-UpliftEnvVariable "UPLF_SQL_INSTANCE_NAME" "" "MSSQLSERVER"
|
40
41
|
|
41
42
|
MinMemory = Get-UpliftEnvVariable "UPLF_SQL_MIN_MEMORY" "" 1024
|
42
43
|
MaxMemory = Get-UpliftEnvVariable "UPLF_SQL_MAX_MEMORY" "" 4096
|
@@ -21,7 +21,7 @@ $instanceFeatures = Get-UpliftEnvVariable "UPLF_SQL_INSTANCE_FEATURES"
|
|
21
21
|
Write-UpliftMessage "Executing prepare DSC..."
|
22
22
|
Configuration Prepare_SQL
|
23
23
|
{
|
24
|
-
Import-DscResource -ModuleName xSQLServer
|
24
|
+
Import-DscResource -ModuleName xSQLServer -ModuleVersion "9.1.0.0"
|
25
25
|
|
26
26
|
Node localhost {
|
27
27
|
|
@@ -9,20 +9,21 @@ Configuration SOE_Shortcuts
|
|
9
9
|
{
|
10
10
|
Import-DscResource -ModuleName DSCR_Shortcut -ModuleVersion '1.3.7'
|
11
11
|
|
12
|
-
$desktopPath = [Environment]::GetFolderPath("
|
12
|
+
$desktopPath = [Environment]::GetFolderPath("CommonDesktopDirectory")
|
13
13
|
|
14
|
+
# common setup - IE, PowerShell ISE, PS6
|
14
15
|
cShortcut IE_Desktop
|
15
16
|
{
|
16
17
|
Path = "$desktopPath\IE.lnk"
|
17
18
|
Target = "C:\Program Files\Internet Explorer\iexplore.exe"
|
18
|
-
|
19
19
|
}
|
20
20
|
|
21
21
|
cShortcut PowerShell_ISE_Desktop
|
22
22
|
{
|
23
|
-
Path = "$desktopPath\
|
23
|
+
Path = "$desktopPath\PowerShell ISE.lnk"
|
24
24
|
Target = "%windir%\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe"
|
25
25
|
WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
|
26
|
+
Description = "IE IE"
|
26
27
|
|
27
28
|
}
|
28
29
|
|
@@ -31,7 +32,60 @@ Configuration SOE_Shortcuts
|
|
31
32
|
Path = "$desktopPath\PowerShell6.lnk"
|
32
33
|
Target = "C:\Program Files\PowerShell\6\pwsh.exe"
|
33
34
|
Arguments = "-WorkingDirectory ~"
|
34
|
-
|
35
|
+
}
|
36
|
+
|
37
|
+
# system utils
|
38
|
+
cShortcut ADUsers
|
39
|
+
{
|
40
|
+
Path = "$desktopPath\AD Users and Computers.lnk"
|
41
|
+
Target = "%SystemRoot%\system32\dsa.msc"
|
42
|
+
WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
|
43
|
+
}
|
44
|
+
|
45
|
+
cShortcut ServerManager
|
46
|
+
{
|
47
|
+
Path = "$desktopPath\Server Manager.lnk"
|
48
|
+
Target = "%windir%\system32\ServerManager.exe"
|
49
|
+
WorkingDirectory = '%windir%\system32'
|
50
|
+
}
|
51
|
+
|
52
|
+
cShortcut Services
|
53
|
+
{
|
54
|
+
Path = "$desktopPath\Services.lnk"
|
55
|
+
Target = "%windir%\system32\services.msc"
|
56
|
+
WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
|
57
|
+
}
|
58
|
+
|
59
|
+
# VS2017 exists?
|
60
|
+
$vs17Path = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe"
|
61
|
+
if( (Test-Path $vs17Path) -eq $True) {
|
62
|
+
cShortcut VS2017
|
63
|
+
{
|
64
|
+
Path = "$desktopPath\VS 2017.lnk"
|
65
|
+
Target = "$vs17Path"
|
66
|
+
WorkingDirectory = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
# sql management
|
71
|
+
$sql16ssms = "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe"
|
72
|
+
if( (Test-Path $sql16ssms) -eq $True) {
|
73
|
+
cShortcut SQL16SSMS
|
74
|
+
{
|
75
|
+
Path = "$desktopPath\SQL Server Manager.lnk"
|
76
|
+
Target = "$sql16ssms"
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
# sharepoint ca
|
81
|
+
$sp16centralAdministration = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\BIN\psconfigui.exe"
|
82
|
+
if( (Test-Path $sp16centralAdministration) -eq $True) {
|
83
|
+
cShortcut SP2016CA
|
84
|
+
{
|
85
|
+
Path = "$desktopPath\SharePoint Central Administration.lnk"
|
86
|
+
Target = $sp16centralAdministration
|
87
|
+
Arguments = "-cmd showcentraladmin"
|
88
|
+
}
|
35
89
|
}
|
36
90
|
}
|
37
91
|
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module VagrantPlugins::Uplift
|
2
|
+
module AppInsights
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
class AppInsightsHelper
|
7
|
+
|
8
|
+
require 'date'
|
9
|
+
require 'uri'
|
10
|
+
require 'net\http'
|
11
|
+
require 'openssl'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
@key = nil
|
15
|
+
|
16
|
+
@endpoint = nil
|
17
|
+
@endpoint_api = nil
|
18
|
+
|
19
|
+
@client_id = nil
|
20
|
+
|
21
|
+
def initialize(key)
|
22
|
+
@key = key
|
23
|
+
|
24
|
+
@endpoint = 'https://dc.services.visualstudio.com'
|
25
|
+
@endpoint_api = '/v2/track'
|
26
|
+
|
27
|
+
@client_id = 'uplift-vagrant:ruby:1.0.0'
|
28
|
+
end
|
29
|
+
|
30
|
+
def track_event(event_name, event_properties)
|
31
|
+
|
32
|
+
_log_debug("tracking event: #{event_name}")
|
33
|
+
|
34
|
+
result = {
|
35
|
+
:success => false
|
36
|
+
}
|
37
|
+
|
38
|
+
begin
|
39
|
+
time = DateTime.now.to_time.utc.strftime('%Y-%m-%dT%H:%M:%S.%7N%z')
|
40
|
+
|
41
|
+
data = {
|
42
|
+
"name" => "Microsoft.ApplicationInsights.Event",
|
43
|
+
|
44
|
+
"time" => time,
|
45
|
+
"iKey" => @key,
|
46
|
+
|
47
|
+
"tags" => {
|
48
|
+
"ai.internal.sdkVersion": @client_id
|
49
|
+
},
|
50
|
+
|
51
|
+
"data" => {
|
52
|
+
"baseType" => "EventData",
|
53
|
+
"baseData" => {
|
54
|
+
"ver": 2,
|
55
|
+
"name": event_name ,
|
56
|
+
"properties": event_properties
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
_log_debug("sending data: #{data}")
|
62
|
+
_send_data_async(data)
|
63
|
+
rescue => e
|
64
|
+
result[:exception] = e;
|
65
|
+
result[:success] = false
|
66
|
+
ensure
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def _log_debug(message)
|
76
|
+
if ENV['UPLF_LOG_LEVEL'] == 'DEBUG'
|
77
|
+
puts " AppInsights DEBUG: #{message}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def _send_data(data_hash)
|
82
|
+
thread = _send_data_async
|
83
|
+
thread.join
|
84
|
+
end
|
85
|
+
|
86
|
+
def _write_appinsight_usage_warning(message = nil, error = nil)
|
87
|
+
_log_debug "[!] Cannot use AppInsight, please report this error or use UPLF_NO_APPINSIGHT env variable to disable it."
|
88
|
+
|
89
|
+
if !message.to_s.empty?
|
90
|
+
_log_debug message
|
91
|
+
end
|
92
|
+
|
93
|
+
if !error.nil?
|
94
|
+
_log_debug e
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def _send_data_async(data_hash)
|
99
|
+
|
100
|
+
thr = Thread.new {
|
101
|
+
|
102
|
+
begin
|
103
|
+
|
104
|
+
_log_debug(" - creating http client")
|
105
|
+
http = _get_http_client
|
106
|
+
|
107
|
+
_log_debug(" - crafting request")
|
108
|
+
request = Net::HTTP::Post.new(@endpoint_api)
|
109
|
+
request.body = data_hash.to_json
|
110
|
+
|
111
|
+
_log_debug(" - http.request(request)")
|
112
|
+
response = http.request(request)
|
113
|
+
|
114
|
+
result = {}
|
115
|
+
|
116
|
+
_log_debug(" - response: #{response.inspect}")
|
117
|
+
|
118
|
+
result[:success] = response != nil && response.code.to_s == '200'
|
119
|
+
result[:response] = response
|
120
|
+
|
121
|
+
result[:response_code] = response.code
|
122
|
+
result[:response_message] = response.message
|
123
|
+
result[:response_body] = response.body()
|
124
|
+
|
125
|
+
if response != nil && response.code.to_s != '200'
|
126
|
+
_log_debug(" [!] FAIL!")
|
127
|
+
_write_appinsight_usage_warning("response code: #{response.code}", nil)
|
128
|
+
else
|
129
|
+
_log_debug(" [+] OK!")
|
130
|
+
end
|
131
|
+
|
132
|
+
rescue => e
|
133
|
+
_log_debug(" [!] FAIL!")
|
134
|
+
_write_appinsight_usage_warning(nil, e)
|
135
|
+
end
|
136
|
+
|
137
|
+
return result
|
138
|
+
}
|
139
|
+
|
140
|
+
return thr
|
141
|
+
end
|
142
|
+
|
143
|
+
def _get_http_client()
|
144
|
+
|
145
|
+
uri = URI.parse(@endpoint)
|
146
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
147
|
+
|
148
|
+
http.use_ssl = true
|
149
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
150
|
+
|
151
|
+
return http
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_client(key)
|
157
|
+
|
158
|
+
client = AppInsightsHelper.new(key)
|
159
|
+
|
160
|
+
_configure_client(client)
|
161
|
+
|
162
|
+
return client
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def _configure_client(client)
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -1,819 +1,1231 @@
|
|
1
|
-
require_relative "log"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
end
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
#
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
vm_config
|
336
|
-
|
337
|
-
vm_config
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
#
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
def
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
vm_config.
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
"
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
log_info_light("#{vm_name}:
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
vm_config
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
def
|
635
|
-
|
636
|
-
require_string(vm_name)
|
637
|
-
require_vagrant_config(vm_config)
|
638
|
-
|
639
|
-
log_info_light("#{vm_name}:
|
640
|
-
|
641
|
-
vm_config.vm.provision "shell",
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
"
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
vm_config.vm.provision "shell",
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
)
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
#
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
1
|
+
require_relative "log"
|
2
|
+
require_relative "appinsights"
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module Uplift
|
9
|
+
|
10
|
+
class UpliftConfigBuilder
|
11
|
+
|
12
|
+
@@logger = nil
|
13
|
+
|
14
|
+
@@network_range = '192.168.4'
|
15
|
+
@@config_file_path = './.vagrant/uplift-vagrant'
|
16
|
+
|
17
|
+
@@ai_client = nil
|
18
|
+
@@ai_config_id = nil
|
19
|
+
|
20
|
+
@@plugin_version = 'v0.1.20190207.235938'
|
21
|
+
|
22
|
+
@@supported_version = nil
|
23
|
+
|
24
|
+
# initialize
|
25
|
+
def initialize()
|
26
|
+
|
27
|
+
@@supported_version = '2.2.3'
|
28
|
+
@@ai_config_id = SecureRandom.uuid.to_s
|
29
|
+
|
30
|
+
if(Vagrant::VERSION != @@supported_version)
|
31
|
+
log_warn "WARN! - detected vagrant v#{Vagrant::VERSION}, uplift is tested on vagrant v#{@@supported_version}"
|
32
|
+
end
|
33
|
+
|
34
|
+
# disable warning:
|
35
|
+
# WARNING: Vagrant has detected the `vagrant-winrm` plugin.
|
36
|
+
ENV['VAGRANT_IGNORE_WINRM_PLUGIN'] = '1'
|
37
|
+
|
38
|
+
log_info_light "vagrant-uplift #{@@plugin_version}"
|
39
|
+
|
40
|
+
_track_ai_event('initialize')
|
41
|
+
|
42
|
+
# track only first time initialization for the vagrantfile
|
43
|
+
# further initializations won't be tracked
|
44
|
+
# _track_first_initialize
|
45
|
+
end
|
46
|
+
|
47
|
+
def vagrant_script_path
|
48
|
+
current_dir = File.dirname(__FILE__)
|
49
|
+
File.expand_path(File.join(current_dir, "/../scripts"))
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_config_path
|
53
|
+
return @@config_file_path
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_config_path(value)
|
57
|
+
@@config_file_path = value
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns path to uplift config folder
|
61
|
+
#
|
62
|
+
# @return [String] path to uplift config folder
|
63
|
+
def get_uplift_config_folder
|
64
|
+
path = File.expand_path(@@config_file_path)
|
65
|
+
FileUtils.mkdir_p path
|
66
|
+
|
67
|
+
return path
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns path to uplift config file
|
71
|
+
#
|
72
|
+
# @return [String] path to uplift config file
|
73
|
+
def get_uplift_config_file
|
74
|
+
config_dir_path = get_uplift_config_folder
|
75
|
+
file_name = ".vagrant-network.yaml"
|
76
|
+
|
77
|
+
return File.join(config_dir_path, file_name)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Sets 'machinefolder' property using 'vboxmanage' util
|
81
|
+
#
|
82
|
+
# @param vm_name [String] vagrant vm name
|
83
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
84
|
+
# @param value [String] path to use for virtualbx vms
|
85
|
+
def set_vbmanage_machinefolder(vm_name, vm_config, value = nil)
|
86
|
+
value = value || ENV['UPLF_VBMANAGE_MACHINEFOLDER']
|
87
|
+
|
88
|
+
if !value.to_s.empty?
|
89
|
+
log_info("#{vm_name}: vboxmanage machinefolder: #{value}")
|
90
|
+
system("vboxmanage setproperty machinefolder #{value}")
|
91
|
+
|
92
|
+
_track_ai_event(__method__, {
|
93
|
+
'vm_name': vm_name
|
94
|
+
})
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Resets 'machinefolder' property to default using 'vboxmanage' util
|
99
|
+
def set_vbmanage_machinefolder_default()
|
100
|
+
system("vboxmanage setproperty machinefolder default")
|
101
|
+
_track_ai_event(__method__, {
|
102
|
+
'vm_name': vm_name
|
103
|
+
})
|
104
|
+
end
|
105
|
+
|
106
|
+
# network helpers
|
107
|
+
def get_network_range
|
108
|
+
@@network_range
|
109
|
+
end
|
110
|
+
|
111
|
+
# Sets network range to be used in the multi-vm setup
|
112
|
+
#
|
113
|
+
# @param value [String] network range such as '192.168.10'
|
114
|
+
def set_network_range(value)
|
115
|
+
@@network_range = value
|
116
|
+
end
|
117
|
+
|
118
|
+
def get_ip_for_host(host_name)
|
119
|
+
start_index = 6
|
120
|
+
|
121
|
+
file_path = get_uplift_config_file
|
122
|
+
|
123
|
+
if(!File.exist? file_path)
|
124
|
+
File.open(file_path,"w") do |f|
|
125
|
+
f.write({}.to_yaml)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
map = YAML.load_file(file_path)
|
130
|
+
|
131
|
+
if map.nil?
|
132
|
+
map = {}
|
133
|
+
end
|
134
|
+
|
135
|
+
network_range = get_network_range
|
136
|
+
|
137
|
+
ip_ranges_key = network_range
|
138
|
+
machine_key = host_name.downcase
|
139
|
+
|
140
|
+
ips = map.fetch(ip_ranges_key, { })
|
141
|
+
machine_ip = ips.fetch(machine_key, nil)
|
142
|
+
|
143
|
+
if machine_ip.nil?
|
144
|
+
machine_ip = network_range + "." + (start_index + ips.count).to_s
|
145
|
+
end
|
146
|
+
|
147
|
+
ips[machine_key] = machine_ip
|
148
|
+
map[ip_ranges_key] = ips
|
149
|
+
|
150
|
+
File.open(file_path,"w") do |f|
|
151
|
+
f.write(map.to_yaml)
|
152
|
+
end
|
153
|
+
|
154
|
+
machine_ip
|
155
|
+
end
|
156
|
+
|
157
|
+
# log helpers
|
158
|
+
def log_warn(message)
|
159
|
+
_logger.warn(message)
|
160
|
+
end
|
161
|
+
|
162
|
+
def log_warning(message)
|
163
|
+
_logger.warn(message)
|
164
|
+
end
|
165
|
+
|
166
|
+
def log_info(message)
|
167
|
+
_logger.info(message)
|
168
|
+
end
|
169
|
+
|
170
|
+
def log_info_light(message)
|
171
|
+
_logger.info_light(message)
|
172
|
+
end
|
173
|
+
|
174
|
+
def log_debug(message)
|
175
|
+
_logger.debug(message)
|
176
|
+
end
|
177
|
+
|
178
|
+
def log_error(message)
|
179
|
+
_logger.error(message)
|
180
|
+
end
|
181
|
+
|
182
|
+
def log_error_and_raise(message)
|
183
|
+
log_error(message)
|
184
|
+
raise(message)
|
185
|
+
end
|
186
|
+
|
187
|
+
# Returns env variable value by name or default value
|
188
|
+
#
|
189
|
+
# @param name [String] env value name
|
190
|
+
# @param default_value [object] default value
|
191
|
+
# @return [object] env value
|
192
|
+
def get_env_variable(name, default_value)
|
193
|
+
var_name = name.upcase
|
194
|
+
var_value = ENV[var_name]
|
195
|
+
|
196
|
+
if var_value.to_s.empty?
|
197
|
+
return default_value
|
198
|
+
end
|
199
|
+
|
200
|
+
return var_value
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns cpus count for the giving vm name
|
204
|
+
#
|
205
|
+
# @param vm_name [String] vm name
|
206
|
+
# @param default_value [object] default value
|
207
|
+
# @return [String] cpus count
|
208
|
+
def get_vm_cpus(vm_name, default_value)
|
209
|
+
require_string(vm_name)
|
210
|
+
require_integer(default_value)
|
211
|
+
|
212
|
+
return get_env_variable("UPLF_#{vm_name}_CPUS", default_value)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Returns memory value for the giving vm name
|
216
|
+
#
|
217
|
+
# @param vm_name [String] vm name
|
218
|
+
# @param default_value [object] default value
|
219
|
+
# @return [String] memory value
|
220
|
+
def get_vm_memory(vm_name, default_value)
|
221
|
+
require_string(vm_name)
|
222
|
+
require_integer(default_value)
|
223
|
+
|
224
|
+
return get_env_variable("UPLF_#{vm_name}_MEMORY", default_value)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Returns checkpoint flag for the giving vm
|
228
|
+
#
|
229
|
+
# @param vm_name [String] vm name
|
230
|
+
# @param checkpoint_name [String] checkpoint name
|
231
|
+
# @return [Boolean] memory value
|
232
|
+
def has_checkpoint?(vm_name, checkpoint_name)
|
233
|
+
|
234
|
+
if !ENV['UPLF_NO_VAGRANT_CHECKPOINTS'].nil?
|
235
|
+
_log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name} (UPLF_NO_VAGRANT_CHECKPOINTS is set)")
|
236
|
+
|
237
|
+
return false
|
238
|
+
end
|
239
|
+
|
240
|
+
file_name = ".vagrant/machines/#{vm_name}/virtualbox/.uplift/.checkpoint-#{checkpoint_name}"
|
241
|
+
exists = File.exist?(file_name)
|
242
|
+
|
243
|
+
if exists == true
|
244
|
+
_log.info_light("#{vm_name}: [+] provision checkpoint: #{checkpoint_name}")
|
245
|
+
else
|
246
|
+
_log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name}")
|
247
|
+
end
|
248
|
+
|
249
|
+
return exists
|
250
|
+
end
|
251
|
+
|
252
|
+
# Configures vagrant vm with 0.5G and 2 CPUs
|
253
|
+
#
|
254
|
+
# @param vm_name [String] vm name
|
255
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
256
|
+
def set_05Gb(vm_name, vm_config)
|
257
|
+
require_string(vm_name)
|
258
|
+
require_vagrant_config(vm_config)
|
259
|
+
|
260
|
+
set_cpu_and_ram(vm_name, vm_config, 2, 512)
|
261
|
+
end
|
262
|
+
|
263
|
+
# Configures vagrant vm with 1G and 2 CPUs
|
264
|
+
#
|
265
|
+
# @param vm_name [String] vm name
|
266
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
267
|
+
def set_1Gb(vm_name, vm_config)
|
268
|
+
require_string(vm_name)
|
269
|
+
require_vagrant_config(vm_config)
|
270
|
+
|
271
|
+
set_cpu_and_ram(vm_name, vm_config, 2, 1024)
|
272
|
+
end
|
273
|
+
|
274
|
+
# Configures vagrant vm with 2G and 2 CPUs
|
275
|
+
#
|
276
|
+
# @param vm_name [String] vm name
|
277
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
278
|
+
def set_2Gb(vm_name, vm_config)
|
279
|
+
require_string(vm_name)
|
280
|
+
require_vagrant_config(vm_config)
|
281
|
+
|
282
|
+
set_cpu_and_ram(vm_name, vm_config, 2, 1024 * 2)
|
283
|
+
end
|
284
|
+
|
285
|
+
# Configures vagrant vm with 4G and 4 CPUs
|
286
|
+
#
|
287
|
+
# @param vm_name [String] vm name
|
288
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
289
|
+
def set_4Gb(vm_name, vm_config)
|
290
|
+
require_string(vm_name)
|
291
|
+
require_vagrant_config(vm_config)
|
292
|
+
|
293
|
+
set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 4)
|
294
|
+
end
|
295
|
+
|
296
|
+
# Configures vagrant vm with 6G and 4 CPUs
|
297
|
+
#
|
298
|
+
# @param vm_name [String] vm name
|
299
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
300
|
+
def set_6Gb(vm_name, vm_config)
|
301
|
+
require_string(vm_name)
|
302
|
+
require_vagrant_config(vm_config)
|
303
|
+
|
304
|
+
set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 6)
|
305
|
+
end
|
306
|
+
|
307
|
+
# Configures vagrant vm with 8G and 4 CPUs
|
308
|
+
#
|
309
|
+
# @param vm_name [String] vm name
|
310
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
311
|
+
def set_8Gb(vm_name, vm_config)
|
312
|
+
require_string(vm_name)
|
313
|
+
require_vagrant_config(vm_config)
|
314
|
+
|
315
|
+
set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 8)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Configures vagrant vm with 12G and 4 CPUs
|
319
|
+
#
|
320
|
+
# @param vm_name [String] vm name
|
321
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
322
|
+
def set_12Gb(vm_name, vm_config)
|
323
|
+
require_string(vm_name)
|
324
|
+
require_vagrant_config(vm_config)
|
325
|
+
|
326
|
+
set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 12)
|
327
|
+
end
|
328
|
+
|
329
|
+
# Configures vagrant vm with 16G and 4 CPUs
|
330
|
+
#
|
331
|
+
# @param vm_name [String] vm name
|
332
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
333
|
+
def set_16Gb(vm_name, vm_config)
|
334
|
+
require_string(vm_name)
|
335
|
+
require_vagrant_config(vm_config)
|
336
|
+
|
337
|
+
set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 16)
|
338
|
+
end
|
339
|
+
|
340
|
+
# Configures vagrant vm with giving RAM and CPUs
|
341
|
+
#
|
342
|
+
# @param vm_name [String] vm name
|
343
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
344
|
+
# @param cpu [String] amount of cpu
|
345
|
+
# @param ram [String] amount of ram
|
346
|
+
def set_cpu_and_ram(vm_name, vm_config, cpu, ram)
|
347
|
+
|
348
|
+
ram_in_gb = (ram / 1024.0)
|
349
|
+
|
350
|
+
# round evertything that bigger that 1
|
351
|
+
if ram_in_gb >= 1
|
352
|
+
ram_in_gb = ram_in_gb.round
|
353
|
+
end
|
354
|
+
|
355
|
+
log_info_light("#{vm_name}: #{ram_in_gb}Gb RAM, #{cpu} CPU")
|
356
|
+
|
357
|
+
vm_config.vm.provider "virtualbox" do |v|
|
358
|
+
|
359
|
+
v.linked_clone = false
|
360
|
+
|
361
|
+
v.memory = ram
|
362
|
+
v.cpus = cpu
|
363
|
+
|
364
|
+
v.gui = false
|
365
|
+
|
366
|
+
v.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
|
367
|
+
v.customize ["modifyvm", :id, "--vram", 32]
|
368
|
+
|
369
|
+
v.customize ["modifyvm", :id, "--audio", "none"]
|
370
|
+
v.customize ["modifyvm", :id, "--usb", "off"]
|
371
|
+
|
372
|
+
# if Vagrant::VERSION >= '2.2.3'
|
373
|
+
# # Vagrant has detected a configuration issue which exposes a vulnerability with the installed version of VirtualBox
|
374
|
+
# # Ensure the guest is trusted to use this configuration or update the NIC type using one of the methods below:
|
375
|
+
# # https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
|
376
|
+
|
377
|
+
# v.default_nic_type = "82543GC"
|
378
|
+
# end
|
379
|
+
|
380
|
+
# https://github.com/hashicorp/vagrant/issues/6812#issuecomment-171981576
|
381
|
+
# Vagrant is reconnecting from scratch, sometimes literally before each command in negotiating loop
|
382
|
+
v.customize ['modifyvm', :id, "--natdnshostresolver1", "off"]
|
383
|
+
end
|
384
|
+
|
385
|
+
# tracking only our own boxes
|
386
|
+
# subpoint | uplift
|
387
|
+
box_name = 'other'
|
388
|
+
box_version = 'other'
|
389
|
+
|
390
|
+
begin
|
391
|
+
box_name = vm_config.vm.box()
|
392
|
+
rescue => e
|
393
|
+
box_name = 'not_set'
|
394
|
+
end
|
395
|
+
|
396
|
+
if( box_name.to_s.downcase.start_with?('subpoint') || box_name.to_s.downcase.start_with?('uplift') )
|
397
|
+
begin
|
398
|
+
box_version = vm_config.vm.box_version()
|
399
|
+
rescue => e
|
400
|
+
box_version = 'not_set'
|
401
|
+
end
|
402
|
+
else
|
403
|
+
box_name = 'other'
|
404
|
+
box_version = 'other'
|
405
|
+
end
|
406
|
+
|
407
|
+
data = {
|
408
|
+
'vm_name': vm_name,
|
409
|
+
'cpus': cpu,
|
410
|
+
'memory': ram,
|
411
|
+
'box_name': box_name,
|
412
|
+
'box_version': box_version
|
413
|
+
}
|
414
|
+
|
415
|
+
_track_ai_event(__method__, data)
|
416
|
+
end
|
417
|
+
|
418
|
+
# Requires value to be integer
|
419
|
+
#
|
420
|
+
# @param value [object] value
|
421
|
+
def require_integer(value)
|
422
|
+
if value.is_a?(Integer) != true
|
423
|
+
log_error_and_raise("expected integer value, got #{value.class}, #{value.inspect}")
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
# Requires value to be string
|
428
|
+
#
|
429
|
+
# @param value [String] value
|
430
|
+
def require_string(value)
|
431
|
+
if value.nil? == true || value.to_s.empty?
|
432
|
+
log_error_and_raise("expected string value, got nil or empty string")
|
433
|
+
end
|
434
|
+
|
435
|
+
if value.is_a?(String) != true
|
436
|
+
log_error_and_raise("expected string value, got #{value.class}, #{value.inspect}")
|
437
|
+
end
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
# Requires value to be [Vagrant::Config::V2::Root]
|
442
|
+
#
|
443
|
+
# @param value [object] value
|
444
|
+
def require_vagrant_config(value)
|
445
|
+
if value.nil? == true
|
446
|
+
log_error_and_raise("expected string value, got nil or empty string")
|
447
|
+
end
|
448
|
+
|
449
|
+
if value.is_a?(Vagrant::Config::V2::Root) != true
|
450
|
+
log_error_and_raise("expected Vagrant::Config::V2::Root value, got #{value.class}, #{value.inspect}")
|
451
|
+
end
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
# Configures vagrant vm with the default winrm settings
|
456
|
+
#
|
457
|
+
# @param vm_name [String] vagrant vm name
|
458
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
459
|
+
def set_winrm(vm_name, vm_config)
|
460
|
+
require_string(vm_name)
|
461
|
+
require_vagrant_config(vm_config)
|
462
|
+
|
463
|
+
log_info_light("#{vm_name}: winrm config")
|
464
|
+
|
465
|
+
# https://www.vagrantup.com/docs/vagrantfile/winrm_settings.html
|
466
|
+
|
467
|
+
vm_config.vm.guest = :windows
|
468
|
+
|
469
|
+
vm_config.vm.boot_timeout = 300
|
470
|
+
|
471
|
+
vm_config.vm.communicator = "winrm"
|
472
|
+
vm_config.winrm.transport = :plaintext
|
473
|
+
vm_config.winrm.basic_auth_only = true
|
474
|
+
|
475
|
+
vm_config.winrm.ssl_peer_verification = false
|
476
|
+
|
477
|
+
vm_config.winrm.username = "vagrant"
|
478
|
+
vm_config.winrm.password = "vagrant"
|
479
|
+
end
|
480
|
+
|
481
|
+
# Disables default synced_folder for vagrant box
|
482
|
+
#
|
483
|
+
# @param vm_name [String] vagrant vm name
|
484
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
485
|
+
def set_default_synced_folder(vm_name, vm_config)
|
486
|
+
|
487
|
+
require_string(vm_name)
|
488
|
+
require_vagrant_config(vm_config)
|
489
|
+
|
490
|
+
log_info_light("#{vm_name}: synced folders config")
|
491
|
+
|
492
|
+
vm_config.vm.synced_folder ".", "/vagrant", disabled: true
|
493
|
+
end
|
494
|
+
|
495
|
+
def execute_tests?(vm_config:)
|
496
|
+
return true
|
497
|
+
end
|
498
|
+
|
499
|
+
def execute_tests(vm_config:, paths:, env: {}, privileged: false)
|
500
|
+
|
501
|
+
if !execute_tests?(vm_config: vm_config)
|
502
|
+
_log.info " - pester: skipping test execition due to false flag in properties"
|
503
|
+
return
|
504
|
+
end
|
505
|
+
|
506
|
+
if !paths.is_a?(Array)
|
507
|
+
paths = [paths]
|
508
|
+
end
|
509
|
+
|
510
|
+
paths.each do | path |
|
511
|
+
test_path_value = File.basename(path)
|
512
|
+
|
513
|
+
_log.debug " - pester test path: #{test_path_value}"
|
514
|
+
end
|
515
|
+
|
516
|
+
paths.each do |src_test_path|
|
517
|
+
|
518
|
+
test_files = Dir[src_test_path]
|
519
|
+
test_files_string = "\n - " + test_files.join("\n - ")
|
520
|
+
_log.debug " - scanned: #{src_test_path}, found: #{test_files_string}"
|
521
|
+
|
522
|
+
if test_files.empty?
|
523
|
+
_log.warn "[!] cannot find any test files under path: #{src_test_path} - mostlikely, wrong location/pattern"
|
524
|
+
end
|
525
|
+
|
526
|
+
test_files.each do |fname|
|
527
|
+
|
528
|
+
test_path_value = File.basename(fname)
|
529
|
+
|
530
|
+
_log.info " - pester test: #{test_path_value}"
|
531
|
+
_log.debug "adding test file: #{fname}"
|
532
|
+
|
533
|
+
src_path = fname
|
534
|
+
dst_path = "c:/windows/temp/tests/" + File.basename(fname)
|
535
|
+
|
536
|
+
vm_config.vm.provision :file do |file|
|
537
|
+
file.source = fname
|
538
|
+
file.destination = dst_path
|
539
|
+
end
|
540
|
+
|
541
|
+
vm_config.vm.provision "shell",
|
542
|
+
inline: "Invoke-Pester -EnableExit -Script #{dst_path}",
|
543
|
+
name: dst_path,
|
544
|
+
env: env
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
end
|
549
|
+
|
550
|
+
# Configures hostname for the vagrant box
|
551
|
+
#
|
552
|
+
# @param vm_name [String] vagrant vm name
|
553
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
554
|
+
# @param hostname [String] hostname
|
555
|
+
def set_hostname(vm_name, vm_config, hostname)
|
556
|
+
require_string(vm_name)
|
557
|
+
require_vagrant_config(vm_config)
|
558
|
+
|
559
|
+
require_string(hostname)
|
560
|
+
|
561
|
+
log_info_light("#{vm_name}: setitng hostname: #{hostname}")
|
562
|
+
vm_config.vm.hostname = hostname
|
563
|
+
end
|
564
|
+
|
565
|
+
# Configures private network for the vagrant box. Use for VMs to be promoted to domain controller.
|
566
|
+
#
|
567
|
+
# @param vm_name [String] vagrant vm name
|
568
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
569
|
+
# @param ip [String] ip value
|
570
|
+
# @param gateway [String] gateway value
|
571
|
+
def set_private_network(vm_name, vm_config, ip: '', gateway: '')
|
572
|
+
|
573
|
+
require_string(vm_name)
|
574
|
+
require_vagrant_config(vm_config)
|
575
|
+
|
576
|
+
log_info(" - ip: #{ip}, gateway: #{gateway}")
|
577
|
+
|
578
|
+
vm_config.vm.network :private_network, ip: ip, gateway: gateway
|
579
|
+
end
|
580
|
+
|
581
|
+
# Configures client network for the vagrant box. Use for VMs to be joined to domain controller.
|
582
|
+
#
|
583
|
+
# @param vm_name [String] vagrant vm name
|
584
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
585
|
+
# @param ip [String] ip value
|
586
|
+
# @param gateway [String] gateway value
|
587
|
+
def set_client_network(vm_name, vm_config, hostname)
|
588
|
+
|
589
|
+
require_string(vm_name)
|
590
|
+
require_vagrant_config(vm_config)
|
591
|
+
|
592
|
+
require_string(hostname)
|
593
|
+
|
594
|
+
network_range = get_network_range
|
595
|
+
|
596
|
+
dc_ip = "#{network_range}.5"
|
597
|
+
machine_ip = get_ip_for_host(hostname)
|
598
|
+
|
599
|
+
log_info(" - private network: ip: #{machine_ip} gateway: #{network_range}.1")
|
600
|
+
vm_config.vm.network :private_network,
|
601
|
+
ip: machine_ip, gateway: "#{network_range}.1"
|
602
|
+
|
603
|
+
log_info(" - fixing secondary network interface: ip: #{machine_ip} dns: #{dc_ip}")
|
604
|
+
vm_config.vm.provision "shell",
|
605
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.core/uplift.fix-second-network.ps1",
|
606
|
+
args: "-ip #{machine_ip} -dns #{dc_ip}"
|
607
|
+
end
|
608
|
+
|
609
|
+
# Configures private network for the vagrant box to be promoted to domain controller.
|
610
|
+
#
|
611
|
+
# @param vm_name [String] vagrant vm name
|
612
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
613
|
+
def set_private_dc_network(vm_name, vm_config)
|
614
|
+
require_string(vm_name)
|
615
|
+
require_vagrant_config(vm_config)
|
616
|
+
|
617
|
+
log_info_light("#{vm_name}: private dc network")
|
618
|
+
|
619
|
+
network_range = get_network_range
|
620
|
+
|
621
|
+
set_private_network(
|
622
|
+
vm_name,
|
623
|
+
vm_config,
|
624
|
+
:ip => "#{network_range}.5",
|
625
|
+
:gateway => "#{network_range}.1"
|
626
|
+
)
|
627
|
+
|
628
|
+
end
|
629
|
+
|
630
|
+
# Provisions box with standard config
|
631
|
+
#
|
632
|
+
# @param vm_name [String] vagrant vm name
|
633
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
634
|
+
def provision_win16_dsc_soe(vm_name, vm_config)
|
635
|
+
|
636
|
+
require_string(vm_name)
|
637
|
+
require_vagrant_config(vm_config)
|
638
|
+
|
639
|
+
log_info_light("#{vm_name}: dsc soe config")
|
640
|
+
|
641
|
+
vm_config.vm.provision "shell",
|
642
|
+
name: "soe.dsc.ps1",
|
643
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.dsc.ps1",
|
644
|
+
env: {
|
645
|
+
"UPLF_DSC_CHECK" => 1
|
646
|
+
}
|
647
|
+
|
648
|
+
execute_tests(
|
649
|
+
vm_config: vm_config,
|
650
|
+
paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/tests/soe.dsc.*"
|
651
|
+
)
|
652
|
+
end
|
653
|
+
|
654
|
+
# Provisions box with standard shortcuts
|
655
|
+
#
|
656
|
+
# @param vm_name [String] vagrant vm name
|
657
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
658
|
+
def provision_win16_dsc_shortcuts(vm_name, vm_config)
|
659
|
+
|
660
|
+
require_string(vm_name)
|
661
|
+
require_vagrant_config(vm_config)
|
662
|
+
|
663
|
+
log_info_light("#{vm_name}: dsc soe shortcuts")
|
664
|
+
|
665
|
+
vm_config.vm.provision "shell",
|
666
|
+
name: "soe.shortcuts.dsc.ps1",
|
667
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.shortcuts.dsc.ps1",
|
668
|
+
env: {
|
669
|
+
"UPLF_DSC_CHECK" => 1
|
670
|
+
}
|
671
|
+
end
|
672
|
+
|
673
|
+
# Provisions domain controller, minimal config
|
674
|
+
#
|
675
|
+
# @param vm_name [String] vagrant vm name
|
676
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
677
|
+
def provision_win16_dsc_dc(vm_name, vm_config)
|
678
|
+
|
679
|
+
require_string(vm_name)
|
680
|
+
require_vagrant_config(vm_config)
|
681
|
+
|
682
|
+
log_info(" - dc provision")
|
683
|
+
|
684
|
+
# just in case there are outstanding tasks
|
685
|
+
vm_config.vm.provision "reload"
|
686
|
+
|
687
|
+
vm_config.vm.provision "shell",
|
688
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.dsc.ps1",
|
689
|
+
name: "dc.dsc.ps1",
|
690
|
+
env: {
|
691
|
+
"UPLF_DC_DOMAIN_NAME" => "uplift.local",
|
692
|
+
"UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
|
693
|
+
"UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
|
694
|
+
|
695
|
+
"UPLF_DSC_CHECK_SKIP" => 1
|
696
|
+
}
|
697
|
+
|
698
|
+
vm_config.vm.provision "reload"
|
699
|
+
|
700
|
+
execute_tests(
|
701
|
+
vm_config: vm_config,
|
702
|
+
paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/tests/dc.dsc.*"
|
703
|
+
)
|
704
|
+
|
705
|
+
_track_ai_event(__method__, {
|
706
|
+
'vm_name': vm_name
|
707
|
+
})
|
708
|
+
end
|
709
|
+
|
710
|
+
# Provisions domain controller users, minimal config
|
711
|
+
#
|
712
|
+
# @param vm_name [String] vagrant vm name
|
713
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
714
|
+
def provision_win16_dsc_dc_users(vm_name, vm_config)
|
715
|
+
|
716
|
+
require_string(vm_name)
|
717
|
+
require_vagrant_config(vm_config)
|
718
|
+
|
719
|
+
log_info(" - domain users")
|
720
|
+
|
721
|
+
vm_config.vm.provision "shell",
|
722
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.users.dsc.ps1",
|
723
|
+
name: 'dc.users.dsc.ps1',
|
724
|
+
env: {
|
725
|
+
"UPLF_DC_DOMAIN_NAME" => "uplift",
|
726
|
+
"UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
|
727
|
+
"UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
|
728
|
+
|
729
|
+
"UPLF_VAGRANT_USER_NAME" => "vagrant",
|
730
|
+
"UPLF_VAGRANT_USER_PASSWORD" => "vagrant"
|
731
|
+
}
|
732
|
+
|
733
|
+
_track_ai_event(__method__, {
|
734
|
+
'vm_name': vm_name
|
735
|
+
})
|
736
|
+
end
|
737
|
+
|
738
|
+
# Provisions domain controller and users, minimal config
|
739
|
+
#
|
740
|
+
# @param vm_name [String] vagrant vm name
|
741
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
742
|
+
def provision_dc16(vm_name, vm_config)
|
743
|
+
|
744
|
+
require_string(vm_name)
|
745
|
+
require_vagrant_config(vm_config)
|
746
|
+
|
747
|
+
log_info_light("#{vm_name}: domain controller setup")
|
748
|
+
|
749
|
+
provision_win16_dsc_dc(vm_name, vm_config)
|
750
|
+
provision_win16_dsc_dc_users(vm_name, vm_config)
|
751
|
+
|
752
|
+
_track_ai_event(__method__, {
|
753
|
+
'vm_name': vm_name
|
754
|
+
})
|
755
|
+
end
|
756
|
+
|
757
|
+
# Provisions domain join for the giving box
|
758
|
+
#
|
759
|
+
# @param vm_name [String] vagrant vm name
|
760
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
761
|
+
def provision_dc_join(vm_name, vm_config)
|
762
|
+
|
763
|
+
require_string(vm_name)
|
764
|
+
require_vagrant_config(vm_config)
|
765
|
+
|
766
|
+
log_info_light("#{vm_name}: domain join")
|
767
|
+
|
768
|
+
network_range = get_network_range
|
769
|
+
dc_ip = "#{network_range}.5"
|
770
|
+
|
771
|
+
log_info(" - dc_ip: #{dc_ip}")
|
772
|
+
|
773
|
+
vm_config.vm.provision "shell",
|
774
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.dsc.ps1",
|
775
|
+
env: {
|
776
|
+
"UPLF_DC_DOMAIN_NAME" => "uplift",
|
777
|
+
|
778
|
+
"UPLF_DC_JOIN_USER_NAME" => "admin",
|
779
|
+
"UPLF_DC_JOIN_USER_PASSWORD" => "uplift!QAZ",
|
780
|
+
|
781
|
+
"UPLF_DC_DOMAIN_HOST_IP" => "#{dc_ip}"
|
782
|
+
}
|
783
|
+
|
784
|
+
vm_config.vm.provision "reload"
|
785
|
+
|
786
|
+
vm_config.vm.provision "shell",
|
787
|
+
name: "dc.join.hostname.ps1",
|
788
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.hostname.ps1"
|
789
|
+
|
790
|
+
_track_ai_event(__method__, {
|
791
|
+
'vm_name': vm_name
|
792
|
+
})
|
793
|
+
end
|
794
|
+
|
795
|
+
# Provisions SharePoint 2016 pre-setup, prepares box for SharePoint 2016 setup.
|
796
|
+
#
|
797
|
+
# @param vm_name [String] vagrant vm name
|
798
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
799
|
+
def provision_sp16_pre_setup(vm_name, vm_config)
|
800
|
+
|
801
|
+
require_string(vm_name)
|
802
|
+
require_vagrant_config(vm_config)
|
803
|
+
|
804
|
+
log_info_light("#{vm_name}: SharePoint 2016: farm pre-setup")
|
805
|
+
|
806
|
+
# shared scripts
|
807
|
+
vm_config.vm.provision "file",
|
808
|
+
source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
|
809
|
+
destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
|
810
|
+
|
811
|
+
# presetup sharepoint farm
|
812
|
+
# - fix iss
|
813
|
+
# - reboot
|
814
|
+
# - restore all services
|
815
|
+
vm_config.vm.provision "shell",
|
816
|
+
name: 'sp-pre_setup1',
|
817
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup1.dsc.ps1"
|
818
|
+
|
819
|
+
vm_config.vm.provision "reload"
|
820
|
+
|
821
|
+
vm_config.vm.provision "shell",
|
822
|
+
name: 'sp-pre_setup2',
|
823
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup2.dsc.ps1"
|
824
|
+
|
825
|
+
_track_ai_event(__method__, {
|
826
|
+
'vm_name': vm_name
|
827
|
+
})
|
828
|
+
end
|
829
|
+
|
830
|
+
# Prepares box for SharePoint 2016 setup.
|
831
|
+
# Ensures CredSSP configs and other box-wide changes
|
832
|
+
# Normally, should be already done under packer image, this is more of a shortcut for non-uplift boxes
|
833
|
+
|
834
|
+
# @param vm_name [String] vagrant vm name
|
835
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
836
|
+
def provision_sp16_image_setup(vm_name, vm_config)
|
837
|
+
require_string(vm_name)
|
838
|
+
require_vagrant_config(vm_config)
|
839
|
+
|
840
|
+
log_info_light("#{vm_name}: SharePoint 2016: image setup")
|
841
|
+
|
842
|
+
vm_config.vm.provision "shell",
|
843
|
+
name: 'image-setup',
|
844
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1"
|
845
|
+
|
846
|
+
vm_config.vm.provision "reload"
|
847
|
+
|
848
|
+
vm_config.vm.provision "shell",
|
849
|
+
name: 'image-setup-dsc-check',
|
850
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1",
|
851
|
+
env: {
|
852
|
+
"UPLF_DSC_CHECK" => 1
|
853
|
+
}
|
854
|
+
|
855
|
+
_track_ai_event(__method__, {
|
856
|
+
'vm_name': vm_name
|
857
|
+
})
|
858
|
+
end
|
859
|
+
|
860
|
+
# Installs required packages for for SharePoint 2016 setup.
|
861
|
+
# Normally, should be already done under packer image, this is more of a shortcut for non-uplift boxes
|
862
|
+
#
|
863
|
+
# @param vm_name [String] vagrant vm name
|
864
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
865
|
+
def provision_sp16_image_packages_setup(vm_name, vm_config)
|
866
|
+
require_string(vm_name)
|
867
|
+
require_vagrant_config(vm_config)
|
868
|
+
|
869
|
+
log_info_light("#{vm_name}: SharePoint 2016: image setup")
|
870
|
+
|
871
|
+
vm_config.vm.provision "shell",
|
872
|
+
name: 'image-packages-setup',
|
873
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/_sp2013_image_packages.dsc.ps1"
|
874
|
+
|
875
|
+
_track_ai_event(__method__, {
|
876
|
+
'vm_name': vm_name
|
877
|
+
})
|
878
|
+
end
|
879
|
+
|
880
|
+
# Prepares SharePoint 2016 setup accounts
|
881
|
+
# https://absolute-sharepoint.com/2017/03/sharepoint-2016-service-accounts-recommendations.html
|
882
|
+
#
|
883
|
+
# @param vm_name [String] vagrant vm name
|
884
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
885
|
+
def provision_sp16_sp_accounts(vm_name, vm_config)
|
886
|
+
require_string(vm_name)
|
887
|
+
require_vagrant_config(vm_config)
|
888
|
+
|
889
|
+
log_info_light("#{vm_name}: SharePoint 2016: image setup")
|
890
|
+
|
891
|
+
vm_config.vm.provision "shell",
|
892
|
+
name: 'sp-accounts-setup',
|
893
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1",
|
894
|
+
env: {
|
895
|
+
"UPLF_DSC_CHECK" => 1
|
896
|
+
}
|
897
|
+
|
898
|
+
_track_ai_event(__method__, {
|
899
|
+
'vm_name': vm_name
|
900
|
+
})
|
901
|
+
end
|
902
|
+
|
903
|
+
# Prepares SharePoint 2016 accounts required for SQL
|
904
|
+
#
|
905
|
+
# @param vm_name [String] vagrant vm name
|
906
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
907
|
+
def provision_sp16_sql_accounts(vm_name, vm_config)
|
908
|
+
require_string(vm_name)
|
909
|
+
require_vagrant_config(vm_config)
|
910
|
+
|
911
|
+
log_info_light("#{vm_name}: SharePoint 2016: image setup")
|
912
|
+
|
913
|
+
vm_config.vm.provision "shell",
|
914
|
+
name: 'sp-sql-accounts-setup',
|
915
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1",
|
916
|
+
env: {
|
917
|
+
"UPLF_DSC_CHECK" => 1
|
918
|
+
}
|
919
|
+
|
920
|
+
_track_ai_event(__method__, {
|
921
|
+
'vm_name': vm_name
|
922
|
+
})
|
923
|
+
end
|
924
|
+
|
925
|
+
# Provisions SharePoint 2016 post-setup, ensures all services work
|
926
|
+
#
|
927
|
+
# @param vm_name [String] vagrant vm name
|
928
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
929
|
+
def provision_sp16_farm_post_setup(vm_name, vm_config)
|
930
|
+
|
931
|
+
require_string(vm_name)
|
932
|
+
require_vagrant_config(vm_config)
|
933
|
+
|
934
|
+
log_info_light("#{vm_name}: SharePoint 2016: farm post-setup")
|
935
|
+
|
936
|
+
vm_config.vm.provision "shell",
|
937
|
+
name: 'sp-post-setup',
|
938
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.post_setup.dsc.ps1"
|
939
|
+
|
940
|
+
_track_ai_event(__method__, {
|
941
|
+
'vm_name': vm_name
|
942
|
+
})
|
943
|
+
end
|
944
|
+
|
945
|
+
# Provisions SharePoint 2016 information gatherer
|
946
|
+
#
|
947
|
+
# @param vm_name [String] vagrant vm name
|
948
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
949
|
+
def provision_sp16_print_info(vm_name, vm_config)
|
950
|
+
|
951
|
+
require_string(vm_name)
|
952
|
+
require_vagrant_config(vm_config)
|
953
|
+
|
954
|
+
log_info_light("#{vm_name}: SharePoint 2016: print info")
|
955
|
+
|
956
|
+
vm_config.vm.provision "shell",
|
957
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.info.ps1"
|
958
|
+
|
959
|
+
_track_ai_event(__method__, {
|
960
|
+
'vm_name': vm_name
|
961
|
+
})
|
962
|
+
end
|
963
|
+
|
964
|
+
# Provisions SharePoint 2016 SingleServerFarm using SPFarm DSC
|
965
|
+
#
|
966
|
+
# @param vm_name [String] vagrant vm name
|
967
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
968
|
+
# @param sql_server [String] sql server host name
|
969
|
+
# @param farm_prefix [String] sql server DBs prefix to use for the current SharePoint farm install
|
970
|
+
def provision_sp16_single_server_farm(vm_name, vm_config, sql_server, farm_prefix = nil, dsc_verbose: '1')
|
971
|
+
|
972
|
+
if farm_prefix.nil?
|
973
|
+
farm_prefix = "#{vm_name}_"
|
974
|
+
end
|
975
|
+
|
976
|
+
require_string(vm_name)
|
977
|
+
require_vagrant_config(vm_config)
|
978
|
+
|
979
|
+
require_string(sql_server)
|
980
|
+
require_string(farm_prefix)
|
981
|
+
|
982
|
+
log_info_light("#{vm_name}: SharePoint 2016: farm creation only")
|
983
|
+
|
984
|
+
# shared scripts
|
985
|
+
vm_config.vm.provision "file",
|
986
|
+
source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
|
987
|
+
destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
|
988
|
+
|
989
|
+
env = {
|
990
|
+
"UPLF_sp_farm_sql_server_host_name" => sql_server,
|
991
|
+
"UPLF_sp_farm_sql_db_prefix" => "#{farm_prefix}_",
|
992
|
+
"UPLF_sp_farm_passphrase" => "uplift!QAZ",
|
993
|
+
|
994
|
+
"UPLF_sp_setup_user_name" => "uplift\\vagrant",
|
995
|
+
"UPLF_sp_setup_user_password" => "vagrant",
|
996
|
+
"UPLF_DSC_VERBOSE" => dsc_verbose
|
997
|
+
}
|
998
|
+
|
999
|
+
vm_config.vm.provision "shell",
|
1000
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.farm-only.dsc.ps1",
|
1001
|
+
env: env
|
1002
|
+
|
1003
|
+
_track_ai_event(__method__, {
|
1004
|
+
'vm_name': vm_name
|
1005
|
+
})
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
# Provisions SharePoint 2016 minimal services: taxonomy, secure store, state service, search, user profile service and others
|
1009
|
+
#
|
1010
|
+
# @param vm_name [String] vagrant vm name
|
1011
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
1012
|
+
# @param sql_server [String] sql server host name
|
1013
|
+
# @param farm_prefix [String] sql server DBs prefix to use for the current SharePoint farm install
|
1014
|
+
def provision_sp16_minimal_services(vm_name, vm_config, sql_server, farm_prefix = nil, dsc_verbose: '1', dsc_check: '1')
|
1015
|
+
|
1016
|
+
if farm_prefix.nil?
|
1017
|
+
farm_prefix = "#{vm_name}_"
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
require_string(vm_name)
|
1021
|
+
require_vagrant_config(vm_config)
|
1022
|
+
|
1023
|
+
require_string(sql_server)
|
1024
|
+
require_string(farm_prefix)
|
1025
|
+
|
1026
|
+
log_info_light("#{vm_name}: SharePoint 2016: minimal services: taxonomy, secure store, state service, search, user profile service")
|
1027
|
+
|
1028
|
+
# shared scripts
|
1029
|
+
vm_config.vm.provision "file",
|
1030
|
+
source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
|
1031
|
+
destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
|
1032
|
+
|
1033
|
+
env = {
|
1034
|
+
"UPLF_sp_farm_sql_server_host_name" => sql_server,
|
1035
|
+
"UPLF_sp_farm_sql_db_prefix" => "#{farm_prefix}_",
|
1036
|
+
|
1037
|
+
"UPLF_sp_setup_user_name" => "uplift\\vagrant",
|
1038
|
+
"UPLF_sp_setup_user_password" => "vagrant",
|
1039
|
+
|
1040
|
+
"UPLF_DSC_VERBOSE" => dsc_verbose,
|
1041
|
+
"UPLF_DSC_CHECK" => dsc_check,
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
vm_config.vm.provision "shell",
|
1045
|
+
name: 'sp-minimal-services',
|
1046
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.farm-minimal-services.dsc.ps1",
|
1047
|
+
env: env
|
1048
|
+
|
1049
|
+
execute_tests(
|
1050
|
+
vm_config: vm_config,
|
1051
|
+
paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/tests/sp2016.minimal-services.Tests.ps1"
|
1052
|
+
)
|
1053
|
+
|
1054
|
+
_track_ai_event(__method__, {
|
1055
|
+
'vm_name': vm_name
|
1056
|
+
})
|
1057
|
+
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
def provision_sp16_web_application(vm_name, vm_config, dsc_verbose: '1', dsc_check: '1')
|
1061
|
+
|
1062
|
+
require_string(vm_name)
|
1063
|
+
require_vagrant_config(vm_config)
|
1064
|
+
|
1065
|
+
env = {
|
1066
|
+
"UPLF_SP_SETUP_USER_NAME" => "uplift\\vagrant",
|
1067
|
+
"UPLF_SP_SETUP_USER_PASSWORD" => "vagrant",
|
1068
|
+
|
1069
|
+
"UPLF_DSC_VERBOSE" => dsc_verbose,
|
1070
|
+
"UPLF_DSC_CHECK" => dsc_check,
|
1071
|
+
|
1072
|
+
"UPLF_SP_WEB_APP_PORT" => "80"
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
vm_config.vm.provision "shell",
|
1076
|
+
name: 'sp-web-application',
|
1077
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.web-application.dsc.ps1",
|
1078
|
+
env: env
|
1079
|
+
end
|
1080
|
+
|
1081
|
+
# Completes SQL Server image
|
1082
|
+
#
|
1083
|
+
# @param vm_name [String] vagrant vm name
|
1084
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
1085
|
+
def provision_sql16_complete_image(vm_name, vm_config)
|
1086
|
+
|
1087
|
+
require_string(vm_name)
|
1088
|
+
require_vagrant_config(vm_config)
|
1089
|
+
|
1090
|
+
log_info_light("#{vm_name}: SQL 2016: image completion")
|
1091
|
+
|
1092
|
+
vm_config.vm.provision "shell",
|
1093
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.complete.dsc.ps1"
|
1094
|
+
|
1095
|
+
execute_tests(
|
1096
|
+
vm_config: vm_config,
|
1097
|
+
paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/tests/sql16.dsc.*"
|
1098
|
+
)
|
1099
|
+
|
1100
|
+
_track_ai_event(__method__, {
|
1101
|
+
'vm_name': vm_name
|
1102
|
+
})
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
# Provisions SQL server optimization
|
1106
|
+
# Sets min/max memory and other tweaks
|
1107
|
+
#
|
1108
|
+
# @param vm_name [String] vagrant vm name
|
1109
|
+
# @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
|
1110
|
+
# @param min_memory [String] min memory, default 1024
|
1111
|
+
# @param max_memory [String] max memory, default 4096
|
1112
|
+
def provision_sql16_optimize(vm_name, vm_config,
|
1113
|
+
min_memory: 1024, max_memory: 4096, instance_name: 'MSSQLSERVER',
|
1114
|
+
dsc_verbose: '1', dsc_check: '1' )
|
1115
|
+
|
1116
|
+
require_string(vm_name)
|
1117
|
+
require_vagrant_config(vm_config)
|
1118
|
+
|
1119
|
+
log_info_light("#{vm_name}: SQL 2016: optimization")
|
1120
|
+
|
1121
|
+
vm_config.vm.provision "shell",
|
1122
|
+
path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.optimize.dsc.ps1",
|
1123
|
+
env: {
|
1124
|
+
"UPLF_SQL_SERVER_NAME" => vm_name,
|
1125
|
+
"UPLF_SQL_INSTANCE_NAME" => instance_name,
|
1126
|
+
"UPLF_SQL_MIN_MEMORY" => min_memory,
|
1127
|
+
"UPLF_SQL_MAX_MEMORY" => max_memory,
|
1128
|
+
|
1129
|
+
"UPLF_DSC_VERBOSE" => dsc_verbose,
|
1130
|
+
"UPLF_DSC_CHECK" => dsc_check,
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
_track_ai_event(__method__, {
|
1134
|
+
'vm_name': vm_name
|
1135
|
+
})
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
private
|
1139
|
+
|
1140
|
+
def _logger
|
1141
|
+
@@logger = @@logger || VagrantPlugins::Uplift::Log.get_logger
|
1142
|
+
@@logger
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
def _ai_client
|
1146
|
+
ai_key = ENV['UPLF_APPINSIGHTS_KEY'] || 'c297a2cc-8194-46ac-bf6b-46edd4c7d2c9'
|
1147
|
+
|
1148
|
+
@@ai_client = @@ai_client || VagrantPlugins::Uplift::AppInsights.get_client(ai_key)
|
1149
|
+
@@ai_client
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
def _log
|
1153
|
+
_logger
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
def _is_privileged_shell?
|
1157
|
+
# https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
|
1158
|
+
# https://github.com/clong/DetectionLab/issues/172
|
1159
|
+
|
1160
|
+
result = Vagrant::VERSION < '2.2.1'
|
1161
|
+
|
1162
|
+
log_debug "_is_privileged_shell: #{result}"
|
1163
|
+
|
1164
|
+
result
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
def _is_powershell_elevated_interactive?
|
1168
|
+
# https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
|
1169
|
+
# https://github.com/clong/DetectionLab/issues/172
|
1170
|
+
|
1171
|
+
result = Vagrant::VERSION < '2.2.1'
|
1172
|
+
|
1173
|
+
# join to dc issue
|
1174
|
+
# workgroup 'WORKGROUP' with following error message: Unable to update the password. The value
|
1175
|
+
# Computer 'WIN-SN2UMLHU29M' failed to join domain 'uplift' from its current workgroup 'WORKGROUP' with following error message: Unable to update the password.
|
1176
|
+
# The value provided as the current password is incorrect.
|
1177
|
+
|
1178
|
+
# http://www.gi-architects.co.uk/2017/01/powershell-add-computer-error-when-executed-remotely/
|
1179
|
+
|
1180
|
+
log_debug "is_powershell_elevated_interactive: #{result}"
|
1181
|
+
|
1182
|
+
result
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
def _track_first_initialize()
|
1186
|
+
path = File.expand_path(@@config_file_path)
|
1187
|
+
FileUtils.mkdir_p path
|
1188
|
+
|
1189
|
+
first_initialize_file = "#{@@config_file_path}/.appinsights-first-init-#{@@plugin_version}"
|
1190
|
+
|
1191
|
+
if(File.exist?(first_initialize_file) == false)
|
1192
|
+
log_debug("AppInsight: tracking first initialize event")
|
1193
|
+
track_ai_event('initialize')
|
1194
|
+
|
1195
|
+
File.open(first_initialize_file, "w") do |f|
|
1196
|
+
f.write("ok")
|
1197
|
+
end
|
1198
|
+
end
|
1199
|
+
end
|
1200
|
+
|
1201
|
+
def _track_ai_event(name, properties = {})
|
1202
|
+
uplift_vagrant_event = 'uplift-vagrant.func'
|
1203
|
+
|
1204
|
+
log_debug("AppInsight: tracking event: #{name}")
|
1205
|
+
_ai_client.track_event(
|
1206
|
+
uplift_vagrant_event,
|
1207
|
+
properties.merge(_get_default_ai_properties(name))
|
1208
|
+
)
|
1209
|
+
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
def _get_default_ai_properties(name)
|
1213
|
+
{
|
1214
|
+
'plugin_version' => @@plugin_version,
|
1215
|
+
'success' => true,
|
1216
|
+
'ruby_platform' => RUBY_PLATFORM,
|
1217
|
+
'vagrant_version' => Vagrant::VERSION,
|
1218
|
+
'config_id' => @@ai_config_id,
|
1219
|
+
'name' => name
|
1220
|
+
}
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
end
|
1224
|
+
|
1225
|
+
def self.Config
|
1226
|
+
return UpliftConfigBuilder.new
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
end
|