Skip to content

Commit

Permalink
Added New-RscSlaDomain and New-RscSnapshotSchedule (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakerobinson authored Feb 14, 2024
1 parent 9f79386 commit 6dbe81e
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 152 deletions.
76 changes: 76 additions & 0 deletions Toolkit/Public/New-RscSlaDomain.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#Requires -Version 3
function New-RscSlaDomain
{
<#
.SYNOPSIS
Creates a new Rubrik SLA Domain
.DESCRIPTION
The New-RscSlaDomain cmdlet will create a new SLA Domain. Rubrik SLA Domains are policies that define the frequency, retention, and rules for acrhival and replication.
.LINK
Schema reference:
https://rubrikinc.github.io/rubrik-api-documentation/schema/reference
.EXAMPLE
Create a Snapshot schedule to take a snapshot every 1 hour and retain that snapshot for 7 days. Then create the SLA Domain with that schedule.
$hourlySchedule = New-RscSnapshotSchedule -Type Hourly -Frequency 1 -Retention 7 -RetentionUnit DAYS
New-RscSlaDomain -Name "Platinum" -HourlySchedule $hourlySchedule -ObjectType VSPHERE_OBJECT_TYPE
#>

[CmdletBinding()]
Param(
# SLA Domain Name
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String]$Name,

# Hourly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.HourlySnapshotScheduleInput]$HourlySchedule,

# Weekly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.WeeklySnapshotScheduleInput]$WeeklySchedule,

# Monthly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.MonthlySnapshotScheduleInput]$MonthlySchedule,

# Quarterly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.QuarterlySnapshotScheduleInput]$QuarterlySchedule,

# Yearly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.YearlySnapshotScheduleInput]$YearlySchedule,

# Yearly Schedule object
[Parameter()]
[RubrikSecurityCloud.Types.SlaObjectType]$ObjectType
)
Process {

$query = New-RscMutation -GqlMutation createGlobalSla
$query.Var.Input = New-Object -TypeName RubrikSecurityCloud.Types.CreateGlobalSlaInput
$query.Var.Input.name = $Name
$query.Var.Input.SnapshotSchedule = New-Object -TypeName RubrikSecurityCloud.Types.GlobalSnapshotScheduleInput
$query.Var.Input.ObjectTypes = @($ObjectType)

if ($HourlySchedule) {
$query.var.input.SnapshotSchedule.Hourly = $HourlySchedule
}
if ($MonthlySchedule) {
$query.var.input.SnapshotSchedule.Monthly = $MonthlySchedule
}
if ($QuarterlySchedule) {
$query.var.input.SnapshotSchedule.Quarterly = $QuarterlySchedule
}
if ($YearlySchedule) {
$query.var.input.SnapshotSchedule.Yearly = $YearlySchedule
}
$result = Invoke-Rsc -Query $query
$result
}
}
98 changes: 98 additions & 0 deletions Toolkit/Public/New-RscSnapshotSchedule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#Requires -Version 3
function New-RscSnapshotSchedule {
<#
.SYNOPSIS
Creates a Snapshot Schedule for use with New-RscSlaDomain
.DESCRIPTION
Creates a Snapshot Schedule for use with New-RscSlaDomain
.PARAMETER Type
The Type of Schedule
(Minute, Hourly, Daily, Weekly, Monthly, Quarterly, Yearly)
.PARAMETER Frequency
The frequency to take a snapshot, based on the schedule type.
.PARAMETER Retention
Length of time to retain the snapshot
.PARAMETER RetentionUnit
Unit of time to retain the snapshot
(Minute, Hourly, Daily, Weekly, Monthly, Quarterly, Yearly)
.LINK
Schema reference:
https://rubrikinc.github.io/rubrik-api-documentation/schema/reference
.EXAMPLE
Create a Snapshot schedule to take a snapshot every 1 hour and retain that snapshot for 7 days. Then create the SLA Domain with that schedule.
$hourlySchedule = New-RscSnapshotSchedule -Type Hourly -Frequency 1 -Retention 7 -RetentionUnit DAYS
New-RscSlaDomain -Name "Platinum" -HourlySchedule $hourlySchedule -ObjectType VSPHERE_OBJECT_TYPE
#>

[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[ValidateSet("Minute","Hourly","Daily","Weekly","Monthly","Quarterly","Yearly")]
$Type,

[Parameter(Mandatory)]
[Int]$Frequency,

[Parameter(Mandatory)]
[Int]$Retention,

[Parameter(Mandatory)]
[RubrikSecurityCloud.Types.RetentionUnit]
$RetentionUnit,

[Parameter()]
[RubrikSecurityCloud.Types.DayOfWeek]
$DayOfWeek = [RubrikSecurityCloud.Types.DayOfWeek]::FRIDAY,

[Parameter()]
[RubrikSecurityCloud.Types.DayOfMonth]
$DayOfMonth = [RubrikSecurityCloud.Types.DayOfMonth]::LAST_DAY,

[Parameter()]
[RubrikSecurityCloud.Types.DayOfQuarter]
$DayOfQuarter = [RubrikSecurityCloud.Types.DayOfQuarter]::LAST_DAY,

[Parameter()]
[RubrikSecurityCloud.Types.Month]
$QuarterStartMonth = [RubrikSecurityCloud.Types.Month]::JANUARY,

[Parameter()]
[RubrikSecurityCloud.Types.DayOfYear]
$DayOfYear = [RubrikSecurityCloud.Types.DayOfYear]::LAST_DAY,

[Parameter()]
[RubrikSecurityCloud.Types.Month]
$YearStartMonth = [RubrikSecurityCloud.Types.Month]::JANUARY

)

Process {
$schedule = New-Object -TypeName "RubrikSecurityCloud.Types.$($Type)SnapshotScheduleInput"
$schedule.BasicSchedule = New-Object -TypeName RubrikSecurityCloud.Types.BasicSnapshotScheduleInput
$schedule.BasicSchedule.Frequency = $Frequency
$schedule.BasicSchedule.Retention = $Retention
$schedule.BasicSchedule.RetentionUnit = $RetentionUnit

if ($Type -eq "Weekly") {
$schedule.DayOfWeek = $DayOfWeek
} elseif ($Type -eq "Monthly") {
$schedule.DayOfMonth = $DayOfMonth
} elseif ($Type -eq "Quarterly") {
$schedule.DayOfQuarter = $DayOfQuarter
$schedule.QuarterStartMonth = $QuarterStartMonth
} elseif ($Type -eq "Yearly") {
$schedule.DayOfYear = $DayOfYear
$schedule.YearStartMonth = $YearStartMonth
}
$schedule
}
}
152 changes: 0 additions & 152 deletions Toolkit/Public/New-SlaDomain.ps1

This file was deleted.

0 comments on commit 6dbe81e

Please sign in to comment.