Skip to content

[REBASE] Added AFS support to Get Policy cmdlet #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,132 @@ public static List<BackupEngineBase> GetBackupEngineModelList(

#region policy

/// <summary>
/// Helper function to convert ps backup policy model for AzureVM from service response.
/// </summary>
public static PolicyBase GetPolicyModelForAzureIaaSVM(
ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
PolicyBase policyModel)
{
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).
RetentionPolicy.GetType() != typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.
Properties).RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).
SchedulePolicy.GetType() != typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.
Properties).SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureVmPolicy();
AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy(
(ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.
AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).
TimeZone);
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy(
(ServiceClientModel.SimpleSchedulePolicy)((ServiceClientModel.
AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).
TimeZone);
return policyModel;
}

/// <summary>
/// Helper function to convert ps backup policy model for AzureSql from service response.
/// </summary>
public static PolicyBase GetPolicyModelForAzureSql(
ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
PolicyBase policyModel)
{
ServiceClientModel.AzureSqlProtectionPolicy azureSqlPolicy =
(ServiceClientModel.AzureSqlProtectionPolicy)serviceClientResponse.Properties;

if (azureSqlPolicy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
azureSqlPolicy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureSqlPolicy();
AzureSqlPolicy sqlPolicyModel = policyModel as AzureSqlPolicy;
sqlPolicyModel.WorkloadType = WorkloadType.AzureSQLDatabase;
sqlPolicyModel.BackupManagementType = BackupManagementType.AzureSQL;

ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
sqlPolicyModel.RetentionPolicy =
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
return policyModel;
}

/// <summary>
/// Helper function to convert ps backup policy model for Azure FileShare from service response.
/// </summary>
public static PolicyBase GetPolicyModelForAzureFileShare(
ServiceClientModel.ProtectionPolicyResource serviceClientResponse,
PolicyBase policyModel)
{
ServiceClientModel.AzureFileShareProtectionPolicy azureFileSharePolicy =
(ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties;

if (azureFileSharePolicy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
azureFileSharePolicy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

if (azureFileSharePolicy.SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
azureFileSharePolicy.SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureFileSharePolicy();
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;
fileSharePolicyModel.RetentionPolicy =
PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).
RetentionPolicy,
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).
TimeZone);
fileSharePolicyModel.SchedulePolicy =
PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).
SchedulePolicy,
((ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties).
TimeZone);
return policyModel;
}

/// <summary>
/// Helper function to convert ps backup policy model from service response.
/// </summary>
public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResource serviceClientResponse)
public static PolicyBase GetPolicyModel(
ServiceClientModel.ProtectionPolicyResource serviceClientResponse)
{
PolicyBase policyModel = null;

Expand All @@ -140,86 +262,20 @@ public static PolicyBase GetPolicyModel(ServiceClientModel.ProtectionPolicyResou
throw new ArgumentException(Resources.EmptyServiceClientResponseException);
}

if (serviceClientResponse.Properties.GetType() == typeof(ServiceClientModel.AzureIaaSVMProtectionPolicy))
if (serviceClientResponse.Properties.GetType() ==
typeof(ServiceClientModel.AzureIaaSVMProtectionPolicy))
{
if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType() !=
typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

if (((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType() !=
typeof(ServiceClientModel.SimpleSchedulePolicy))
{
Logger.Instance.WriteDebug("Unknown SchedulePolicy object received: " +
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureVmPolicy();
AzureVmPolicy iaasPolicyModel = policyModel as AzureVmPolicy;
iaasPolicyModel.WorkloadType = WorkloadType.AzureVM;
iaasPolicyModel.BackupManagementType = BackupManagementType.AzureVM;
iaasPolicyModel.RetentionPolicy = PolicyHelpers.GetPSLongTermRetentionPolicy((ServiceClientModel.LongTermRetentionPolicy)
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).RetentionPolicy,
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
iaasPolicyModel.SchedulePolicy = PolicyHelpers.GetPSSimpleSchedulePolicy((ServiceClientModel.SimpleSchedulePolicy)
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).SchedulePolicy,
((ServiceClientModel.AzureIaaSVMProtectionPolicy)serviceClientResponse.Properties).TimeZone);
policyModel = GetPolicyModelForAzureIaaSVM(serviceClientResponse, policyModel);
}
else if (serviceClientResponse.Properties.GetType() ==
typeof(ServiceClientModel.AzureSqlProtectionPolicy))
{
ServiceClientModel.AzureSqlProtectionPolicy azureSqlPolicy =
(ServiceClientModel.AzureSqlProtectionPolicy)serviceClientResponse.Properties;

if (azureSqlPolicy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.SimpleRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
azureSqlPolicy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureSqlPolicy();
AzureSqlPolicy sqlPolicyModel = policyModel as AzureSqlPolicy;
sqlPolicyModel.WorkloadType = WorkloadType.AzureSQLDatabase;
sqlPolicyModel.BackupManagementType = BackupManagementType.AzureSQL;

ServiceClientModel.SimpleRetentionPolicy azureSqlRetentionPolicy =
(ServiceClientModel.SimpleRetentionPolicy)azureSqlPolicy.RetentionPolicy;
sqlPolicyModel.RetentionPolicy =
PolicyHelpers.GetPSSimpleRetentionPolicy(azureSqlRetentionPolicy, null);
policyModel = GetPolicyModelForAzureSql(serviceClientResponse, policyModel);
}
else if (serviceClientResponse.Properties.GetType() ==
typeof(ServiceClientModel.AzureFileShareProtectionPolicy))
{
ServiceClientModel.AzureFileShareProtectionPolicy azureFileSharePolicy =
(ServiceClientModel.AzureFileShareProtectionPolicy)serviceClientResponse.Properties;

if (azureFileSharePolicy.RetentionPolicy.GetType() !=
typeof(ServiceClientModel.LongTermRetentionPolicy))
{
Logger.Instance.WriteDebug("Unknown RetentionPolicy object received: " +
azureFileSharePolicy.RetentionPolicy.GetType());
Logger.Instance.WriteWarning(Resources.UpdateToNewAzurePowershellWarning);
return null;
}

policyModel = new AzureFileSharePolicy();
AzureFileSharePolicy fileSharePolicyModel = policyModel as AzureFileSharePolicy;
fileSharePolicyModel.WorkloadType = WorkloadType.AzureFiles;
fileSharePolicyModel.BackupManagementType = BackupManagementType.AzureStorage;

ServiceClientModel.LongTermRetentionPolicy azureFileShareRetentionPolicy =
(ServiceClientModel.LongTermRetentionPolicy)azureFileSharePolicy.RetentionPolicy;
fileSharePolicyModel.RetentionPolicy =
PolicyHelpers.GetPSLongTermRetentionPolicy(azureFileShareRetentionPolicy, null);
policyModel = GetPolicyModelForAzureFileShare(serviceClientResponse, policyModel);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public AzureFileShareItem(ProtectedItemResource protectedItemResource,
/// <summary>
/// Azure File Share Item ExtendedInfo Class
/// </summary>
public class AzureFileShareExtendedInfo : AzureItemExtendedInfo
public class AzureFileShareItemExtendedInfo : AzureItemExtendedInfo
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
/// <summary>
/// Azure FileShare specific backup policy class.
/// </summary>
public class AzureFileSharePolicy : PolicyBase
public class AzureFileSharePolicy : AzurePolicy
{
/// <summary>
/// Object defining the retention behavior of this policy.
/// </summary>
public RetentionPolicyBase RetentionPolicy { get; set; }

public override void Validate()
{
base.Validate();
RetentionPolicy.Validate();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
{
/// <summary>
/// Azure Workload specific backup policy class.
/// </summary>
public class AzurePolicy : PolicyBase
{
/// <summary>
/// Object defining the schedule associated with this policy.
/// </summary>
public SchedulePolicyBase SchedulePolicy { get; set; }

/// <summary>
/// Object defining the retention behavior of this policy.
/// </summary>
public RetentionPolicyBase RetentionPolicy { get; set; }

public override void Validate()
{
base.Validate();

SchedulePolicy.Validate();
RetentionPolicy.Validate();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,9 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
/// <summary>
/// Azure VM specific backup policy class.
/// </summary>
public class AzureVmPolicy : PolicyBase
public class AzureVmPolicy : AzurePolicy
{
/// <summary>
/// Object defining the schedule associated with this policy.
/// </summary>
public SchedulePolicyBase SchedulePolicy { get; set; }

/// <summary>
/// Object defining the retention behavior of this policy.
/// </summary>
public RetentionPolicyBase RetentionPolicy { get; set; }

public override void Validate()
{
base.Validate();

SchedulePolicy.Validate();
RetentionPolicy.Validate();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="AzureFileShareModels\AzureFileShareItem.cs" />
<Compile Include="AzureModels\AzureContainer.cs" />
<Compile Include="AzureModels\AzureItem.cs" />
<Compile Include="AzureModels\AzurePolicy.cs" />
<Compile Include="AzureSqlModels\AzureSqlContainer.cs" />
<Compile Include="AzureSqlModels\AzureSqlItem.cs" />
<Compile Include="AzureSqlModels\AzureSqlPolicy.cs" />
Expand Down
Loading