/// <summary> /// Validating vault upgrade prerequisites. /// </summary> /// <returns>CheckPrerequisites response.</returns> private CheckVaultUpgradePrerequisitesResponse ValidateVaultUpgradePrerequisites() { CheckVaultUpgradePrerequisitesResponse response = CheckVaultUpgradePrerequisitesResponse.Succeeded; try { this.RecoveryServicesClient.TestVaultUpgradePrerequistes( this.VaultName, this.Location, this.ResourceType, this.TargetResourceGroupName, this.Profile.Context.Subscription.Id.ToString()); } catch (Exception exception) { ExceptionDetails details = this.HandleVaultUpgradeException(exception); if (details != null) { if (!string.IsNullOrEmpty(details.WarningDetails)) { this.WriteWarning(details.WarningDetails + Environment.NewLine); response = CheckVaultUpgradePrerequisitesResponse.SucceededWithWarnings; } if (!string.IsNullOrEmpty(details.ErrorDetails)) { response = CheckVaultUpgradePrerequisitesResponse.Failed; Exception ex = new InvalidOperationException( string.Format( Properties.Resources.ConfirmVaultUpgradePrereqFailed, Properties.Resources.VaultUpgradeExceptionDetails, details.ErrorDetails)); this.WriteVaultUpgradeError(ex); } } else { response = CheckVaultUpgradePrerequisitesResponse.Failed; } } return(response); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteCmdlet() { CheckVaultUpgradePrerequisitesResponse result = this.ValidateVaultUpgradePrerequisites(); if (result == CheckVaultUpgradePrerequisitesResponse.Failed) { return; } bool actionConfirmed = false; ResourceUpgradeDetails response = null; string message = result == CheckVaultUpgradePrerequisitesResponse.Succeeded ? Properties.Resources.PrerequisitesCheckPassed : Properties.Resources.PrerequisitesCheckReturnedWarnings; try { if (this.ShouldProcess(this.VaultName, Properties.Resources.StartVaultUpgradeWhatIfMessage) && (this.Force.IsPresent || this.ShouldContinue(string.Format(message), string.Empty))) { response = this.RecoveryServicesClient.StartVaultUpgrade( this.VaultName, this.Location, this.ResourceType, this.TargetResourceGroupName, this.Profile.Context.Subscription.Id.ToString()); actionConfirmed = true; } if (actionConfirmed) { this.WaitForJobCompletion(response); } } catch (Exception exception) { this.HandleVaultUpgradeException(exception); } }