Skip to content

Commit 3f57ac0

Browse files
committed
Merge branch 'dev' of https://github.com/elvg/azure-powershell into dev3
2 parents 1bbecef + 3a11633 commit 3f57ac0

File tree

9 files changed

+118
-55
lines changed

9 files changed

+118
-55
lines changed

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/AzureAutomationBaseCmdlet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public override void ExecuteCmdlet()
8585
}
8686
}
8787

88-
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent || cloudException.Response.StatusCode == HttpStatusCode.NotFound)
88+
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
8989
{
90-
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.ResourceNotFound), cloudException);
90+
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.AutomationAccountNotFound), cloudException);
9191
}
9292

9393
throw;

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJob.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class GetAzureAutomationJob : AzureAutomationBaseCmdlet
3838
/// <summary>
3939
/// Gets or sets the runbook name of the job.
4040
/// </summary>
41-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, HelpMessage = "The runbook name of the job.")]
41+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, HelpMessage = "The runbook name of the job.")]
42+
[Alias("Name")]
4243
public string RunbookName { get; set; }
4344

4445
/// <summary>

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/GetAzureAutomationJobOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class GetAzureAutomationJobOutput : AzureAutomationBaseCmdlet
3232
/// Gets or sets the job id
3333
/// </summary>
3434
[Alias("JobId")]
35-
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, HelpMessage = "The job name or Id")]
35+
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true, HelpMessage = "The job name or Id")]
3636
public Guid Id { get; set; }
3737

3838
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type. Defaults to Any.")]

src/ServiceManagement/Automation/Commands.Automation/Cmdlet/StartAzureAutomationRunbook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class StartAzureAutomationRunbook : AzureAutomationBaseCmdlet
3030
/// <summary>
3131
/// Gets or sets the runbook name
3232
/// </summary>
33-
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook name.")]
33+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByRunbookName, Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The runbook name.")]
3434
[ValidateNotNullOrEmpty]
3535
[Alias("RunbookName")]
3636
public string Name { get; set; }

src/ServiceManagement/Automation/Commands.Automation/Common/AutomationClient.cs

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void DeleteSchedule(string automationAccountName, string scheduleName)
107107
}
108108
catch (CloudException cloudException)
109109
{
110-
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
110+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
111111
{
112112
throw new ResourceNotFoundException(typeof(Schedule),
113113
string.Format(CultureInfo.CurrentCulture, Resources.ScheduleNotFound, scheduleName));
@@ -144,6 +144,8 @@ public Schedule UpdateSchedule(string automationAccountName, string scheduleName
144144
{
145145
AutomationManagement.Models.Schedule scheduleModel = this.GetScheduleModel(automationAccountName,
146146
scheduleName);
147+
isEnabled = (isEnabled.HasValue) ? isEnabled : scheduleModel.Properties.IsEnabled;
148+
description = description ?? scheduleModel.Properties.Description; ;
147149
return this.UpdateScheduleHelper(automationAccountName, scheduleModel, isEnabled, description);
148150
}
149151

@@ -228,7 +230,20 @@ public Runbook CreateRunbookByPath(string automationAccountName, string runbookP
228230

229231
public void DeleteRunbook(string automationAccountName, string runbookName)
230232
{
231-
this.automationManagementClient.Runbooks.Delete(automationAccountName, runbookName);
233+
try
234+
{
235+
this.automationManagementClient.Runbooks.Delete(automationAccountName, runbookName);
236+
}
237+
catch (CloudException cloudException)
238+
{
239+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
240+
{
241+
throw new ResourceNotFoundException(typeof(Connection), string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, runbookName));
242+
}
243+
244+
throw;
245+
}
246+
232247
}
233248

234249
public Runbook UpdateRunbook(string automationAccountName, string runbookName, string description,
@@ -249,7 +264,7 @@ public Runbook UpdateRunbook(string automationAccountName, string runbookName, s
249264
runbookUpdateParameters.Properties = new RunbookUpdateProperties();
250265
runbookUpdateParameters.Properties.Description = description ?? runbookModel.Properties.Description;
251266
runbookUpdateParameters.Properties.LogProgress = (logProgress.HasValue) ? logProgress.Value : runbookModel.Properties.LogProgress;
252-
runbookUpdateParameters.Properties.LogVerbose = (logProgress.HasValue) ? logProgress.Value : runbookModel.Properties.LogVerbose;
267+
runbookUpdateParameters.Properties.LogVerbose = (logVerbose.HasValue) ? logVerbose.Value : runbookModel.Properties.LogVerbose;
253268

254269
var runbook = this.automationManagementClient.Runbooks.Update(automationAccountName, runbookUpdateParameters).Runbook;
255270

@@ -266,8 +281,8 @@ public RunbookDefinition UpdateRunbookDefinition(string automationAccountName, s
266281
string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, runbookName));
267282
}
268283

269-
if ((0 ==
270-
String.Compare(runbook.Properties.State, RunbookState.Edit, CultureInfo.InvariantCulture,
284+
if ((0 !=
285+
String.Compare(runbook.Properties.State, RunbookState.Published, CultureInfo.InvariantCulture,
271286
CompareOptions.IgnoreCase) && overwrite == false))
272287
{
273288
throw new ResourceCommonException(typeof(Runbook),
@@ -295,19 +310,40 @@ public IEnumerable<RunbookDefinition> ListRunbookDefinitionsByRunbookName(string
295310
string.Format(CultureInfo.CurrentCulture, Resources.RunbookNotFound, runbookName));
296311
}
297312

298-
if (0 !=
299-
String.Compare(runbook.Properties.State, RunbookState.Published, CultureInfo.InvariantCulture,
300-
CompareOptions.IgnoreCase) && isDraft != null && isDraft.Value == true)
313+
var draftContent = String.Empty;
314+
var publishedContent = String.Empty;
315+
316+
if (0 != String.Compare(runbook.Properties.State, RunbookState.Published, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
301317
{
302-
var draftContent =
303-
this.automationManagementClient.RunbookDraft.Content(automationAccountName, runbookName).Stream;
304-
ret.Add(new RunbookDefinition(automationAccountName, runbook, draftContent, Constants.Draft));
318+
draftContent = this.automationManagementClient.RunbookDraft.Content(automationAccountName, runbookName).Stream;
305319
}
306-
else
320+
if (0 != String.Compare(runbook.Properties.State, RunbookState.New, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
307321
{
308-
var publishedContent =
309-
this.automationManagementClient.Runbooks.Content(automationAccountName, runbookName).Stream;
310-
ret.Add(new RunbookDefinition(automationAccountName, runbook, publishedContent, Constants.Published));
322+
publishedContent = this.automationManagementClient.Runbooks.Content(automationAccountName, runbookName).Stream;
323+
}
324+
325+
// if no slot specified return both draft and publish content
326+
if (false == isDraft.HasValue)
327+
{
328+
if (false == String.IsNullOrEmpty(draftContent)) ret.Add(new RunbookDefinition(automationAccountName, runbook, draftContent, Constants.Draft));
329+
if (false == String.IsNullOrEmpty(publishedContent)) ret.Add(new RunbookDefinition(automationAccountName, runbook, publishedContent, Constants.Published));
330+
}
331+
else
332+
{
333+
if (isDraft.Value == true)
334+
{
335+
336+
if (String.IsNullOrEmpty(draftContent)) throw new ResourceCommonException(typeof(Runbook),
337+
string.Format(CultureInfo.CurrentCulture, Resources.RunbookHasNoDraftVersion, runbookName));
338+
if (false == String.IsNullOrEmpty(draftContent)) ret.Add(new RunbookDefinition(automationAccountName, runbook, draftContent, Constants.Draft));
339+
}
340+
else
341+
{
342+
if (String.IsNullOrEmpty(publishedContent)) throw new ResourceCommonException(typeof(Runbook),
343+
string.Format(CultureInfo.CurrentCulture, Resources.RunbookHasNoPublishedVersion, runbookName));
344+
345+
if (false == String.IsNullOrEmpty(publishedContent)) ret.Add(new RunbookDefinition(automationAccountName, runbook, publishedContent, Constants.Published));
346+
}
311347
}
312348

313349
return ret;
@@ -421,10 +457,15 @@ public void DeleteVariable(string automationAccountName, string variableName)
421457
this.automationManagementClient.Variables.Delete(automationAccountName, variableName);
422458
}
423459
}
424-
catch (ResourceNotFoundException)
460+
catch (CloudException cloudException)
425461
{
426-
// the variable does not exists or already deleted. Do nothing. Return.
427-
return;
462+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
463+
{
464+
throw new ResourceNotFoundException(typeof(Variable),
465+
string.Format(CultureInfo.CurrentCulture, Resources.VariableNotFound, variableName));
466+
}
467+
468+
throw;
428469
}
429470
}
430471

@@ -583,10 +624,11 @@ public CredentialInfo CreateCredential(string automationAccountName, string name
583624
public CredentialInfo UpdateCredential(string automationAccountName, string name, string userName, string password,
584625
string description)
585626
{
627+
var exisitngCredential = this.GetCredential(automationAccountName, name);
586628
var credentialUpdateParams = new AutomationManagement.Models.CredentialUpdateParameters();
587629
credentialUpdateParams.Name = name;
588630
credentialUpdateParams.Properties = new AutomationManagement.Models.CredentialUpdateProperties();
589-
if (description != null) credentialUpdateParams.Properties.Description = description;
631+
credentialUpdateParams.Properties.Description = description ?? exisitngCredential.Description;
590632

591633
credentialUpdateParams.Properties.UserName = userName;
592634
credentialUpdateParams.Properties.Password = password;
@@ -647,7 +689,7 @@ public void DeleteCredential(string automationAccountName, string name)
647689
{
648690
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
649691
{
650-
throw new ResourceNotFoundException(typeof(Schedule), string.Format(CultureInfo.CurrentCulture, Resources.CredentialNotFound, name));
692+
throw new ResourceNotFoundException(typeof(Credential), string.Format(CultureInfo.CurrentCulture, Resources.CredentialNotFound, name));
651693
}
652694

653695
throw;
@@ -757,9 +799,9 @@ public void DeleteModule(string automationAccountName, string name)
757799
}
758800
catch (CloudException cloudException)
759801
{
760-
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
802+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
761803
{
762-
throw new ResourceNotFoundException(typeof(Schedule), string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
804+
throw new ResourceNotFoundException(typeof(Module), string.Format(CultureInfo.CurrentCulture, Resources.ModuleNotFound, name));
763805
}
764806

765807
throw;
@@ -1129,7 +1171,19 @@ public IEnumerable<CertificateInfo> ListCertificates(string automationAccountNam
11291171

11301172
public void DeleteCertificate(string automationAccountName, string name)
11311173
{
1132-
this.automationManagementClient.Certificates.Delete(automationAccountName, name);
1174+
try
1175+
{
1176+
this.automationManagementClient.Certificates.Delete(automationAccountName, name);
1177+
}
1178+
catch (CloudException cloudException)
1179+
{
1180+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
1181+
{
1182+
throw new ResourceNotFoundException(typeof(Schedule), string.Format(CultureInfo.CurrentCulture, Resources.CertificateNotFound, name));
1183+
}
1184+
1185+
throw;
1186+
}
11331187
}
11341188

11351189
#endregion
@@ -1230,7 +1284,19 @@ public IEnumerable<Connection> ListConnections(string automationAccountName)
12301284

12311285
public void DeleteConnection(string automationAccountName, string name)
12321286
{
1233-
this.automationManagementClient.Connections.Delete(automationAccountName, name);
1287+
try
1288+
{
1289+
this.automationManagementClient.Connections.Delete(automationAccountName, name);
1290+
}
1291+
catch (CloudException cloudException)
1292+
{
1293+
if (cloudException.Response.StatusCode == HttpStatusCode.NoContent)
1294+
{
1295+
throw new ResourceNotFoundException(typeof(Connection), string.Format(CultureInfo.CurrentCulture, Resources.ConnectionNotFound, name));
1296+
}
1297+
1298+
throw;
1299+
}
12341300
}
12351301

12361302
#endregion

src/ServiceManagement/Automation/Commands.Automation/Model/AutomationAccount.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public AutomationAccount(AutomationManagement.Models.CloudService cloudService,
3939

4040
this.AutomationAccountName = resource.Name;
4141
this.Location = cloudService.GeoRegion;
42-
this.Plan = resource.Plan;
43-
4442
switch (resource.State)
4543
{
4644
case AutomationManagement.Models.AutomationResourceState.Started:
@@ -53,6 +51,8 @@ public AutomationAccount(AutomationManagement.Models.CloudService cloudService,
5351
this.State = resource.State;
5452
break;
5553
}
54+
55+
if (resource.IntrinsicSettings != null) this.Plan = resource.IntrinsicSettings.SubscriptionPlan;
5656
}
5757

5858
/// <summary>

src/ServiceManagement/Automation/Commands.Automation/Model/Job.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ public Job(string accountName, Azure.Management.Automation.Models.Job job)
3939
Requires.Argument("accountName", accountName).NotNull();
4040

4141
this.AutomationAccountName = accountName;
42-
this.Location = job.Location;
43-
this.Type = job.Type;
44-
this.Tags = job.Tags ?? new Dictionary<string, string>();
45-
this.Id = Guid.Parse(job.Name);
4642

4743
if (job.Properties == null) return;
4844

45+
this.Id = job.Properties.JobId;
4946
this.CreationTime = job.Properties.CreationTime.ToLocalTime();
5047
this.LastModifiedTime = job.Properties.LastModifiedTime.ToLocalTime();
5148
this.StartTime = job.Properties.StartTime;
@@ -75,21 +72,6 @@ public Job()
7572
/// </summary>
7673
public Guid Id { get; set; }
7774

78-
/// <summary>
79-
/// Gets or sets the location.
80-
/// </summary>
81-
public string Location { get; set; }
82-
83-
/// <summary>
84-
/// Gets or sets the type.
85-
/// </summary>
86-
public string Type { get; set; }
87-
88-
/// <summary>
89-
/// Gets or sets the tags.
90-
/// </summary>
91-
public IDictionary<string, string> Tags { get; set; }
92-
9375
/// <summary>
9476
/// Gets or sets the tags.
9577
/// </summary>

src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.Designer.cs

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/Automation/Commands.Automation/Properties/Resources.resx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@
172172
<comment>Automation</comment>
173173
</data>
174174
<data name="ResourceExists" xml:space="preserve">
175-
<value>Resource exists.</value>
175+
<value>Resource exist.</value>
176+
<comment>Automation</comment>
176177
</data>
177178
<data name="RunbookNotFound" xml:space="preserve">
178179
<value>The Runbook was not found. Runbook name: {0}.</value>
@@ -247,7 +248,7 @@
247248
<comment>Automation</comment>
248249
</data>
249250
<data name="ResourceNotFound" xml:space="preserve">
250-
<value>Resource does not exists.</value>
251+
<value>Resource does not exist.</value>
251252
<comment>Automation</comment>
252253
</data>
253254
<data name="ConnectionAlreadyExists" xml:space="preserve">
@@ -266,4 +267,8 @@
266267
<value>Password and Exportable parameters cannot be updated for an existing certificate. They can only be specified when overwriting this certificate with a new one, via the Path parameter</value>
267268
<comment>Automation</comment>
268269
</data>
270+
<data name="RunbookHasNoDraftVersion" xml:space="preserve">
271+
<value>The runbook has no draft version. Runbook name {0}.</value>
272+
<comment>Automation</comment>
273+
</data>
269274
</root>

0 commit comments

Comments
 (0)