Skip to content

Commit 811c1f2

Browse files
committed
set-rubriksla support
1 parent d728100 commit 811c1f2

File tree

3 files changed

+267
-2
lines changed

3 files changed

+267
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
### Added
2020

2121
* New `Get-RubrikVMDownloadLink` and `Start-RubrikVMDownloadLink` cmdlets added along with associated unit tests
22-
* Added `Test-ManagedByRSC`,`Get-RubrikRSCVM`,`Get-RubrikRSCDatabase`,`Get-RubrikRSCFileset`,`Get-RubrikRSCFilesetTemplate`,`Get-RubrikRSCHost`,`Get-RubrikNutanixVM`,`Get-RubrikHyperVVM`, `Get-RubrikRSCSla`, `Get-RubrikRSCSqlInstance`, `New-RubrikRSCSla`, `Set-RubrikRSCSqlInstance`, `Set-RubrikRSCDatabase`,`Protect-RubrikRSCVM`,`Protect-RubrikRSCHyperVVM`,`Protect-RubrikRSCDatabase`, and `Protect-RubrikRSCNutanixVM` to support integration into the RSC PowerShell SDK
22+
* Added `Test-ManagedByRSC`,`Get-RubrikRSCVM`,`Get-RubrikRSCDatabase`,`Get-RubrikRSCFileset`,`Get-RubrikRSCFilesetTemplate`,`Get-RubrikRSCHost`,`Get-RubrikNutanixVM`,`Get-RubrikHyperVVM`, `Get-RubrikRSCSla`, `Get-RubrikRSCSqlInstance`, `New-RubrikRSCSla`, `Set-RubrikRSCSla`, `Set-RubrikRSCSqlInstance`, `Set-RubrikRSCDatabase`,`Protect-RubrikRSCVM`,`Protect-RubrikRSCHyperVVM`,`Protect-RubrikRSCDatabase`, and `Protect-RubrikRSCNutanixVM` to support integration into the RSC PowerShell SDK
2323

2424
### Modified
2525
* Modified `Connect-Rubrik` to detect if cluster is managed by RSC - if it is, redirect certain cmdlets to GQL Endpoints
2626
* Added a new `-RedirectToRSC` parameter to `Connect-Rubrik` to turn redirection to GQL endpoints on or off
2727
* Added new global variables `RSCInstance`,`clusterId`, and `RSCHeaders` to rubrikConnection
28-
* Modified `Get-RubrikSla`,`Get-RubrikVM`,`Get-RubrikHyperVVM`, `Get-RubrikNutanixVM`,`Get-RubrikFileset`,`Get-RubrikFilesetTemplate`,`Get-RubrikHost`,`Get-RubrikDatabase`, `Get-RubrikSqlInstance`, `New-RubrikSla`, `Set-RubrikSqlInstance`, `Set-RubrikDatabase`,`Protect-RubrikDatabase`,`Protect-RubrikVM`,`Protect-RubrikNutanixVM`, and `Protect-RubrikHyperVVM` to redirect to newly added (above) cmdlets that call GQL endpoints
28+
* Modified `Get-RubrikSla`,`Get-RubrikVM`,`Get-RubrikHyperVVM`, `Get-RubrikNutanixVM`,`Get-RubrikFileset`,`Get-RubrikFilesetTemplate`,`Get-RubrikHost`,`Get-RubrikDatabase`, `Get-RubrikSqlInstance`, `New-RubrikSla`, `Set-RubrikSqlInstance`, `Set-RubrikSla`, `Set-RubrikDatabase`,`Protect-RubrikDatabase`,`Protect-RubrikVM`,`Protect-RubrikNutanixVM`, and `Protect-RubrikHyperVVM` to redirect to newly added (above) cmdlets that call GQL endpoints
2929

3030
## [6.0.2](https://github.com/rubrikinc/rubrik-sdk-for-powershell/tree/6.0.2) - 2023-01-06
3131

Rubrik/Private/Set-RubrikRSCSla.ps1

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
function Set-RubrikRSCSLA
2+
{
3+
[CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact = 'High')]
4+
Param(
5+
# SLA id value from the Rubrik Cluster
6+
[Parameter(
7+
ValueFromPipelineByPropertyName = $true,
8+
Mandatory = $true )]
9+
[ValidateNotNullOrEmpty()]
10+
[String]$id,
11+
# SLA Domain Name
12+
[Parameter(
13+
ValueFromPipelineByPropertyName = $true)]
14+
[Alias('SLA')]
15+
[ValidateNotNullOrEmpty()]
16+
[String]$Name,
17+
# Hourly frequency to take snapshots
18+
[int]$HourlyFrequency,
19+
# Number of days or weeks to retain the hourly snapshots. For CDM versions prior to 5.0 this value must be set in days
20+
[int]$HourlyRetention,
21+
# Retention type to apply to hourly snapshots when advanced configuration is enabled. Does not apply to CDM versions prior to 5.0
22+
[ValidateSet('Daily','Weekly')]
23+
[String]$HourlyRetentionType='Daily',
24+
# Daily frequency to take snapshots
25+
[int]$DailyFrequency,
26+
# Number of days or weeks to retain the daily snapshots. For CDM versions prior to 5.0 this value must be set in days
27+
[int]$DailyRetention,
28+
# Retention type to apply to daily snapshots when advanced configuration is enabled. Does not apply to CDM versions prior to 5.0
29+
[ValidateSet('Daily','Weekly')]
30+
[String]$DailyRetentionType='Daily',
31+
# Weekly frequency to take snapshots
32+
[int]$WeeklyFrequency,
33+
# Number of weeks to retain the weekly snapshots
34+
[int]$WeeklyRetention,
35+
# Day of week for the weekly snapshots when advanced configuration is enabled. The default is Saturday. Does not apply to CDM versions prior to 5.0
36+
[ValidateSet('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')]
37+
[String]$DayOfWeek='Saturday',
38+
# Monthly frequency to take snapshots
39+
[int]$MonthlyFrequency,
40+
# Number of months, quarters or years to retain the monthly backups. For CDM versions prior to 5.0, this value must be set in years
41+
[int]$MonthlyRetention,
42+
# Day of month for the monthly snapshots when advanced configuration is enabled. The default is the last day of the month. Does not apply to CDM versions prior to 5.0
43+
[ValidateSet('FirstDay','Fifteenth','LastDay')]
44+
[String]$DayOfMonth='LastDay',
45+
# Retention type to apply to monthly snapshots. Does not apply to CDM versions prior to 5.0
46+
[ValidateSet('Monthly','Quarterly','Yearly')]
47+
[String]$MonthlyRetentionType='Monthly',
48+
# Quarterly frequency to take snapshots. Does not apply to CDM versions prior to 5.0
49+
[int]$QuarterlyFrequency,
50+
# Number of quarters or years to retain the monthly snapshots. Does not apply to CDM versions prior to 5.0
51+
[int]$QuarterlyRetention,
52+
# Day of quarter for the quarterly snapshots when advanced configuration is enabled. The default is the last day of the quarter. Does not apply to CDM versions prior to 5.0
53+
[ValidateSet('FirstDay','LastDay')]
54+
[String]$DayOfQuarter='LastDay',
55+
# Month that starts the first quarter of the year for the quarterly snapshots when advanced configuration is enabled. The default is January. Does not apply to CDM versions prior to 5.0
56+
[ValidateSet('January','February','March','April','May','June','July','August','September','October','November','December')]
57+
[String]$FirstQuarterStartMonth='January',
58+
# Retention type to apply to quarterly snapshots. The default is Quarterly. Does not apply to CDM versions prior to 5.0
59+
[ValidateSet('Quarterly','Yearly')]
60+
[String]$QuarterlyRetentionType='Quarterly',
61+
# Yearly frequency to take snapshots
62+
[int]$YearlyFrequency,
63+
# Number of years to retain the yearly snapshots
64+
[int]$YearlyRetention,
65+
# Day of year for the yearly snapshots when advanced configuration is enabled. The default is the last day of the year. Does not apply to CDM versions prior to 5.0
66+
[ValidateSet('FirstDay','LastDay')]
67+
[String]$DayOfYear='LastDay',
68+
# Month that starts the first quarter of the year for the quarterly snapshots when advanced configuration is enabled. The default is January. Does not apply to CDM versions prior to 5.0
69+
[ValidateSet('January','February','March','April','May','June','July','August','September','October','November','December')]
70+
[String]$YearStartMonth='January',
71+
# Whether to turn advanced SLA configuration on or off. Does not apply to CDM versions prior to 5.0
72+
[Parameter(
73+
ValueFromPipelineByPropertyName = $true)]
74+
[alias('showAdvancedUi')]
75+
[switch]$AdvancedConfig,
76+
# Hour from which backups are allowed to run. Uses the 24-hour clock
77+
[ValidateRange(0,23)]
78+
[int]$BackupStartHour,
79+
# Minute of hour from which backups are allowed to run
80+
[ValidateRange(0,59)]
81+
[int]$BackupStartMinute,
82+
# Number of hours during which backups are allowed to run
83+
[ValidateRange(1,23)]
84+
[int]$BackupWindowDuration,
85+
# Hour from which the first full backup is allowed to run. Uses the 24-hour clock
86+
[ValidateRange(0,23)]
87+
[int]$FirstFullBackupStartHour,
88+
# Minute of hour from which the first full backup is allowed to run
89+
[ValidateRange(0,59)]
90+
[int]$FirstFullBackupStartMinute,
91+
[ValidateSet('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','1','2','3','4','5','6','7')]
92+
[String]$FirstFullBackupDay,
93+
# Number of hours during which the first full backup is allowed to run
94+
[int]$FirstFullBackupWindowDuration,
95+
# Whether to enable archival
96+
[switch]$Archival,
97+
# Time in days to keep backup data locally on the cluster.
98+
[Parameter(
99+
ValueFromPipelineByPropertyName = $true)]
100+
[alias('localRetentionLimit')]
101+
[int]$LocalRetention,
102+
# ID of the archival location
103+
[ValidateNotNullOrEmpty()]
104+
[String]$ArchivalLocationId,
105+
# Polaris Managed ID
106+
[ValidateNotNullOrEmpty()]
107+
[String]$PolarisID,
108+
# Whether to enable Instant Archive
109+
[switch]$InstantArchive,
110+
# Whether a retention lock is active on this SLA, Does not apply to CDM versions prior to 5.2
111+
[alias('isRetentionLocked')]
112+
[switch]$RetentionLock,
113+
# Whether to enable replication
114+
[switch]$Replication,
115+
# ID of the replication target
116+
[ValidateNotNullOrEmpty()]
117+
[String]$ReplicationTargetId,
118+
# Time in days to keep data on the replication target.
119+
[int]$RemoteRetention,
120+
# Retrieves frequencies from Get-RubrikSLA via the pipeline
121+
[Parameter(
122+
ValueFromPipelineByPropertyName = $true)]
123+
[object[]] $Frequencies,
124+
# Retrieves the advanced UI configuration parameters from Get-RubrikSLA via the pipeline
125+
[Parameter(
126+
ValueFromPipelineByPropertyName = $true)]
127+
[alias('advancedUiConfig')]
128+
[object[]] $AdvancedFreq,
129+
# Retrieves the allowed backup windows from Get-RubrikSLA via the pipeline
130+
[Parameter(
131+
ValueFromPipelineByPropertyName = $true)]
132+
[alias('allowedBackupWindows')]
133+
[object[]] $BackupWindows,
134+
# Retrieves the allowed backup windows for the first full backup from Get-RubrikSLA via the pipeline
135+
[Parameter(
136+
ValueFromPipelineByPropertyName = $true)]
137+
[alias('firstFullAllowedBackupWindows')]
138+
[object[]] $FirstFullBackupWindows,
139+
# Retrieves the archical specifications from Get-RubrikSLA via the pipeline
140+
[Parameter(
141+
ValueFromPipelineByPropertyName = $true)]
142+
[object[]] $ArchivalSpecs,
143+
# Retrieves the replication specifications from Get-RubrikSLA via the pipeline
144+
[Parameter(
145+
ValueFromPipelineByPropertyName = $true)]
146+
[object[]] $ReplicationSpecs,
147+
# Rubrik server IP or FQDN
148+
[String]$Server = $global:RubrikConnection.server,
149+
# API version
150+
[String]$api = $global:RubrikConnection.api
151+
)
152+
153+
$RscParams = @{}
154+
155+
if ($id) {
156+
$RscParams.Add("id",$id)
157+
}
158+
159+
if ($HourlyFrequency) {
160+
if ($HourlyRetentionType -eq "Weekly") {
161+
$RetentionUnit = "WEEKS"
162+
} else {
163+
$RetentionUnit = "DAYS"
164+
}
165+
$hourlySchedule = New-RscSlaSnapshotSchedule -Type Hourly -Frequency $HourlyFrequency -Retention $HourlyRetention -RetentionUnit $RetentionUnit
166+
$RscParams.Add("HourlySchedule", $hourlySchedule)
167+
}
168+
if ($DailyFrequency) {
169+
if ($DailyRetentionType -eq "Weekly") {
170+
$RetentionUnit = "WEEKS"
171+
} else {
172+
$RetentionUnit = "DAYS"
173+
}
174+
$dailySchedule = New-RscSlaSnapshotSchedule -Type Daily -Frequency $DailyFrequency -Retention $DailyRetention -RetentionUnit $RetentionUnit
175+
$RscParams.Add("DailySchedule",$dailySchedule)
176+
}
177+
if ($WeeklyFrequency) {
178+
if ($DayOfWeek) {
179+
$DayToTakeSnap = $DayOfWeek.toUpper()
180+
} else {
181+
$DayToTakeSnap = "MONDAY"
182+
}
183+
$weeklySchedule = New-RscSlaSnapshotSchedule -Type Weekly -Frequency $WeeklyFrequency -Retention $WeeklyRetention -DayOfWeek $DayToTakeSnap -RetentionUnit WEEKS
184+
Write-Host "Adding weekly"
185+
$RscParams.Add("WeeklySchedule",$weeklySchedule)
186+
}
187+
if ($MonthlyFrequency) {
188+
if ($DayOfMonth -eq "FirstDay") {
189+
$DayToTakeSnap = "FIRST_DAY"
190+
} elseif ($DayOfMonth -eq "Fifteenth") {
191+
$DayToTakeSnap = "FIFTEENTH"
192+
} else {
193+
$DayToTakeSnap = "LAST_DAY"
194+
}
195+
if ($MonthlyRetentionType -eq "Quarterly") {
196+
$RetentionUnit = "QUARTERS"
197+
} elseif ($MonthlyRetentionType -eq "Yearly") {
198+
$RetentionUnit = "YEARS"
199+
} else {
200+
$RetentionUnit = "MONTHS"
201+
}
202+
$monthlySchedule = New-RscSlaSnapshotSchedule -Type Monthly -Frequency $MonthlyFrequency -Retention $MonthlyRetention -DayOfMonth $DayToTakeSnap -RetentionUnit $RetentionUnit
203+
$RscParams.Add("MonthlySchedule",$monthlySchedule)
204+
}
205+
if ($QuarterlyFrequency) {
206+
if ($DayOfQuarter -eq "FirstDay") {
207+
$DayToTakeSnap = "FIRST_DAY"
208+
} else {
209+
$DayToTakeSnap = "LAST_DAY"
210+
}
211+
212+
if ($FirstQuarterStartMonth) {
213+
$QuarterStartMonth = $FirstQuarterStartMonth.toUpper()
214+
} else {
215+
$QuarterStartMonth = "JANUARY"
216+
}
217+
if ($QuarterlyRetentionType -eq "Yearly") {
218+
$RetentionUnit = "YEARS"
219+
} else {
220+
$RetentionUnit = "QUARTERS"
221+
}
222+
$quarterlySchedule = New-RscSlaSnapshotSchedule -Type Quarterly -Frequency $QuarterlyFrequency -Retention $QuarterlyRetention -DayOfQuarter $DayToTakeSnap -RetentionUnit $RetentionUnit -QuarterStartMonth $QuarterStartMonth
223+
$RscParams.Add("QuarterlySchedule",$quarterlySchedule)
224+
}
225+
if ($YearlyFrequency) {
226+
$RetentionUnit = "YEARS"
227+
if ($YearStartMonth) {
228+
$YearStart = [RubrikSecurityCloud.Types.Month] $YearStartMonth.toUpper()
229+
} else {
230+
$YearStart = [RubrikSecurityCloud.Types.Month] "JANUARY"
231+
}
232+
if ($DayOfYear -eq "FirstDay") {
233+
$DayYear = "FIRST_DAY"
234+
} else {
235+
$DayYear = "LAST_DAY"
236+
}
237+
$yearlySchedule = New-RscSlaSnapshotSchedule -Type Yearly -Frequency $YearlyFrequency -Retention $YearlyRetention -RetentionUnit $RetentionUnit -YearStartMonth $YearStart -DayOfYear $DayYear
238+
$RscParams.Add("YearlySchedule",$yearlySchedule)
239+
}
240+
241+
if ($Name) {
242+
$RscParams.Add("Name",$Name)
243+
}
244+
245+
# Retrieve current object types for sla
246+
247+
$query = New-RscQuery -GqlQuery slaDomains
248+
$query.Field.nodes[1].ObjectTypes = "VSPHERE_OBJECT_TYPE"
249+
$slas = (Invoke-Rsc $query).nodes
250+
$indsla = $slas | where-Object {$_.id -eq $id}
251+
$objecttypes = $indsla.ObjectTypes
252+
253+
$RscParams.Add("ObjectType",$objectTypes)
254+
$response = Set-RscSla @RscParams
255+
return $response
256+
257+
}

Rubrik/Public/Set-RubrikSLA.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ function Set-RubrikSLA
239239
}
240240

241241
Process {
242+
243+
# If connected to RSC, redirect to new GQL cmdlet
244+
if ($global:rubrikConnection.RSCInstance) {
245+
Write-Verbose -Message "Cluster connected to RSC instance, redirecting to Set-RubrikRSCSla"
246+
$response = Set-RubrikRSCSla @PSBoundParameters
247+
return $response
248+
}
249+
242250
$uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id
243251
$uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri
244252

0 commit comments

Comments
 (0)