Skip to content

Commit 9d7221c

Browse files
author
dragonfly91
committed
Merge branch 'dev1' into anudeeb-dev1
2 parents 7db66dd + 2769841 commit 9d7221c

File tree

15 files changed

+432
-6
lines changed

15 files changed

+432
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
/// <summary>
27+
/// Get default schedule policy object for given workloadType and backupmanagementtype
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureRMBackupRetentionPolicyObject"), OutputType(typeof(AzureRmRecoveryServicesRetentionPolicyBase))]
30+
public class GetAzureRMBackupRetentionPolicyObject : RecoveryServicesBackupCmdletBase
31+
{
32+
[Parameter(Mandatory = true, HelpMessage = "", ValueFromPipelineByPropertyName = true)]
33+
[ValidateNotNullOrEmpty]
34+
public WorkloadType WorkloadType { get; set; }
35+
36+
[Parameter(Mandatory = false, HelpMessage = "", ValueFromPipelineByPropertyName = true)]
37+
[ValidateNotNullOrEmpty]
38+
public BackupManagementType BackupManagementType { get; set; }
39+
40+
public override void ExecuteCmdlet()
41+
{
42+
base.ExecuteCmdlet();
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
24+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
25+
{
26+
/// <summary>
27+
/// Get default schedule policy object for given workloadType and backupmanagementtype
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureRMBackupSchedulePolicyObject"), OutputType(typeof(AzureRmRecoveryServicesSchedulePolicyBase))]
30+
public class GetAzureRMBackupSchedulePolicyObject : RecoveryServicesBackupCmdletBase
31+
{
32+
[Parameter(Mandatory = true, HelpMessage = "", ValueFromPipelineByPropertyName = true)]
33+
[ValidateNotNullOrEmpty]
34+
public WorkloadType WorkloadType { get; set; }
35+
36+
[Parameter(Mandatory = false, HelpMessage = "", ValueFromPipelineByPropertyName = true)]
37+
[ValidateNotNullOrEmpty]
38+
public BackupManagementType BackupManagementType { get; set; }
39+
40+
public override void ExecuteCmdlet()
41+
{
42+
base.ExecuteCmdlet();
43+
}
44+
}
45+
}
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 System;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter;
24+
25+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
26+
{
27+
/// <summary>
28+
/// To set RecoveryServicesVaultContext
29+
/// </summary>
30+
[Cmdlet(VerbsCommon.Set, "AzureRmRecoveryServicesVaultContext")]
31+
public class SetAzureRmRecoveryServicesVaultContext : RecoveryServicesBackupCmdletBase
32+
{
33+
[Parameter(Mandatory = true, HelpMessage = "", ValueFromPipeline = true)]
34+
[ValidateNotNullOrEmpty]
35+
public ARSVault Vault { get; set; }
36+
37+
public override void ExecuteCmdlet()
38+
{
39+
ExecutionBlock(() =>
40+
{
41+
base.ExecuteCmdlet();
42+
43+
// Validate required parameters taken from the Vault.
44+
if (string.IsNullOrEmpty(Vault.Name))
45+
{
46+
throw new ArgumentException(
47+
Properties.Resources.ResourceNameNullOrEmpty,
48+
Vault.Name);
49+
}
50+
51+
if (string.IsNullOrEmpty(Vault.ResouceGroupName))
52+
{
53+
throw new ArgumentException(
54+
Properties.Resources.CloudServiceNameNullOrEmpty,
55+
Vault.ResouceGroupName);
56+
}
57+
58+
AzureRmRecoveryServicesVaultCreds vaultCreds = new AzureRmRecoveryServicesVaultCreds(Vault.Name,
59+
Vault.ResouceGroupName, Vault.Location);
60+
61+
ClientProxyBase.UpdateCurrentVaultContext(vaultCreds);
62+
63+
//Add validation to check vault exist or not (see if we can resuse existing ASR code).
64+
65+
this.WriteObject(vaultCreds);
66+
});
67+
68+
}
69+
}
70+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
<ItemGroup>
7171
<Compile Include="Cmdlets\Container\GetAzureRmRecoveryServicesContainer.cs" />
7272
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesPolicy.cs" />
73+
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupSchedulePolicyObject.cs" />
74+
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRMBackupRetentionPolicyObject.cs" />
7375
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureRmRecoveryServicesPolicy.cs" />
7476
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureRmRecoveryServicesPolicy.cs" />
7577
<Compile Include="Properties\AssemblyInfo.cs" />

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<Reference Include="System.Xml" />
4343
</ItemGroup>
4444
<ItemGroup>
45+
<Compile Include="Conversions\JobConversions.cs" />
4546
<Compile Include="Validations\PolicyValidations.cs" />
4647
<Compile Include="Conversions\SchedulePolicyConversions.cs" />
4748
<Compile Include="Conversions\RetentionPolicyConversions.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.Management.RecoveryServices.Backup.Models;
17+
18+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers
19+
{
20+
public class JobConversions
21+
{
22+
#region Hydra to PS convertors
23+
24+
public static AzureRmRecoveryServicesJobBase GetPSJob(JobResponse hydraJob)
25+
{
26+
AzureRmRecoveryServicesJobBase response = null;
27+
28+
if (hydraJob.Item.Properties.GetType() == typeof(AzureIaaSVMJob))
29+
{
30+
response = GetPSAzureVmJob(hydraJob);
31+
}
32+
33+
return response;
34+
}
35+
36+
public static AzureRmRecoveryServicesAzureVmJob GetPSAzureVmJob(JobResponse hydraJob)
37+
{
38+
AzureRmRecoveryServicesAzureVmJob response = new AzureRmRecoveryServicesAzureVmJob();
39+
40+
response.InstanceId = hydraJob.Item.Id;
41+
// TODO: Fill complete conversion
42+
43+
return response;
44+
}
45+
46+
#endregion
47+
}
48+
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System;
16-
using System.Collections.Generic;
17-
using System.Linq;
18-
using System.Text;
19-
using System.Threading.Tasks;
15+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
2016

2117
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
2218
{
2319
public partial class HydraAdapter
2420
{
21+
public JobResponse GetJob(string resourceGroupName, string resourceName, string jobId)
22+
{
23+
return BmsAdapter.Client.Job.GetAsync(
24+
resourceGroupName,
25+
resourceName,
26+
jobId,
27+
BmsAdapter.GetCustomRequestHeaders(),
28+
BmsAdapter.CmdletCancellationToken).Result;
29+
}
2530
}
2631
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/ClientProxyBase.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
using System.Text;
2020
using System.Threading;
2121
using System.Threading.Tasks;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
2223

2324
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
2425
{
2526
public class ClientProxyBase
2627
{
28+
/// <summary>
29+
/// Recovery Services Vault Credentials.
30+
/// </summary>
31+
protected static AzureRmRecoveryServicesVaultCreds recoveryServicesVaultCreds = new AzureRmRecoveryServicesVaultCreds();
32+
2733
protected object[] Parameters;
2834

2935
/// <summary>
@@ -36,7 +42,7 @@ public class ClientProxyBase
3642
/// </summary>
3743
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
3844
public CancellationToken CmdletCancellationToken;
39-
45+
4046
public ClientProxyBase(params object[] parameters)
4147
{
4248
Parameters = parameters;
@@ -56,5 +62,24 @@ public string GetClientRequestId()
5662
{
5763
return ClientRequestId;
5864
}
65+
66+
public AzureRmRecoveryServicesVaultCreds GetVaultCredentials()
67+
{
68+
return recoveryServicesVaultCreds;
69+
}
70+
71+
public static void UpdateCurrentVaultContext(AzureRmRecoveryServicesVaultCreds vaultCreds)
72+
{
73+
object updateVaultContextOneAtATime = new object();
74+
lock (updateVaultContextOneAtATime)
75+
{
76+
recoveryServicesVaultCreds.ResourceName =
77+
vaultCreds.ResourceName;
78+
recoveryServicesVaultCreds.ResourceGroupName =
79+
vaultCreds.ResourceGroupName;
80+
recoveryServicesVaultCreds.Location =
81+
vaultCreds.Location;
82+
}
83+
}
5984
}
6085
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.Collections.Generic;
16+
17+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models
18+
{
19+
public class AzureRmRecoveryServicesAzureVmJob : AzureRmRecoveryServicesJobBase
20+
{
21+
public bool IsCancellable { get; set; }
22+
23+
public bool IsRetriable { get; set; }
24+
25+
public string VmVersion { get; set; }
26+
27+
public List<AzureRmRecoveryServicesAzureVmJobErrorInfo> ErrorDetails { get; set; }
28+
}
29+
30+
public class AzureRmRecoveryServicesAzureVmJobDetails : AzureRmRecoveryServicesAzureVmJob
31+
{
32+
/// <summary>
33+
/// Context sensitive error message that might be helpful in debugging the issue.
34+
/// Mostly this contains trace dumps from VM.
35+
/// </summary>
36+
public string DynamicErrorMessage { get; set; }
37+
38+
public Dictionary<string, string> Properties { get; set; }
39+
40+
public List<AzureRmRecoveryServicesAzureVmJobSubTask> SubTasks { get; set; }
41+
}
42+
43+
public class AzureRmRecoveryServicesAzureVmJobErrorInfo : AzureRmRecoveryServicesJobErrorInfoBase
44+
{
45+
public int ErrorCode { get; set; }
46+
}
47+
48+
public class AzureRmRecoveryServicesAzureVmJobSubTask : AzureRmRecoveryServicesJobSubTaskBase
49+
{
50+
}
51+
}

0 commit comments

Comments
 (0)