Skip to content

Commit

Permalink
Merge pull request #54 from rubrikinc/final-updates
Browse files Browse the repository at this point in the history
Final updates :shipit:
  • Loading branch information
chriswahl authored Dec 28, 2016
2 parents 2c89ade + d75bd9f commit 7429e92
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 310 deletions.
6 changes: 5 additions & 1 deletion Rubrik/Private/Connect-TovCenter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ function ConnectTovCenter($vCenter)
Write-Verbose -Message 'Ignoring self-signed SSL certificates for vCenter Server (optional)'
$null = Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$false -Scope User -Confirm:$false

if ($vCenter -eq $null)
if ($vCenter -eq $null -and $global:DefaultVIServer -ne $null)
{
$vCenter = $global:DefaultVIServer.Name
}
else
{
throw 'You are not connected to a vCenter Server'
}

Write-Verbose -Message 'Connecting to vCenter'
try
Expand Down
42 changes: 42 additions & 0 deletions Rubrik/Private/Get-RubrikAPIData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,48 @@ function GetRubrikAPIData($endpoint)
FailureMock = ''
}
}
VMwareVMPatch = @{
v1 = @{
URI = '/api/v1/vmware/vm/{id}'
Method = 'Patch'
Params = @{
snapshotConsistencyMandate = 'snapshotConsistencyMandate'
maxNestedVsphereSnapshots = 'maxNestedVsphereSnapshots'
isVmPaused = 'isVmPaused'
preBackupScript = @{
scriptPath = 'scriptPath'
timeoutMs = 'timeoutMs'
failureHandling = 'failureHandling'
}
postSnapScript = @{
scriptPath = 'scriptPath'
timeoutMs = 'timeoutMs'
failureHandling = 'failureHandling'
}
postBackupScript = @{
scriptPath = 'scriptPath'
timeoutMs = 'timeoutMs'
failureHandling = 'failureHandling'
}
}
SuccessCode = '200'
SuccessMock = ''
FailureCode = ''
FailureMock = ''
}
v0 = @{
URI = '/vm/{id}'
Method = 'Patch'
Params = @{
snapshotConsistencyMandate = 'snapshotConsistencyMandate'
maxNestedVsphereSnapshots = 'maxNestedVsphereSnapshots'
}
SuccessCode = '200'
SuccessMock = ''
FailureCode = ''
FailureMock = ''
}
}
} # End of API

return $api.$endpoint
Expand Down
65 changes: 0 additions & 65 deletions Rubrik/Public/Set-RubrikMount.ps1

This file was deleted.

169 changes: 103 additions & 66 deletions Rubrik/Public/Set-RubrikVM.ps1
Original file line number Diff line number Diff line change
@@ -1,80 +1,117 @@
#requires -Version 3
function Set-RubrikVM
{
<#
.SYNOPSIS
Applies settings on one or more virtual machines known to a Rubrik cluster
.DESCRIPTION
The Set-RubrikVM cmdlet is used to apply updated settings from a Rubrik cluster on any number of virtual machines
.NOTES
Written by Chris Wahl for community usage
Twitter: @ChrisWahl
GitHub: chriswahl
.LINK
https://github.com/rubrikinc/PowerShell-Module
.EXAMPLE
Set-RubrikVM -VM 'Server1' -SnapConsistency AUTO
This will configure the backup consistency type for Server1 to Automatic (try for application consistency and fail to crash consistency).
.EXAMPLE
(Get-RubrikVM -VM * -SLA 'Example').name | Set-RubrikVM -SnapConsistency AUTO
This will gather the name of all VMs belonging to the SLA Domain named Example and configure the backup consistency type to be crash consistent.
#>
<#
.SYNOPSIS
Applies settings on one or more virtual machines known to a Rubrik cluster
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true,Position = 0,HelpMessage = 'Virtual Machine',ValueFromPipeline = $true)]
[Alias('Name')]
[ValidateNotNullorEmpty()]
[String]$VM,
[Parameter(Mandatory = $false,Position = 1,HelpMessage = 'Backup consistency type. Choices are AUTO or CRASH_CONSISTENT')]
[ValidateSet('AUTO', 'CRASH_CONSISTENT')]
[String]$SnapConsistency,
[Parameter(Mandatory = $false,Position = 3,HelpMessage = 'Rubrik FQDN or IP address')]
[ValidateNotNullorEmpty()]
[String]$Server = $global:RubrikConnection.server
)
.DESCRIPTION
The Set-RubrikVM cmdlet is used to apply updated settings from a Rubrik cluster on any number of virtual machines
Process {
.NOTES
Written by Chris Wahl for community usage
Twitter: @ChrisWahl
GitHub: chriswahl
TestRubrikConnection
.LINK
https://github.com/rubrikinc/PowerShell-Module
Write-Verbose -Message 'Gathering VM ID value from Rubrik'
$vmid = (Get-RubrikVM -VM $VM).id
.EXAMPLE
Set-RubrikVM -VM 'Server1' -SnapConsistency AUTO
This will configure the backup consistency type for Server1 to Automatic (try for application consistency and fail to crash consistency).
Write-Verbose -Message 'Building the request'
$uri = 'https://'+$Server+'/vm/'+$vmid
.EXAMPLE
(Get-RubrikVM -VM * -SLA 'Example').name | Set-RubrikVM -SnapConsistency AUTO
This will gather the name of all VMs belonging to the SLA Domain named Example and configure the backup consistency type to be crash consistent.
#>

Write-Verbose -Message 'Validating the consistency type'
if ($SnapConsistency)
{
Write-Verbose -Message 'Translating friendly choice into API value'
switch ($SnapConsistency)
{
AUTO
{
$SnapVar = ''
}
CRASH_CONSISTENT
{
$SnapVar = 'CRASH_CONSISTENT'
}
}

$body = @{
snapshotConsistencyMandate = $SnapVar
}
}
[CmdletBinding()]
Param(
# Virtual machine name
[Parameter(Mandatory = $true,Position = 0,ValueFromPipelineByPropertyName = $true)]
[Alias('Name')]
[ValidateNotNullorEmpty()]
[String]$VM,
# Backup consistency type
# Choices are AUTO or CRASH_CONSISTENT
[Parameter(Position = 1)]
[ValidateSet('APP_CONSISTENT', 'CRASH_CONSISTENT','FILE_SYSTEM_CONSISTENT','INCONSISTENT','VSS_CONSISTENT')]
[String]$SnapConsistency,
# The number of existing virtual machine snapshots allowed by Rubrik
# If this value is exceeded, backups will be prevented due to seeing too many existing snapshots
# Keeping snapshots open on a virtual machine can adversely affect performance and increase consolidation times
# Choices range from 0 - 4 snapshots
[ValidateRange(0,4)]
[Parameter(Position = 2)]
[int]$MaxNestedSnapshots,
# Set to $true to enable backups for a particular virtual machine
# Set to $false to disable backups for a particular virtual machine
[Parameter(Position = 3)]
[bool]$PauseBackups,
# Rubrik server IP or FQDN
[String]$Server = $global:RubrikConnection.server,
# API version
[String]$api = $global:RubrikConnection.api
)

try
{
$r = Invoke-WebRequest -Uri $uri -Headers $header -Body (ConvertTo-Json -InputObject $body) -Method Patch
$result = ConvertFrom-Json -InputObject $r.Content
return $result
}
catch
Process {

TestRubrikConnection

Write-Verbose -Message 'Determining which version of the API to use'
$resources = GetRubrikAPIData -endpoint ('VMwareVMPatch')

Write-Verbose -Message 'Gathering VM ID value from Rubrik'
$vmid = (Get-RubrikVM -VM $VM).id

Write-Verbose -Message 'Building the URI'
$uri = 'https://'+$Server+$resources.$api.URI
# Replace the placeholder of {id} with the actual VM ID
$uri = $uri -replace '{id}', $vmid

# Set the method
$method = $resources.$api.Method

Write-Verbose -Message 'Defining a body variable for required API params'
$body = @{}

if ($SnapConsistency)
{
$body.Add($resources.$api.Params.snapshotConsistencyMandate,$SnapConsistency)
}
if ($MaxNestedSnapshots)
{
Write-Verbose -Message 'Adding maxNestedVsphereSnapshots to Body'
$body.Add($resources.$api.Params.maxNestedVsphereSnapshots,$MaxNestedSnapshots)
}
if ($PauseBackups -ne $null)
{
Write-Verbose -Message 'Adding isVmPaused to Body'
$body.Add($resources.$api.Params.isVmPaused,$PauseBackups)
}

# If the $body variable is empty, no params were defined
if ($body.Keys.Count -eq 0)
{
throw 'No parameters were defined.'
}

try
{
if ($PSCmdlet.ShouldProcess($VM,'Modifying settings'))
{
$r = Invoke-WebRequest -Uri $uri -Headers $Header -Method $method -Body (ConvertTo-Json -InputObject $body)
if ($r.StatusCode -ne $resources.$api.SuccessCode)
{
throw $_
Write-Warning -Message 'Did not receive successful status code from Rubrik'
throw $_
}
}
}
catch
{
throw $_
}

} # End of process
} # End of process
} # End of function
Loading

0 comments on commit 7429e92

Please sign in to comment.