-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovision_sqlserver.ps1
More file actions
238 lines (200 loc) · 7.68 KB
/
provision_sqlserver.ps1
File metadata and controls
238 lines (200 loc) · 7.68 KB
1
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
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
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
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
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
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Copyright (c) 2017 by Delphix. All rights reserved.
#
# Program Name : provision_sqlserver.ps1
# Description : Delphix PowerShell API provision VDB Example
# Author : Alan Bitterman
# Created : 2017-11-15
# Version : v1.1
#
# Requirements :
# 1.) curl command line executable and ConvertFrom-Json Commandlet
# 2.) Populate Delphix Engine Connection Information . .\delphix_engine_conf.ps1
# 3.) Include Delphix Functions . .\delphixFunctions.ps1
# 4.) Change values below as required
#
# Usage: . .\provision_sqlserver.ps1
#
#########################################################
# DELPHIX CORP #
# Please make changes to the parameters below as req'd! #
#########################################################
#########################################################
## Parameter Initialization ...
. .\delphix_engine_conf.ps1
#
# Required for Provisioning Virtual Database ...
#
$SOURCE_SID="delphixdb" # dSource name used to get db container reference value
$VDB_NAME="Vdelphixdb" # Delphix VDB Name
$TARGET_GRP="Windows_Target" # Delphix Engine Group Name
$TARGET_ENV="Windows Host" # Target Environment used to get repository reference value
$TARGET_REP="MSSQLSERVER" # Target Environment Repository / Instance name
#########################################################
# NO CHANGES REQUIRED BELOW THIS POINT #
#########################################################
#########################################################
## Local Functions ...
. .\delphixFunctions.ps1
#########################################################
## Authentication ...
Write-Output "Authenticating on ${BaseURL} ... ${nl}"
$results=RestSession "${DMUSER}" "${DMPASS}" "${BaseURL}" "${COOKIE}" "${CONTENT_TYPE}"
#Write-Output "${nl} Results are ${results} ..."
Write-Output "Login Successful ..."
#########################################################
## API Version ...
$apival=Get_APIVAL "${BaseURL}" "${COOKIE}" "${CONTENT_TYPE}"
Write-Output "API Version: ${apival} "
#########################################################
## Get Group Reference ...
#Write-Output "${nl}Calling Group API ...${nl}"
$results = (curl.exe --insecure -sX GET -k ${BaseURL}/group -b "${COOKIE}" -H "${CONTENT_TYPE}")
$status = ParseStatus "${results}" "${ignore}"
#Write-Output "Group API Results: ${results}"
#
# Convert Results String to JSON Object and Get Results Status ...
#
$o = ConvertFrom-Json $results
$a = $o.result
$b = $a | where { $_.name -eq "${TARGET_GRP}" } | Select-Object
$GROUP_REFERENCE=$b.reference
Write-Output "group reference: ${GROUP_REFERENCE}"
#########################################################
## Get database container ...
#Write-Output "${nl}Calling Database API ...${nl}"
$results = (curl.exe --insecure -sX GET -k ${BaseURL}/database -b "${COOKIE}" -H "${CONTENT_TYPE}")
$status = ParseStatus "${results}" "${ignore}"
#Write-Output "Database API Results: ${results}"
#
# Convert Results String to JSON Object and Get Results Status ...
#
$o = ConvertFrom-Json $results
$a = $o.result
$b = $a | where { $_.name -eq "${SOURCE_SID}" -and $_.type -eq "MSSqlDatabaseContainer"} | Select-Object
$CONTAINER_REFERENCE=$b.reference
Write-Output "container reference: ${CONTAINER_REFERENCE}"
#########################################################
## Get Environment reference ...
#Write-Output "${nl}Calling environment API ...${nl}"
$results = (curl.exe --insecure -sX GET -k ${BaseURL}/environment -b "${COOKIE}" -H "${CONTENT_TYPE}")
$status = ParseStatus "${results}" "${ignore}"
#Write-Output "environment API Results: ${results}"
$o = ConvertFrom-Json $results
$a = $o.result
$b = $a | where { $_.name -eq "${TARGET_ENV}" } | Select-Object
$ENV_REFERENCE=$b.reference
Write-Output "env reference: ${ENV_REFERENCE}"
#########################################################
## Get Repository reference ...
#Write-Output "${nl}Calling repository API ...${nl}"
$results = (curl.exe --insecure -sX GET -k ${BaseURL}/repository -b "${COOKIE}" -H "${CONTENT_TYPE}")
$status = ParseStatus "${results}" "${ignore}"
#Write-Output "repository API Results: ${results}"
#
# Convert Results String to JSON Object and Get Results Status ...
#
$o = ConvertFrom-Json $results
$a = $o.result
$b = $a | where { $_.name -eq "${TARGET_REP}" -and $_.environment -eq "${ENV_REFERENCE}"} | Select-Object
$REP_REFERENCE=$b.reference
Write-Output "repository reference: ${REP_REFERENCE}"
#########################################################
## Provision a SQL Server Database ...
$json = @"
{
\"type\": \"MSSqlProvisionParameters\",
\"container\": {
\"type\": \"MSSqlDatabaseContainer\",
\"name\": \"${VDB_NAME}\",
\"group\": \"${GROUP_REFERENCE}\",
\"sourcingPolicy\": {
\"type\": \"SourcingPolicy\",
\"loadFromBackup\": false,
\"logsyncEnabled\": false
},
\"validatedSyncMode\": \"TRANSACTION_LOG\"
},
\"source\": {
\"type\": \"MSSqlVirtualSource\",
"@
#
# Auto Restart Option starting with API Version 1.8.x ...
#
if ( $apival -gt 180 ) {
$json = @"
${json}
\"allowAutoVDBRestartOnHostReboot\": false,
"@
}
#
# Continue to build JSON string ...
#
$json1 = @"
${json}
\"operations\": {
\"type\": \"VirtualSourceOperations\",
\"configureClone\": [],
\"postRefresh\": [],
\"postRollback\": [],
\"postSnapshot\": [],
\"preRefresh\": [],
\"preSnapshot\": []
}
},
\"sourceConfig\": {
\"type\": \"MSSqlSIConfig\",
\"linkingEnabled\": false,
\"repository\": \"${REP_REFERENCE}\",
\"databaseName\": \"${VDB_NAME}\",
\"recoveryModel\": \"SIMPLE\",
\"instance\": {
\"type\": \"MSSqlInstanceConfig\",
\"host\": \"${ENV_REFERENCE}\"
}
},
\"timeflowPointParameters\": {
\"type\": \"TimeflowPointSemantic\",
\"container\": \"${CONTAINER_REFERENCE}\",
\"location\": \"LATEST_SNAPSHOT\"
}
}
"@
Write-Output "JSON: $json1"
#
# NOTE: the above JSON does change with the upcomming Delphix J release API Version 1.9.0?
#
#Write-Output "${nl}Calling database provision API ...${nl}"
$results = (curl.exe --insecure -sX POST -k ${BaseURL}/database/provision -b "${COOKIE}" -H "${CONTENT_TYPE}" -d "${json1}")
$status = ParseStatus "${results}" "${ignore}"
Write-Output "database provision API Results: ${results}"
#
# Convert Results String to JSON Object and Get Results Status ...
#
$o = ConvertFrom-Json $results
$JOB=$o.job
Write-Output "Job # ${JOB}"
#
# Allow job to submit internally before while loop ...
#
sleep 1
Monitor_JOB "$BaseURL" "$COOKIE" "$CONTENT_TYPE" "$JOB"
############## E O F ####################################
## Clean up and Done ...
Remove-Variable -Name * -ErrorAction SilentlyContinue
Write-Output " "
Write-Output "Done ..."
Write-Output " "
exit 0