Skip to content

Commit f6cf4bd

Browse files
committed
Fix for register unregister cmdlet
1 parent b6fce04 commit f6cf4bd

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/RegisterAzureBackupContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private bool IsDiscoveryNeeded(string vmName, string rgName, out CSMContainerRes
162162
FriendlyName = vmName,
163163
};
164164

165-
//First check if container is discoverd or not
165+
//First check if container is discovered or not
166166
var containers = AzureBackupClient.ListContainers(parameters);
167167
WriteDebug(String.Format("Container count returned from service: {0}.", containers.Count()));
168168
if (containers.Count() == 0)

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Container/UnregisterAzureBackupContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void ExecuteCmdlet()
4545
{
4646
base.ExecuteCmdlet();
4747

48-
AzureBackupContainerType containerType = (AzureBackupContainerType)Enum.Parse(typeof(AzureBackupContainerType), Container.ContainerType);
48+
AzureBackupContainerType containerType = (AzureBackupContainerType)Enum.Parse(typeof(AzureBackupContainerType), Container.ContainerType, true);
4949
switch (containerType)
5050
{
5151
case AzureBackupContainerType.Windows:

src/ResourceManager/AzureBackup/Commands.AzureBackup/Helpers/ContainerHelpers.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Helpers
3636
{
3737
internal class ContainerHelpers
3838
{
39-
private static readonly Regex ResourceGroupRegex = new Regex(@"/resourceGroups/(?<resourceGroupName>.+)/providers/", RegexOptions.Compiled);
39+
private static readonly Regex ResourceGroupRegex = new Regex(@"/subscriptions/(?<subscriptionsId>.+)/resourceGroups/(?<resourceGroupName>.+)/providers/(?<providersName>.+)/BackupVault/(?<BackupVaultName>.+)/containers/(?<containersName>.+)", RegexOptions.Compiled);
4040

4141
internal static AzureBackupContainerType GetContainerType(string customerType)
4242
{
@@ -70,6 +70,28 @@ internal static AzureBackupContainerType GetContainerType(string customerType)
7070
return containerType;
7171
}
7272

73+
internal static AzureBackupContainerType GetTypeForManagedContainer(string managedContainerTypeString)
74+
{
75+
ManagedContainerType managedContainerType = (ManagedContainerType)Enum.Parse(typeof(ManagedContainerType), managedContainerTypeString, true);
76+
77+
AzureBackupContainerType containerType = 0;
78+
79+
switch (managedContainerType)
80+
{
81+
case ManagedContainerType.Invalid:
82+
break;
83+
case ManagedContainerType.IaasVM:
84+
containerType = AzureBackupContainerType.AzureVM;
85+
break;
86+
case ManagedContainerType.IaasVMService:
87+
break;
88+
default:
89+
break;
90+
}
91+
92+
return containerType;
93+
}
94+
7395
internal static string GetQueryFilter(ListContainerQueryParameter queryParams)
7496
{
7597
NameValueCollection collection = new NameValueCollection();
@@ -101,10 +123,10 @@ internal static string GetRGNameFromId(string id)
101123
var match = ResourceGroupRegex.Match(id);
102124
if (match.Success)
103125
{
104-
var resourceGroupNameGroup = match.Groups["resourceGroupName"];
105-
if (resourceGroupNameGroup != null && resourceGroupNameGroup.Success)
126+
var vmRGName = match.Groups["containersName"];
127+
if (vmRGName != null && vmRGName.Success)
106128
{
107-
return resourceGroupNameGroup.Value;
129+
return vmRGName.Value;
108130
}
109131
}
110132

src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupBaseObjects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public AzureBackupContainerContextObject(AzureBackupContainer azureBackupContain
9292
public AzureBackupContainerContextObject(AzurePSBackupVault vault, CSMContainerResponse containerInfo)
9393
: base(vault.ResourceGroupName, vault.Name, vault.Region)
9494
{
95-
ContainerType = containerInfo.Properties.ContainerType;
95+
ContainerType = ContainerHelpers.GetTypeForManagedContainer(containerInfo.Properties.ContainerType).ToString();
9696
ContainerUniqueName = containerInfo.Name;
9797
}
9898
}

0 commit comments

Comments
 (0)