Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit bbf2702

Browse files
committed
Initial commit
Signed-off-by: Chris Wahl <github@wahlnetwork.com>
0 parents  commit bbf2702

15 files changed

+720
-0
lines changed

.build.ps1

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
param (
2+
# Path to the environment JSON file used to identify the vCenter and Rubrik servers
3+
[Parameter(Mandatory=$true)]
4+
[ValidateScript({Test-Path $_})]
5+
[String]$EnvironmentFile,
6+
# Path to the configuration JSON file used to describe the applications being tested
7+
[Parameter(Mandatory=$true)]
8+
[ValidateScript({Test-Path $_})]
9+
[String]$ConfigFile,
10+
# Path to the folder that contains XML credential files for this build
11+
[Parameter(Mandatory=$true)]
12+
[ValidateScript({Test-Path $_})]
13+
[String]$IdentityPath
14+
)
15+
16+
# Synopsis: Pull configuration details from the root config.json file
17+
task GetConfig {
18+
$script:Environment = Get-Content -Path $EnvironmentFile | ConvertFrom-Json
19+
$script:Config = Get-Content -Path $ConfigFile | ConvertFrom-Json
20+
# If a trailing backslash is omitted, this will make sure it's added to correct for future path + filename activities
21+
if ($IdentityPath.Substring($IdentityPath.Length - 1) -ne '\') {
22+
$script:IdentityPath += '\'
23+
}
24+
}
25+
26+
# Synopsis: Establish connectivity to a Rubrik Cluster
27+
task ConnectRubrik {
28+
$Credential = Import-Clixml -Path ($IdentityPath + $Environment.rubrikCred)
29+
$null = Connect-Rubrik -Server $Environment.rubrikServer -Credential $Credential
30+
Write-Verbose -Message "Rubrik Status: Connected to $($rubrikConnection.server)" -Verbose
31+
}
32+
33+
# Synopsis: Establish connectivity to a VMware vCenter Server
34+
task ConnectVMware {
35+
$Credential = Import-Clixml -Path ($IdentityPath + $Environment.vmwareCred)
36+
$null = Connect-VIServer -Server $Environment.vmwareServer -Credential $Credential
37+
Write-Verbose -Message "VMware Status: Connected to $($global:DefaultVIServer.Name)" -Verbose
38+
}
39+
40+
# Synopsis: Create a Live Mount of the intended virtual machine(s)
41+
task CreateLiveMount {
42+
$i = 0
43+
# Uses a null array of Mount IDs that will be used to track the request process
44+
[Array]$Script:MountArray = $null
45+
foreach ($VM in $Config.virtualMachines) {
46+
# The resulting Live Mount has the network interface disabled
47+
$MountRequest = Get-RubrikVM $VM.name | Get-RubrikSnapshot -Date (Get-Date) | New-RubrikMount -MountName $VM.mountName -PowerOn -DisableNetwork $true -Confirm:$false
48+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Request Created: $($MountRequest.id)" -Verbose
49+
$Script:MountArray += $MountRequest
50+
$i++
51+
}
52+
}
53+
54+
# Synopsis: Validate the health of the Live Mount request and power state
55+
task ValidateLiveMount {
56+
$i = 0
57+
foreach ($Mount in $MountArray) {
58+
while ($true) {
59+
$ValidateRequest = (Get-RubrikRequest -id $Mount.id -Type vmware/vm).status
60+
$ValidatePowerOn = (Get-VM -Name $Config.virtualMachines[$i].mountName -ErrorAction:SilentlyContinue).PowerState
61+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Status: Request is $ValidateRequest, PowerState is $ValidatePowerOn" -Verbose
62+
if ($ValidateRequest -ne 'SUCCEEDED' -or $ValidatePowerOn -ne 'PoweredOn') {
63+
Start-Sleep 5
64+
}
65+
else {
66+
break
67+
}
68+
}
69+
$i++
70+
}
71+
}
72+
73+
# Synopsis: Validate the health of the Live Mount VMware Tools
74+
task ValidateLiveMountTools {
75+
$i = 0
76+
foreach ($Mount in $MountArray) {
77+
while ($true) {
78+
$ValidateTools = (Get-VM -Name $Config.virtualMachines[$i].mountName).ExtensionData.Guest.ToolsRunningStatus
79+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) VMware Tools Status: $ValidateTools" -Verbose
80+
if ($ValidateTools -ne 'guestToolsRunning') {
81+
Start-Sleep 5
82+
}
83+
else {
84+
break
85+
}
86+
}
87+
$i++
88+
}
89+
}
90+
91+
# Synopsis: Move a Live Mount to a test network
92+
task MoveLiveMountNetwork {
93+
$i = 0
94+
foreach ($Mount in $MountArray) {
95+
$ValidateNetwork = Get-NetworkAdapter -VM $Config.virtualMachines[$i].mountName | Set-NetworkAdapter `
96+
-NetworkName $Config.virtualMachines[$i].testNetwork `
97+
-Connected:$true `
98+
-Confirm:$false
99+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Network Status: $($ValidateNetwork.NetworkName) is $($ValidateNetwork.ConnectionState)" -Verbose
100+
$i++
101+
}
102+
}
103+
104+
# Synopsis: Move a Live Mount to a test address
105+
task MoveLiveMountNetworkAddress {
106+
$i = 0
107+
foreach ($Mount in $MountArray) {
108+
# Keeping the guest credential value local since it may only apply to the individual virtual machine in some cases
109+
$GuestCredential = Import-Clixml -Path ($IdentityPath + $($Config.virtualMachines[$i].guestCred))
110+
$splat = @{
111+
ScriptText = 'Get-NetAdapter | where {$_.Status -eq "Up"} | New-NetIPAddress -IPAddress ' + $Config.virtualMachines[$i].testIp + ' -PrefixLength 24 -DefaultGateway ' + $Config.virtualMachines[$i].testGateway
112+
ScriptType = 'PowerShell'
113+
VM = $Config.virtualMachines[$i].mountName
114+
GuestCredential = $GuestCredential
115+
}
116+
$null = Invoke-VMScript @splat -ErrorAction Stop
117+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Network Address Status: Assigned to $($Config.virtualMachines[$i].testIp)" -Verbose
118+
$i++
119+
}
120+
}
121+
122+
# Synopsis: Validate the Live Mount against one or more tests to verify the backup copy is operational
123+
task LiveMountTest {
124+
$i = 0
125+
foreach ($Mount in $MountArray) {
126+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Test Status: Loading the following tests - $($Config.virtualMachines[$i].tasks)" -Verbose
127+
# Keeping the guest credential value local since it may only apply to the individual virtual machine in some cases
128+
# Not all tests will need a guest credential, but it's there in case required
129+
$GuestCredential = Import-Clixml -Path ($IdentityPath + $($Config.virtualMachines[$i].guestCred))
130+
Invoke-Build -File .\tests.ps1 -Task $Config.virtualMachines[$i].tasks -Config $Config.virtualMachines[$i] -GuestCredential $GuestCredential
131+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Test Status: Testing complete" -Verbose
132+
$i++
133+
}
134+
}
135+
136+
# Synopsis: Remove any remaining Live Mount artifacts
137+
task Cleanup {
138+
$i = 0
139+
foreach ($Mount in $MountArray) {
140+
# The request may take a few seconds to complete, but it's not worth holding up the build waiting for the task
141+
$UnmountRequest = Get-RubrikMount -id (Get-RubrikRequest -id $Mount.id -Type vmware/vm).links.href[0].split('/')[-1] | Remove-RubrikMount -Force -Confirm:$false
142+
Write-Verbose -Message "$($Config.virtualMachines[$i].mountName) Removal Status: $($UnmountRequest.id) is $($UnmountRequest.status)" -Verbose
143+
$i++
144+
}
145+
}
146+
147+
task 1_Init `
148+
GetConfig
149+
150+
task 2_Connect `
151+
ConnectRubrik,
152+
ConnectVMware
153+
154+
task 3_LiveMount `
155+
CreateLiveMount,
156+
ValidateLiveMount,
157+
ValidateLiveMountTools
158+
159+
task 4_LiveMountNetwork `
160+
MoveLiveMountNetwork,
161+
MoveLiveMountNetworkAddress
162+
163+
task 5_Testing `
164+
LiveMountTest
165+
166+
task . `
167+
1_Init,
168+
2_Connect,
169+
3_LiveMount,
170+
4_LiveMountNetwork,
171+
5_Testing,
172+
Cleanup

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Compiled source #
2+
###################
3+
*.com
4+
*.class
5+
*.dll
6+
*.exe
7+
*.o
8+
*.so
9+
10+
# Packages #
11+
############
12+
# it's better to unpack these files and commit the raw source
13+
# git has its own built in compression methods
14+
*.7z
15+
*.dmg
16+
*.gz
17+
*.iso
18+
*.jar
19+
*.rar
20+
*.tar
21+
*.zip
22+
23+
# Logs and databases #
24+
######################
25+
*.log
26+
*.sql
27+
*.sqlite
28+
29+
# OS generated files #
30+
######################
31+
.DS_Store
32+
.DS_Store?
33+
._*
34+
.Spotlight-V100
35+
.Trashes
36+
ehthumbs.db
37+
Thumbs.db
38+
39+
# Custom #
40+
######################
41+
.vscode/
42+
credential/

0 commit comments

Comments
 (0)