Skip to content

Commit 62233cd

Browse files
Merge pull request #214 from MabOneSdk/swatim-dev1
Get and Unregister Container Powershell Cmdlet
2 parents 9de143f + a37cd76 commit 62233cd

22 files changed

+766
-9
lines changed

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ internal static class Container
2828
public const string ResourceGroupName = "The ResourceGroup of the resource being managed by the Azure Backup service (for example: ResourceGroup name of the VM).";
2929
public const string Status = "The registration status of the Azure Backup container.";
3030
public const string ContainerType = "The type of the Azure Backup container. This can be a Windows Server, an Azure IaaS VM, or a Data Protection Manager server.";
31+
public const string BackupManagementType = "The backup management type of the Azure Backup container";
32+
public const string RegisteredContainer = "The recovery services backup container.";
3133
}
3234

3335
internal static class Common
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// Get list of containers
29+
/// </summary>
30+
[Cmdlet(VerbsCommon.Get, "AzureRmRecoveryServicesContainer"), OutputType(typeof(List<AzureRmRecoveryServicesContainerBase>), typeof(AzureRmRecoveryServicesContainerBase))]
31+
public class GetAzureRmBackupManagementServer : RecoveryServicesBackupCmdletBase
32+
{
33+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.Name)]
34+
[ValidateNotNullOrEmpty]
35+
public string Name { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
44+
{
45+
{ContainerParams.ContainerType, ContainerType.Windows},
46+
{ContainerParams.BackupManagementType, BackupManagementType.Scdpm},
47+
{ContainerParams.Name, Name}
48+
}, HydraAdapter);
49+
50+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType.Windows, BackupManagementType.Scdpm);
51+
52+
var containerModels = psBackupProvider.ListProtectionContainers();
53+
54+
if (containerModels.Count == 1)
55+
{
56+
WriteObject(containerModels.First());
57+
}
58+
else
59+
{
60+
WriteObject(containerModels);
61+
}
62+
});
63+
}
64+
}
65+
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletB
3434
[ValidateNotNullOrEmpty]
3535
public ContainerType ContainerType { get; set; }
3636

37+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.BackupManagementType)]
38+
[ValidateNotNullOrEmpty]
39+
public BackupManagementType BackupManagementType { get; set; }
40+
3741
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Container.Name)]
3842
[ValidateNotNullOrEmpty]
3943
public string Name { get; set; }
@@ -55,12 +59,13 @@ public override void ExecuteCmdlet()
5559
PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary<System.Enum, object>()
5660
{
5761
{ContainerParams.ContainerType, ContainerType},
62+
{ContainerParams.BackupManagementType, BackupManagementType},
5863
{ContainerParams.Name, Name},
5964
{ContainerParams.ResourceGroupName, ResourceGroupName},
6065
{ContainerParams.Status, Status},
6166
}, HydraAdapter);
6267

63-
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType);
68+
IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(ContainerType, BackupManagementType);
6469
var containerModels = psBackupProvider.ListProtectionContainers();
6570

6671
if (containerModels.Count == 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Container
26+
{
27+
[Cmdlet(VerbsLifecycle.Unregister, "AzureRmBackupManagementServer")]
28+
public class UnregisterAzureRmBackupManagementServer : RecoveryServicesBackupCmdletBase
29+
{
30+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.RegisteredContainer)]
31+
[ValidateNotNullOrEmpty]
32+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
33+
34+
public override void ExecuteCmdlet()
35+
{
36+
ExecutionBlock(() =>
37+
{
38+
base.ExecuteCmdlet();
39+
40+
if (Container.ContainerType != ContainerType.Windows || Container.BackupManagementType != BackupManagementType.Scdpm)
41+
{
42+
throw new ArgumentException(String.Format("Please provide Container of containerType Windows and backupManagementType Scdpm. Provided Container has containerType {0} and backupManagementType {1}", Container.ContainerType, Container.BackupManagementType));
43+
}
44+
45+
string containerName = Container.Name;
46+
HydraAdapter.UnregisterContainers(containerName);
47+
});
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
16+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
17+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Linq;
21+
using System.Management.Automation;
22+
using System.Text;
23+
using System.Threading.Tasks;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// Get list of containers
29+
/// </summary>
30+
[Cmdlet(VerbsLifecycle.Unregister, "AzureRmRecoveryServicesBackupContainer")]
31+
public class UnregisterAzureRmRecoveryServicesBackupContainer : RecoveryServicesBackupCmdletBase
32+
{
33+
[Parameter(Mandatory = true, HelpMessage = ParamHelpMsg.Container.RegisteredContainer)]
34+
[ValidateNotNullOrEmpty]
35+
public AzureRmRecoveryServicesContainerBase Container { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
if (Container.ContainerType != ContainerType.Windows || Container.BackupManagementType != BackupManagementType.Mars)
44+
{
45+
throw new ArgumentException(String.Format("Please provide Container of containerType Windows and backupManagementType Mars. Provided Container has containerType {0} and backupManagementType {1}", Container.ContainerType, Container.BackupManagementType));
46+
}
47+
string containerName = Container.Name;
48+
HydraAdapter.UnregisterContainers(containerName);
49+
});
50+
}
51+
}
52+
}
53+

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<AssemblyName>Microsoft.Azure.Commands.RecoveryServices.Backup</AssemblyName>
1212
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
1416
</PropertyGroup>
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1618
<DebugSymbols>true</DebugSymbols>
@@ -72,7 +74,10 @@
7274
<Reference Include="System.Xml" />
7375
</ItemGroup>
7476
<ItemGroup>
77+
<Compile Include="Cmdlets\Container\GetAzureRmBackupManagementServer.cs" />
7578
<Compile Include="Cmdlets\Container\GetAzureRmRecoveryServicesContainer.cs" />
79+
<Compile Include="Cmdlets\Container\UnregisterAzureRmBackupManagementServer.cs" />
80+
<Compile Include="Cmdlets\Container\UnregisterAzureRmRecoveryServicesBackupContainer.cs" />
7681
<Compile Include="Cmdlets\Item\EnableAzureRmRecoveryServicesProtection.cs" />
7782
<Compile Include="Cmdlets\Item\GetAzureRmRecoveryServicesItem.cs" />
7883
<Compile Include="Cmdlets\Jobs\GetAzureRmRecoveryServicesJob.cs" />
@@ -143,6 +148,13 @@
143148
<None Include="packages.config" />
144149
</ItemGroup>
145150
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
151+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
152+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
153+
<PropertyGroup>
154+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
155+
</PropertyGroup>
156+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
157+
</Target>
146158
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
147159
Other similar extension points exist, see Microsoft.Common.targets.
148160
<Target Name="BeforeBuild">

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/ContainerAPIs.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,20 @@ public BaseRecoveryServicesJobResponse RefreshContainers()
4949
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, BmsAdapter.CmdletCancellationToken).Result;
5050
return response;
5151
}
52+
53+
/// <summary>
54+
/// Unregister a container in service
55+
/// </summary>
56+
/// <returns></returns>
57+
public AzureOperationResponse UnregisterContainers(string containerName)
58+
{
59+
string resourceName = BmsAdapter.GetResourceName();
60+
string resourceGroupName = BmsAdapter.GetResourceGroupName();
61+
62+
var response = BmsAdapter.Client.Container.UnregisterAsync(
63+
resourceGroupName, resourceName, containerName,
64+
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
65+
return response;
66+
}
5267
}
5368
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/CmdletParamEnums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public enum ContainerParams
2929
Name,
3030
ResourceGroupName,
3131
Status,
32+
Container
3233
}
3334

3435
public enum GetRecoveryPointParams

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Commands.RecoveryServices.Backup.Models.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmPolicy.cs" />
5454
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmItem.cs" />
5555
<Compile Include="AzureVmModels\AzureRmRecoveryServicesAzureVmContainer.cs" />
56+
<Compile Include="DpmModels\AzureRmRecoveryServicesDpmContainer.cs" />
57+
<Compile Include="MabModels\AzureRmRecoveryServicesMabContainer.cs" />
5658
<Compile Include="Properties\AssemblyInfo.cs" />
5759
<Compile Include="Properties\Resources.Designer.cs">
5860
<DependentUpon>Resources.resx</DependentUpon>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
2323
public enum ContainerType
2424
{
2525
AzureVM = 1,
26-
27-
AzureSqlContainer,
26+
//AzureSqlContainer,
27+
Windows
2828
}
2929

3030
public enum BackupManagementType
3131
{
3232
AzureVM = 1,
33+
Mars,
34+
Scdpm
3335
}
3436

3537
public enum WorkloadType
@@ -40,8 +42,9 @@ public enum WorkloadType
4042
public enum PsBackupProviderTypes
4143
{
4244
IaasVm = 1,
43-
4445
AzureSql,
46+
Mab,
47+
Dpm
4548
}
4649

4750
public enum ContainerRegistrationStatus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
23+
{
24+
public class AzureRmRecoveryServicesDpmContainer : AzureRmRecoveryServicesContainerBase
25+
{
26+
/// <summary>
27+
/// Resource Group where the Container is present
28+
/// </summary>
29+
public string ResourceGroupName { get; set; }
30+
31+
/// <summary>
32+
/// Friendly name of the container
33+
/// </summary>
34+
public string FriendlyName { get; set; }
35+
36+
/// <summary>
37+
/// Registration Status
38+
/// </summary>
39+
public ContainerRegistrationStatus Status { get; set; }
40+
41+
public AzureRmRecoveryServicesDpmContainer(ProtectionContainerResource protectionContainer)
42+
: base(protectionContainer)
43+
{
44+
DpmProtectionContainer dpmProtectionContainer = (DpmProtectionContainer)protectionContainer.Properties;
45+
ResourceGroupName = IdUtils.GetResourceGroupName(protectionContainer.Id);
46+
FriendlyName = dpmProtectionContainer.FriendlyName;
47+
Status = EnumUtils.GetEnum<ContainerRegistrationStatus>(dpmProtectionContainer.RegistrationStatus);
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)