Skip to content

Commit 694947e

Browse files
committed
import mof powershell sdk update
1 parent cf5144e commit 694947e

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
using Microsoft.Azure.Commands.Automation.Common;
21+
using Microsoft.Azure.Commands.Automation.Model;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
23+
24+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
25+
{
26+
/// <summary>
27+
/// Imports dsc node configuration script
28+
/// </summary>
29+
[Cmdlet(VerbsData.Import, "ImportAzureAutomationDscNodeConfiguration")]
30+
[OutputType(typeof(DscConfiguration))]
31+
public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet
32+
{
33+
/// <summary>
34+
/// Gets or sets the source path.
35+
/// </summary>
36+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Path to the node configuration script .mof to import.")]
37+
[Alias("Path")]
38+
[ValidateNotNullOrEmpty]
39+
public string SourcePath { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the node configuration name.
43+
/// </summary>
44+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node configuration name for which .mof is imported.")]
45+
[Alias("Name")]
46+
public string Name { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the configuration name for the node configuration.
50+
/// </summary>
51+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration name for .mof imported")]
52+
[Alias("ConfigurationName")]
53+
public string ConfigurationName { get; set; }
54+
55+
/// <summary>
56+
/// Execute this cmdlet.
57+
/// </summary>
58+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
59+
public override void ExecuteCmdlet()
60+
{
61+
var nodeConfiguration = this.AutomationClient.CreateNodeConfiguration(
62+
this.ResourceGroupName,
63+
this.AutomationAccountName,
64+
this.SourcePath,
65+
this.Name,
66+
this.ConfigurationName);
67+
68+
this.WriteObject(nodeConfiguration);
69+
}
70+
}
71+
}

src/ResourceManager/Automation/Commands.Automation/Commands.ResourceManagement.Automation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
</ItemGroup>
118118
<ItemGroup>
119119
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
120+
<Compile Include="Cmdlet\ImportAzureAutomationDscNodeConfiguration.cs" />
120121
<Compile Include="Cmdlet\ExportAzureAutomationDscConfiguration.cs" />
121122
<Compile Include="Cmdlet\ExportAzureAutomationDscNodeReportContent.cs" />
122123
<Compile Include="Cmdlet\GetAzureAutomationCertificate.cs" />

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,63 @@ public Model.NodeConfiguration GetNodeConfiguration(string resourceGroupName, st
11181118
}
11191119
}
11201120

1121+
public Model.NodeConfiguration CreateNodeConfiguration(
1122+
string resourceGroupName,
1123+
string automationAccountName,
1124+
string sourcePath,
1125+
string nodeConfiguraionName,
1126+
string configurationName)
1127+
{
1128+
using (var request = new RequestSettings(this.automationManagementClient))
1129+
{
1130+
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
1131+
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
1132+
Requires.Argument("SourcePath", sourcePath).NotNull();
1133+
1134+
string fileContent = null;
1135+
string nodeConfigurationName = String.Empty;
1136+
1137+
try
1138+
{
1139+
if (File.Exists(Path.GetFullPath(sourcePath)))
1140+
{
1141+
fileContent = System.IO.File.ReadAllText(sourcePath);
1142+
}
1143+
}
1144+
catch (Exception)
1145+
{
1146+
// exception in accessing the file path
1147+
throw new FileNotFoundException(
1148+
string.Format(
1149+
CultureInfo.CurrentCulture,
1150+
Resources.ConfigurationSourcePathInvalid));
1151+
}
1152+
1153+
var nodeConfigurationCreateParameters = new DscNodeConfigurationCreateOrUpdateParameters()
1154+
{
1155+
Name = nodeConfiguraionName,
1156+
Source = new Microsoft.Azure.Management.Automation.Models.ContentSource()
1157+
{
1158+
// only embeddedContent supported for now
1159+
ContentType = Model.ContentSourceType.embeddedContent.ToString(),
1160+
Value = fileContent
1161+
},
1162+
Configuration = new DscConfigurationAssociationProperty()
1163+
{
1164+
Name = configurationName
1165+
}
1166+
};
1167+
1168+
var configuration =
1169+
this.automationManagementClient.NodeConfigurations.CreateOrUpdate(
1170+
resourceGroupName,
1171+
automationAccountName,
1172+
nodeConfigurationCreateParameters).NodeConfiguration;
1173+
1174+
return new Model.NodeConfiguration(resourceGroupName, automationAccountName, configuration);
1175+
}
1176+
}
1177+
11211178
#endregion
11221179

11231180
#region dsc reports

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public interface IAutomationClient
5959
IEnumerable<NodeConfiguration> ListNodeConfigurationsByConfigurationName(string resourceGroupName, string automationAccountName, string configurationName, string rollupStatus);
6060

6161
IEnumerable<NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus);
62+
63+
NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, IDictionary tags);
6264
#endregion
6365

6466
#region Configurations

0 commit comments

Comments
 (0)