Skip to content

Commit b5de0f2

Browse files
committed
report model update3
1 parent 28e8804 commit b5de0f2

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/ImportAzureAutomationDscNodeConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl
4747
/// Gets or sets the configuration name for the node configuration.
4848
/// </summary>
4949
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the DSC Configuration to import the Node Configuration under. All Node Configurations in Azure Automation must exist under a Configuration. The name of the Configuration will become the namespace of the imported Node Configuration, in the form of 'ConfigurationName.MofFileName'")]
50-
[Alias("NodeConfigurationName")]
51-
public string Name { get; set; }
50+
[Alias("ConfigurationName")]
51+
public string ConfigName { get; set; }
5252

5353

5454
/// <summary>
@@ -71,7 +71,7 @@ public override void ExecuteCmdlet()
7171
this.ResourceGroupName,
7272
this.AutomationAccountName,
7373
this.SourcePath,
74-
this.Name,
74+
this.ConfigName,
7575
this.Force);
7676

7777
this.WriteObject(nodeConfiguration);

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,22 @@ public Model.CompilationJob StartCompilationJob(string resourceGroupName, string
10651065
#endregion
10661066

10671067
#region node configuration
1068+
public Model.NodeConfiguration TryGetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus)
1069+
{
1070+
using (var request = new RequestSettings(this.automationManagementClient))
1071+
{
1072+
try
1073+
{
1074+
return GetNodeConfiguration(resourceGroupName, automationAccountName, nodeConfigurationName, rollupStatus);
1075+
}
1076+
catch (ResourceNotFoundException resourceNotFoundException)
1077+
{
1078+
Console.Write(resourceNotFoundException.Message);
1079+
return null;
1080+
}
1081+
}
1082+
}
1083+
10681084
public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, string automationAccountName, string nodeConfigurationName, string rollupStatus)
10691085
{
10701086
using (var request = new RequestSettings(this.automationManagementClient))
@@ -1164,23 +1180,24 @@ public Model.NodeConfiguration CreateNodeConfiguration(
11641180
string resourceGroupName,
11651181
string automationAccountName,
11661182
string sourcePath,
1167-
string nodeConfigurationName,
1183+
string configurationName,
11681184
bool overWrite)
11691185
{
11701186
using (var request = new RequestSettings(this.automationManagementClient))
11711187
{
11721188
Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty();
11731189
Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty();
11741190
Requires.Argument("SourcePath", sourcePath).NotNullOrEmpty();
1175-
Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNullOrEmpty();
1191+
Requires.Argument("configurationName", configurationName).NotNullOrEmpty();
11761192

11771193
string fileContent = null;
1178-
string configurationName = null;
1194+
string nodeConfigurationName = null;
11791195
string nodeName = null;
11801196

11811197
if (File.Exists(Path.GetFullPath(sourcePath)))
11821198
{
11831199
fileContent = System.IO.File.ReadAllText(sourcePath);
1200+
nodeConfigurationName = configurationName + "." + System.IO.Path.GetFileNameWithoutExtension(sourcePath);
11841201
}
11851202
else
11861203
{
@@ -1190,35 +1207,9 @@ public Model.NodeConfiguration CreateNodeConfiguration(
11901207
CultureInfo.CurrentCulture,
11911208
Resources.ConfigurationSourcePathInvalid));
11921209
}
1193-
1194-
try
1195-
{
1196-
int index = nodeConfigurationName.IndexOf(".");
1197-
if (index > 0)
1198-
{
1199-
nodeName = nodeConfigurationName.Substring(0, index);
1200-
int configNameStartIndex = index + 1;
1201-
int configNameLenght = nodeConfigurationName.Length - index -1;
1202-
configurationName = nodeConfigurationName.Substring(configNameStartIndex, configNameLenght);
1203-
}
1204-
else
1205-
{
1206-
throw new ArgumentException(string.Format(
1207-
CultureInfo.CurrentCulture,
1208-
Resources.NodeConfigurationNameInvalid));
1209-
}
1210-
}
1211-
catch (Exception)
1212-
{
1213-
// exception in getting the config name from configurationName
1214-
throw new ArgumentException(
1215-
string.Format(
1216-
CultureInfo.CurrentCulture,
1217-
Resources.NodeConfigurationNameInvalid));
1218-
}
1219-
1210+
12201211
// if node configuration already exists, ensure overwrite flag is specified
1221-
var nodeConfigurationModel = this.GetNodeConfiguration(
1212+
var nodeConfigurationModel = this.TryGetNodeConfiguration(
12221213
resourceGroupName,
12231214
automationAccountName,
12241215
nodeConfigurationName,

0 commit comments

Comments
 (0)