Skip to content

Commit ac3ac8b

Browse files
Merge pull request #324 from MabOneSdk/swatim-azuresql
Get Container and Unregister Container for AzureSql
2 parents a66d529 + 6510b2e commit ac3ac8b

File tree

11 files changed

+47
-11
lines changed

11 files changed

+47
-11
lines changed

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Conversions/ConversionHelpers.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ public static AzureRmRecoveryServicesBackupContainerBase GetContainerModel(Prote
3737
{
3838
containerModel = new AzureRmRecoveryServicesBackupIaasVmContainer(protectionContainer);
3939
}
40-
if (protectionContainer.Properties.GetType() == typeof(MabProtectionContainer))
40+
else if (protectionContainer.Properties.GetType() == typeof(MabProtectionContainer))
4141
{
4242
containerModel = new AzureRmRecoveryServicesMabContainer(protectionContainer);
4343
}
44+
else if (protectionContainer.Properties.GetType() == typeof(AzureSqlProtectionContainer))
45+
{
46+
containerModel = new AzureRmRecoveryServicesAzureSqlContainer(protectionContainer);
47+
}
4448
}
4549

4650
return containerModel;

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/AzureSqlModels/AzureRmRecoveryServicesAzureSqlContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2323
{
2424
public class AzureRmRecoveryServicesAzureSqlContainer : AzureRmRecoveryServicesBackupContainerBase
2525
{
26+
public ContainerRegistrationStatus Status { get; set; }
2627
public AzureRmRecoveryServicesAzureSqlContainer(ProtectionContainerResource protectionContainer)
2728
: base(protectionContainer)
2829
{
30+
AzureSqlProtectionContainer sqlProtectionContainer = (AzureSqlProtectionContainer)protectionContainer.Properties;
31+
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(sqlProtectionContainer.RegistrationStatus);
2932
}
3033
}
3134
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CommonModels/Utils.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public static ContainerType GetPsContainerType(string containerType)
163163
{
164164
return ContainerType.Windows;
165165
}
166+
else if (containerType == ContainerType.AzureSqlContainer.ToString())
167+
{
168+
return ContainerType.AzureSqlContainer;
169+
}
166170
else
167171
{
168172
throw new Exception("Unsupported ContainerType: " + containerType);

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Please contact Microsoft for further assistant.</value>
414414
<value>Please provide AzureRmBackupManagementServer of BackupEngineType as DpmEngine or DpmVenusEngine and provide BackupManagementType as SCDPM. Provided AzureRmBackupManagementServer has BackupEngineType {0} and backupManagementType {1} which is not valid.</value>
415415
</data>
416416
<data name="UnsupportedContainerException" xml:space="preserve">
417-
<value>Please provide Container of containerType as Windows and backupManagementType as MARS. Provided Container has containerType {0} and backupManagementType {1} which is invalid.</value>
417+
<value>Please provide Container of containerType as Windows and backupManagementType as MARS or Container of containerType as AzureSQL and backupManagementType as AzureSQL. Provided Container has containerType {0} and backupManagementType {1} which is invalid.</value>
418418
</data>
419419
<data name="GetRPErrorInputDatesShouldBeInUTC" xml:space="preserve">
420420
<value>Please specify startdate and enddate in UTC format</value>
@@ -447,6 +447,6 @@ Please contact Microsoft for further assistant.</value>
447447
<value>BackupManagementType provider for ContainerType {0} is incorrect.</value>
448448
</data>
449449
<data name="AllowedSqlRetentionRange" xml:space="preserve">
450-
<value>RetentionCount in Weeks should be 1-520, in Months should be 1-120 and Years should be 1-10</value>
450+
<value>Retention count in Weeks should be in between 1-520, in Months should be in between 1-120 and Years should be in between 1-10</value>
451451
</data>
452452
</root>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,25 @@ public ProtectionPolicyResponse ModifyPolicy()
188188

189189
public List<Models.AzureRmRecoveryServicesBackupContainerBase> ListProtectionContainers()
190190
{
191-
throw new NotImplementedException();
191+
string name = (string)this.ProviderData.ProviderParameters[ContainerParams.Name];
192+
193+
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
194+
195+
queryParams.BackupManagementType = Microsoft.Azure.Management.RecoveryServices.Backup.Models.BackupManagementType.AzureSql.ToString();
196+
197+
var listResponse = HydraAdapter.ListContainers(queryParams);
198+
199+
List<AzureRmRecoveryServicesBackupContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
200+
201+
if (!string.IsNullOrEmpty(name))
202+
{
203+
if (containerModels != null)
204+
{
205+
containerModels = containerModels.Where(x => x.Name == name).ToList();
206+
}
207+
}
208+
209+
return containerModels;
192210
}
193211

194212
public List<AzureRmRecoveryServicesBackupEngineBase> ListBackupManagementServers()

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/PsBackupProviderManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public IPsBackupProvider GetProviderInstance(ContainerType containerType, Backup
5858
throw new ArgumentException(String.Format(Resources.BackupManagementTypeIncorrectForContainerType, containerType));
5959
break;
6060
case ContainerType.AzureSqlContainer:
61-
if (backupManagementType == BackupManagementType.AzureSql)
61+
if (backupManagementType == BackupManagementType.AzureSql || backupManagementType == null)
6262
providerType = PsBackupProviderTypes.AzureSql;
6363
else
6464
throw new ArgumentException(String.Format(Resources.BackupManagementTypeRequiredForContainerType, containerType));

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesBackupContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class GetAzureRmRecoveryServicesBackupContainer : RecoveryServicesBackupC
3636

3737
[Parameter(Mandatory = false, Position = 2, HelpMessage = ParamHelpMsg.Container.BackupManagementType)]
3838
[ValidateNotNullOrEmpty]
39-
[ValidateSet("AzureVM", "MARS")]
39+
[ValidateSet("AzureVM", "MARS", "AzureSql")]
4040
public string BackupManagementType { get; set; }
4141

4242
[Parameter(Mandatory = false, Position = 3, HelpMessage = ParamHelpMsg.Container.Name)]

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Cmdlets/Container/UnregisterAzureRmRecoveryServicesBackupContainer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ public override void ExecuteCmdlet()
4141
{
4242
base.ExecuteCmdlet();
4343

44-
if (Container.ContainerType != ContainerType.Windows || Container.BackupManagementType != BackupManagementType.MARS)
44+
if (!((Container.ContainerType == ContainerType.Windows && Container.BackupManagementType == BackupManagementType.MARS) ||
45+
(Container.ContainerType == ContainerType.AzureSqlContainer && Container.BackupManagementType == BackupManagementType.AzureSql)))
4546
{
4647
throw new ArgumentException(String.Format(Resources.UnsupportedContainerException, Container.ContainerType, Container.BackupManagementType));
4748
}
48-
AzureRmRecoveryServicesMabContainer mabContainer = Container as AzureRmRecoveryServicesMabContainer;
49-
string containerName = mabContainer.Name;
49+
string containerName = Container.Name;
50+
if (Container.ContainerType == ContainerType.AzureSqlContainer)
51+
containerName = ContainerConstansts.SqlContainerNamePrefix + containerName;
5052
HydraAdapter.UnregisterContainers(containerName);
5153
});
5254
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public class PolicyConstants
2424
public const int MinPolicyNameLength = 3;
2525
public const int MaxPolicyNameLength = 150;
2626
}
27+
28+
public class ContainerConstansts
29+
{
30+
public const string SqlContainerNamePrefix = "AzureSqlContainer;";
31+
}
2732
}

0 commit comments

Comments
 (0)