Skip to content

Commit 3326e60

Browse files
committed
ARM SiteRecovery cmdlets (Vault, Server, Protection Container, Protection Entity, Protection Profile, Job)
1 parent 926e58c commit 3326e60

21 files changed

+2523
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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.Collections.Generic;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
using Microsoft.Azure.Management.SiteRecovery.Models;
20+
21+
namespace Microsoft.Azure.Commands.SiteRecovery
22+
{
23+
/// <summary>
24+
/// Retrieves Azure site Recovery Job.
25+
/// </summary>
26+
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryJob", DefaultParameterSetName = ASRParameterSets.ByParam)]
27+
[OutputType(typeof(IEnumerable<ASRJob>))]
28+
public class GetAzureSiteRecoveryJob : SiteRecoveryCmdletBase
29+
{
30+
#region Parameters
31+
/// <summary>
32+
/// Gets or sets Job Name.
33+
/// </summary>
34+
[Parameter(ParameterSetName = ASRParameterSets.ByName, Mandatory = true)]
35+
[ValidateNotNullOrEmpty]
36+
public string Name { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets Job Object.
40+
/// </summary>
41+
[Parameter(ParameterSetName = ASRParameterSets.ByObject, Mandatory = true, ValueFromPipeline = true)]
42+
[ValidateNotNullOrEmpty]
43+
public ASRJob Job { get; set; }
44+
45+
///// <summary>
46+
///// Gets or sets start time. Allows to filter the list of jobs started after the given
47+
///// start time.
48+
///// </summary>
49+
//[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "Represents start time of jobs to querying, jobs with the start time later than this will be returned")]
50+
//[ValidateNotNullOrEmpty]
51+
//public DateTime? StartTime { get; set; }
52+
53+
///// <summary>
54+
///// Gets or sets end time. Allows to filter the list of jobs ended before it.
55+
///// </summary>
56+
//[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "Represents end time of jobs to query.")]
57+
//[ValidateNotNullOrEmpty]
58+
//public DateTime? EndTime { get; set; }
59+
60+
///// <summary>
61+
///// Gets or sets target object id.
62+
///// </summary>
63+
//[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "ID of the object on which Job was targeted to.")]
64+
//[ValidateNotNullOrEmpty]
65+
//public string TargetObjectId { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets state. Take string input for possible States of ASR Job. Use this parameter
69+
/// to get filtered view of Jobs
70+
/// </summary>
71+
/// Considered Valid states from WorkflowStatus enum in SRS (WorkflowData.cs)
72+
[Parameter(ParameterSetName = ASRParameterSets.ByParam, HelpMessage = "State of job to return.")]
73+
[ValidateNotNullOrEmpty]
74+
[ValidateSet(
75+
"NotStarted",
76+
"InProgress",
77+
"Succeeded",
78+
"Other",
79+
"Failed",
80+
"Cancelled",
81+
"Suspended")]
82+
public string State { get; set; }
83+
#endregion Parameters
84+
85+
/// <summary>
86+
/// ProcessRecord of the command.
87+
/// </summary>
88+
public override void ExecuteCmdlet()
89+
{
90+
try
91+
{
92+
switch (this.ParameterSetName)
93+
{
94+
case ASRParameterSets.ByObject:
95+
this.Name = this.Job.Name;
96+
this.GetByName();
97+
break;
98+
99+
case ASRParameterSets.ByName:
100+
this.GetByName();
101+
break;
102+
103+
case ASRParameterSets.ByParam:
104+
default:
105+
this.GetByParam();
106+
break;
107+
}
108+
}
109+
catch (Exception exception)
110+
{
111+
this.HandleException(exception);
112+
}
113+
}
114+
115+
/// <summary>
116+
/// Queries by Name.
117+
/// </summary>
118+
private void GetByName()
119+
{
120+
this.WriteJob(RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(this.Name).Job);
121+
}
122+
123+
/// <summary>
124+
/// Queries by Parameters.
125+
/// </summary>
126+
private void GetByParam()
127+
{
128+
JobQueryParameter jqp = new JobQueryParameter();
129+
130+
//if (this.StartTime.HasValue)
131+
//{
132+
// jqp.StartTime =
133+
// this.StartTime.Value.ToUniversalTime().ToBinary().ToString();
134+
//}
135+
136+
//if (this.EndTime.HasValue)
137+
//{
138+
// jqp.EndTime =
139+
// this.EndTime.Value.ToUniversalTime().ToBinary().ToString();
140+
//}
141+
142+
//jqp.State = this.State;
143+
//jqp.ObjectId = this.TargetObjectId;
144+
145+
this.WriteJobs(RecoveryServicesClient.GetAzureSiteRecoveryJob(jqp).Jobs);
146+
}
147+
148+
/// <summary>
149+
/// Writes Job.
150+
/// </summary>
151+
/// <param name="job">JOB object</param>
152+
private void WriteJob(Microsoft.Azure.Management.SiteRecovery.Models.Job job)
153+
{
154+
this.WriteObject(new ASRJob(job));
155+
}
156+
157+
/// <summary>
158+
/// Writes Jobs.
159+
/// </summary>
160+
/// <param name="jobs">Job objects</param>
161+
private void WriteJobs(IList<Microsoft.Azure.Management.SiteRecovery.Models.Job> jobs)
162+
{
163+
this.WriteObject(jobs.Select(j => new ASRJob(j)), true);
164+
}
165+
}
166+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 Microsoft.Azure.Management.SiteRecovery.Models;
18+
19+
namespace Microsoft.Azure.Commands.SiteRecovery
20+
{
21+
/// <summary>
22+
/// Resumes Azure Site Recovery Job.
23+
/// </summary>
24+
[Cmdlet(VerbsLifecycle.Resume, "AzureSiteRecoveryJob", DefaultParameterSetName = ASRParameterSets.ByObject)]
25+
[OutputType(typeof(ASRJob))]
26+
public class ResumeAzureSiteRecoveryJob : SiteRecoveryCmdletBase
27+
{
28+
#region Parameters
29+
/// <summary>
30+
/// Gets or sets Job ID.
31+
/// </summary>
32+
[Parameter(ParameterSetName = ASRParameterSets.ByName, Mandatory = true)]
33+
[ValidateNotNullOrEmpty]
34+
public string Name { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets Job Object.
38+
/// </summary>
39+
[Parameter(ParameterSetName = ASRParameterSets.ByObject, Mandatory = true, ValueFromPipeline = true)]
40+
[ValidateNotNullOrEmpty]
41+
public ASRJob Job { get; set; }
42+
43+
/// <summary>
44+
/// Gets or sets job comments.
45+
/// </summary>
46+
[Parameter(Mandatory = false)]
47+
[ValidateNotNullOrEmpty]
48+
public string Comments { get; set; }
49+
#endregion Parameters
50+
51+
/// <summary>
52+
/// ProcessRecord of the command.
53+
/// </summary>
54+
public override void ExecuteCmdlet()
55+
{
56+
try
57+
{
58+
switch (this.ParameterSetName)
59+
{
60+
case ASRParameterSets.ByObject:
61+
this.Name = this.Job.Name;
62+
this.ResumesByName();
63+
break;
64+
65+
case ASRParameterSets.ByName:
66+
this.ResumesByName();
67+
break;
68+
}
69+
}
70+
catch (Exception exception)
71+
{
72+
this.HandleException(exception);
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Resumes by Name.
78+
/// </summary>
79+
private void ResumesByName()
80+
{
81+
ResumeJobParams resumeJobParams = new ResumeJobParams();
82+
if (string.IsNullOrEmpty(this.Comments))
83+
{
84+
this.Comments = " ";
85+
}
86+
87+
resumeJobParams.Comments = this.Comments;
88+
89+
LongRunningOperationResponse response = RecoveryServicesClient.ResumeAzureSiteRecoveryJob(this.Name, resumeJobParams);
90+
91+
JobResponse jobResponse =
92+
RecoveryServicesClient
93+
.GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));
94+
95+
WriteObject(new ASRJob(jobResponse.Job));
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)