Skip to content

Commit bab1c8e

Browse files
committed
Merge pull request #8 from MabOneSdk/panbha
Local Changes for Commandlets
2 parents 6966a2d + b22b9b4 commit bab1c8e

File tree

7 files changed

+316
-5
lines changed

7 files changed

+316
-5
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
20+
using Microsoft.Azure.Common.Authentication;
21+
using Microsoft.Azure.Common.Authentication.Models;
22+
using System.Threading;
23+
using Hyak.Common;
24+
using Microsoft.Azure.Commands.AzureBackup.Properties;
25+
using System.Net;
26+
27+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
28+
{
29+
public abstract class AzureBackupDSCmdletBase : AzureBackupCmdletBase
30+
{
31+
// ToDO:
32+
// Correct Help message and other attributes related to paameters
33+
[Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ResourceGroupName, ValueFromPipelineByPropertyName = true)]
34+
[ValidateNotNullOrEmpty]
35+
public AzureBackupItem AzureBackupItem { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
base.ExecuteCmdlet();
40+
41+
WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}", AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName));
42+
43+
InitializeAzureBackupCmdlet(AzureBackupItem.ResourceGroupName, AzureBackupItem.ResourceName);
44+
}
45+
}
46+
}
47+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using System.Linq;
20+
using Microsoft.Azure.Management.BackupServices.Models;
21+
using MBS = Microsoft.Azure.Management.BackupServices;
22+
23+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
24+
{
25+
// ToDo:
26+
// Correct the Commandlet
27+
// Correct the OperationResponse
28+
// Get Tracking API from Piyush and Get JobResponse
29+
// Get JobResponse Object from Aditya
30+
31+
/// <summary>
32+
/// Get list of containers
33+
/// </summary>
34+
[Cmdlet(VerbsCommon.New, "AzureBackupItem"), OutputType(typeof(MBS.OperationResponse))]
35+
public class TriggerAzureBackup : AzureBackupDSCmdletBase
36+
{
37+
public override void ExecuteCmdlet()
38+
{
39+
base.ExecuteCmdlet();
40+
41+
ExecutionBlock(() =>
42+
{
43+
WriteVerbose("Making client call");
44+
45+
MBS.OperationResponse triggerBackUpInfo =
46+
AzureBackupClient.BackUp.TriggerBackUpAsync(GetCustomRequestHeaders(),
47+
AzureBackupItem.ContainerName,
48+
AzureBackupItem.DataSourceType,
49+
AzureBackupItem.DataSourceId,
50+
CmdletCancellationToken).Result;
51+
52+
WriteVerbose("Received policy response");
53+
WriteVerbose("Received policy response2");
54+
55+
WriteVerbose("Converting response");
56+
WriteAzureBackupProtectionPolicy(triggerBackUpInfo);
57+
});
58+
}
59+
60+
public void WriteAzureBackupProtectionPolicy(MBS.OperationResponse sourceOperationResponse)
61+
{
62+
// this needs to be uncommented once we have proper constructor
63+
//this.WriteObject(new AzureBackupRecoveryPoint(ResourceGroupName, ResourceName, sourceOperationResponse));
64+
}
65+
66+
public void WriteAzureBackupProtectionPolicy(IEnumerable<MBS.OperationResponse> sourceOperationResponseList)
67+
{
68+
List<MBS.OperationResponse> targetList = new List<MBS.OperationResponse>();
69+
70+
foreach (var sourceOperationResponse in sourceOperationResponseList)
71+
{
72+
// this needs to be uncommented once we have proper constructor
73+
//targetList.Add(new TriggerBackUpInfo(ResourceGroupName, ResourceName, sourceOperationResponse));
74+
}
75+
76+
this.WriteObject(targetList, true);
77+
}
78+
}
79+
}
80+

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public override void ExecuteCmdlet()
4646
IEnumerable<ProtectionPolicyInfo> policyObjects = null;
4747
if (Name != null)
4848
{
49-
policyObjects = policyListResponse.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase));
49+
policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase));
5050
}
5151
else
5252
{
53-
policyObjects = policyListResponse.Objects;
53+
policyObjects = policyListResponse.ProtectionPolicies.Objects;
5454
}
5555

5656
WriteVerbose("Converting response");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 System;
16+
using System.Management.Automation;
17+
using System.Collections.Generic;
18+
using System.Xml;
19+
using System.Linq;
20+
using Microsoft.Azure.Management.BackupServices.Models;
21+
22+
namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets
23+
{
24+
/// <summary>
25+
/// Get list of containers
26+
/// </summary>
27+
[Cmdlet(VerbsCommon.Get, "AzureBackupRecoveryPoint"), OutputType(typeof(AzureBackupRecoveryPoint), typeof(List<AzureBackupRecoveryPoint>))]
28+
public class GetAzureBackupRecoveryPoint : AzureBackupDSCmdletBase
29+
{
30+
[Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)]
31+
[ValidateNotNullOrEmpty]
32+
public string Id { get; set; }
33+
34+
public override void ExecuteCmdlet()
35+
{
36+
base.ExecuteCmdlet();
37+
38+
ExecutionBlock(() =>
39+
{
40+
WriteVerbose("Making client call");
41+
42+
RecoveryPointListResponse recoveryPointListResponse =
43+
AzureBackupClient.RecoveryPoint.ListAsync(GetCustomRequestHeaders(),
44+
AzureBackupItem.ContainerName,
45+
AzureBackupItem.DataSourceType,
46+
AzureBackupItem.DataSourceId,
47+
CmdletCancellationToken).Result;
48+
49+
WriteVerbose("Received policy response");
50+
WriteVerbose("Received policy response2");
51+
IEnumerable<RecoveryPointInfo> recoveryPointObjects = null;
52+
if (Id != null)
53+
{
54+
recoveryPointObjects = recoveryPointListResponse.RecoveryPoints.Objects.Where(x => x.InstanceId.Equals(Id, System.StringComparison.InvariantCultureIgnoreCase));
55+
}
56+
else
57+
{
58+
recoveryPointObjects = recoveryPointListResponse.RecoveryPoints.Objects;
59+
}
60+
61+
WriteVerbose("Converting response");
62+
WriteAzureBackupProtectionPolicy(recoveryPointObjects, AzureBackupItem);
63+
});
64+
}
65+
66+
public void WriteAzureBackupProtectionPolicy(RecoveryPointInfo sourceRecoverPoint, AzureBackupItem azureBackupItem)
67+
{
68+
this.WriteObject(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
69+
}
70+
71+
public void WriteAzureBackupProtectionPolicy(IEnumerable<RecoveryPointInfo> sourceRecoverPointList, AzureBackupItem azureBackupItem)
72+
{
73+
List<AzureBackupRecoveryPoint> targetList = new List<AzureBackupRecoveryPoint>();
74+
75+
foreach (var sourceRecoverPoint in sourceRecoverPointList)
76+
{
77+
targetList.Add(new AzureBackupRecoveryPoint(sourceRecoverPoint, azureBackupItem));
78+
}
79+
80+
this.WriteObject(targetList, true);
81+
}
82+
}
83+
}
84+

src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@
7777
<Reference Include="Microsoft.WindowsAzure.Management">
7878
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
7979
</Reference>
80-
<Reference Include="Microsoft.WindowsAzure.Management.BackupServicesManagment, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
81-
<SpecificVersion>False</SpecificVersion>
82-
<HintPath>..\..\..\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll</HintPath>
80+
<Reference Include="Microsoft.WindowsAzure.Management.BackupServicesManagment">
81+
<HintPath>..\..\..\..\..\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\bin\Net40-Debug\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll</HintPath>
8382
</Reference>
8483
<Reference Include="Microsoft.WindowsAzure.Management.Scheduler">
8584
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Scheduler.6.0.0\lib\net40\Microsoft.WindowsAzure.Management.Scheduler.dll</HintPath>
@@ -111,12 +110,18 @@
111110
<Reference Include="System.Xml" />
112111
</ItemGroup>
113112
<ItemGroup>
113+
<Compile Include="AzureBackupDSCmdletBase.cs" />
114114
<Compile Include="AzureBackupVaultCmdletBase.cs" />
115115
<Compile Include="AzureBackupCmdletBase.cs" />
116116
<Compile Include="AzureBackupCmdletHelpMessage.cs" />
117+
<Compile Include="Cmdlets\BackUp\TriggerBackUp.cs" />
117118
<Compile Include="Cmdlets\Jobs\GetAzureBackupJob.cs" />
118119
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureBackupProtectionPolicy.cs" />
120+
<Compile Include="Cmdlets\RecoveryPoint\GetAzureBackupRecoveryPoint.cs" />
119121
<Compile Include="Models\AzureBackupBaseObjects.cs" />
122+
<Compile Include="Models\AzureBackupContainer.cs" />
123+
<Compile Include="Models\AzureBackupItem.cs" />
124+
<Compile Include="Models\AzureBackupRecoveryPoint.cs" />
120125
<Compile Include="Models\ProtectionPolicy.cs" />
121126
<Compile Include="Properties\Resources.Designer.cs">
122127
<AutoGen>True</AutoGen>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ public class AzureBackupContainerContextObject : AzureBackupVaultContextObject
5353
/// Id of the Azure Backup Container
5454
/// </summary>
5555
public string ContainerId { get; set; }
56+
57+
public AzureBackupContainerContextObject()
58+
: base()
59+
{
60+
}
61+
62+
public AzureBackupContainerContextObject(AzureBackupContainerContextObject azureBackupContainerContextObject)
63+
: base(azureBackupContainerContextObject.ResourceGroupName, azureBackupContainerContextObject.ResourceName)
64+
{
65+
ContainerType = azureBackupContainerContextObject.ContainerType;
66+
ContainerName = azureBackupContainerContextObject.ContainerName;
67+
ContainerId = azureBackupContainerContextObject.ContainerId;
68+
}
5669
}
5770

5871
public class AzureBackupItemContextObject : AzureBackupContainerContextObject
@@ -66,5 +79,17 @@ public class AzureBackupItemContextObject : AzureBackupContainerContextObject
6679
/// DataSourceId of Azure Backup Item
6780
/// </summary>
6881
public string DataSourceType { get; set; }
82+
83+
public AzureBackupItemContextObject()
84+
: base()
85+
{
86+
}
87+
88+
public AzureBackupItemContextObject(AzureBackupItemContextObject azureBackupItemContextObject)
89+
: base(azureBackupItemContextObject)
90+
{
91+
DataSourceId = azureBackupItemContextObject.DataSourceId;
92+
DataSourceType = azureBackupItemContextObject.DataSourceType;
93+
}
6994
}
7095
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.BackupServices.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.AzureBackup.Cmdlets
23+
{
24+
public class AzureBackupRecoveryPointContextObject : AzureBackupItemContextObject
25+
{
26+
/// <summary>
27+
/// RecoveryPointId of Azure Backup Item
28+
/// </summary>
29+
public string RecoveryPointId { get; set; }
30+
31+
public AzureBackupRecoveryPointContextObject()
32+
: base()
33+
{
34+
}
35+
36+
public AzureBackupRecoveryPointContextObject(RecoveryPointInfo recoveryPointInfo, AzureBackupItem azureBackupItem)
37+
: base(azureBackupItem)
38+
{
39+
RecoveryPointId = recoveryPointInfo.InstanceId;
40+
}
41+
}
42+
43+
/// <summary>
44+
/// Represents Azure Backup Container
45+
/// </summary>
46+
public class AzureBackupRecoveryPoint : AzureBackupRecoveryPointContextObject
47+
{
48+
/// <summary>
49+
/// Last Recovery Point for the Azure Backup Item
50+
/// </summary>
51+
public DateTime RecoveryPointTime { get; set; }
52+
53+
/// <summary>
54+
/// DataSourceId of Azure Backup Item
55+
/// </summary>
56+
public string RecoveryPointType { get; set; }
57+
58+
public AzureBackupRecoveryPoint()
59+
: base()
60+
{
61+
}
62+
63+
public AzureBackupRecoveryPoint(RecoveryPointInfo recoveryPointInfo, AzureBackupItem azureBackupItem)
64+
: base(recoveryPointInfo, azureBackupItem)
65+
{
66+
RecoveryPointTime = recoveryPointInfo.RecoveryPointTime;
67+
RecoveryPointType = recoveryPointInfo.RecoveryPointType;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)