Skip to content

Commit b6585f4

Browse files
unknownunknown
authored andcommitted
CustomScript extension, VMAccess extension cmdlets
1 parent 3cc9370 commit b6585f4

22 files changed

+1217
-9
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,19 @@ public void TestVirtualMachineExtension()
2525
{
2626
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineExtension");
2727
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestVirtualMachineCustomScriptExtension()
32+
{
33+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineCustomScriptExtension");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestVirtualMachineAccessExtension()
39+
{
40+
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineAccessExtension");
41+
}
2842
}
2943
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1

Lines changed: 332 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function Test-VirtualMachineProfile
105105
Assert-AreEqual $encodedCustom $p.OSProfile.CustomData;
106106

107107
# Verify WinRM
108-
Assert-AreEqual $null $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[0].CertificateUrl;
108+
Assert-Null $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[0].CertificateUrl;
109109
Assert-AreEqual "http" $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[0].Protocol ;
110110
Assert-AreEqual $winRMCertUrl $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[1].CertificateUrl ;
111111
Assert-AreEqual "https" $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[1].Protocol ;

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.168.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
101101
<SpecificVersion>False</SpecificVersion>
102102
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
103+
</Reference>
104+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
105+
<SpecificVersion>False</SpecificVersion>
106+
<HintPath>..\..\..\packages\WindowsAzure.Storage.4.0.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
103107
</Reference>
104108
<Reference Include="Newtonsoft.Json">
105109
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -131,11 +135,22 @@
131135
<Compile Include="AvailabilitySets\GetAzureAvailabilitySetCommand.cs" />
132136
<Compile Include="AvailabilitySets\NewAzureAvailabilitySetCommand.cs" />
133137
<Compile Include="AvailabilitySets\AvailabilitySetBaseCmdlet.cs" />
134-
<Compile Include="Common\ExtensionSettingBuilder.cs" />
135138
<Compile Include="Common\ComputeClient.cs" />
139+
<Compile Include="Extension\CustomScript\GetAzureVMCustomScriptExtensionCommand.cs" />
140+
<Compile Include="Extension\CustomScript\CustomScriptExtensionPrivateSettings.cs" />
141+
<Compile Include="Extension\CustomScript\CustomScriptExtensionPublicSettings.cs" />
142+
<Compile Include="Extension\CustomScript\RemoveAzureVMCustomScriptExtensionCommand.cs" />
143+
<Compile Include="Extension\CustomScript\SetAzureVMCustomScriptExtensionCommand.cs" />
144+
<Compile Include="Extension\CustomScript\VirtualMachineCustomScriptExtensionContext.cs" />
136145
<Compile Include="Extension\SetAzureVMExtensionCommand.cs" />
137146
<Compile Include="Extension\RemoveAzureVMExtensionCommand.cs" />
138147
<Compile Include="Extension\GetAzureVMExtensionCommand.cs" />
148+
<Compile Include="Extension\VMAccess\GetAzureVMAccessExtension.cs" />
149+
<Compile Include="Extension\VMAccess\RemoveAzureVMAccessExtension.cs" />
150+
<Compile Include="Extension\VMAccess\SetAzureVMAccessExtension.cs" />
151+
<Compile Include="Extension\VMAccess\VirtualMachineAccessExtensionContext.cs" />
152+
<Compile Include="Extension\VMAccess\VMAccessExtensionPrivateSettings.cs" />
153+
<Compile Include="Extension\VMAccess\VMAccessExtensionPublicSettings.cs" />
139154
<Compile Include="Models\PSVirtualMachineExtension.cs" />
140155
<Compile Include="Models\PSAvailabilitySet.cs" />
141156
<Compile Include="Models\PSVirtualMachineInstanceView.cs" />
@@ -227,6 +242,7 @@
227242
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
228243
</Content>
229244
</ItemGroup>
245+
<ItemGroup />
230246
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
231247
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
232248
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public static class ProfileNouns
6565

6666
public const string VirtualMachine = "AzureVM";
6767
public const string VirtualMachineExtension = "AzureVMExtension";
68+
public const string VirtualMachineCustomScriptExtension = "AzureVMCustomScriptExtension";
69+
public const string VirtualMachineAccessExtension = "AzureVMAccessExtension";
6870

6971
public const string AvailabilitySet = "AzureAvailabilitySet";
7072
public const string VirtualMachineConfig = "AzureVMConfig";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
public class CustomScriptExtensionPrivateSettings
18+
{
19+
public string storageAccountName;
20+
public string storageAccountKey;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
namespace Microsoft.Azure.Commands.Compute
16+
{
17+
public class CustomScriptExtensionPublicSettings
18+
{
19+
public string[] fileUris;
20+
public string commandToExecute;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.Compute.Common;
16+
using Microsoft.Azure.Commands.Compute.Models;
17+
using Microsoft.Azure.Management.Compute;
18+
using Newtonsoft.Json;
19+
using System;
20+
using System.Management.Automation;
21+
22+
namespace Microsoft.Azure.Commands.Compute
23+
{
24+
[Cmdlet(
25+
VerbsCommon.Get,
26+
ProfileNouns.VirtualMachineCustomScriptExtension,
27+
DefaultParameterSetName = GetCustomScriptExtensionParamSetName),
28+
OutputType(
29+
typeof(VirtualMachineCustomScriptExtensionContext))]
30+
public class GetAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet
31+
{
32+
protected const string GetCustomScriptExtensionParamSetName = "GetCustomScriptExtension";
33+
34+
//[Parameter(
35+
// Mandatory = true,
36+
// Position = 0,
37+
// ValueFromPipelineByPropertyName = true,
38+
// HelpMessage = "The resource group name.")]
39+
//[ValidateNotNullOrEmpty]
40+
//public override string ResourceGroupName { get; set; }
41+
42+
//[Alias("ResourceName")]
43+
//[Parameter(
44+
// Mandatory = true,
45+
// Position = 1,
46+
// ValueFromPipelineByPropertyName = true,
47+
// HelpMessage = "The virtual machine name.")]
48+
//[ValidateNotNullOrEmpty]
49+
//public override string VMName { get; set; }
50+
51+
//[Alias("ExtensionName")]
52+
//[Parameter(
53+
// Mandatory = true,
54+
// Position = 2,
55+
// ValueFromPipelineByPropertyName = true,
56+
// HelpMessage = "The extension name.")]
57+
//[ValidateNotNullOrEmpty]
58+
//public override string Name { get; set; }
59+
60+
[Parameter(
61+
Position = 3,
62+
ValueFromPipelineByPropertyName = true,
63+
HelpMessage = "To show the status.")]
64+
[ValidateNotNullOrEmpty]
65+
public SwitchParameter Status { get; set; }
66+
67+
68+
public override void ExecuteCmdlet()
69+
{
70+
base.ExecuteCmdlet();
71+
72+
if (Status)
73+
{
74+
var result = this.VirtualMachineExtensionClient.GetInstanceView(this.ResourceGroupName, this.VMName, this.Name);
75+
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);
76+
77+
if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) &&
78+
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.InvariantCultureIgnoreCase))
79+
{
80+
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
81+
}
82+
else
83+
{
84+
WriteObject(null);
85+
}
86+
}
87+
else
88+
{
89+
var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name);
90+
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);
91+
92+
if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) &&
93+
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.InvariantCultureIgnoreCase))
94+
{
95+
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
96+
}
97+
else
98+
{
99+
WriteObject(null);
100+
}
101+
}
102+
}
103+
}
104+
}
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.Compute.Common;
16+
using Microsoft.Azure.Management.Compute;
17+
using System.Management.Automation;
18+
19+
namespace Microsoft.Azure.Commands.Compute
20+
{
21+
[Cmdlet(
22+
VerbsCommon.Remove,
23+
ProfileNouns.VirtualMachineCustomScriptExtension),
24+
OutputType(
25+
typeof(object))]
26+
27+
28+
public class RemoveAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet
29+
{
30+
31+
[Parameter(HelpMessage = "To force the removal.")]
32+
[ValidateNotNullOrEmpty]
33+
public SwitchParameter Force { get; set; }
34+
35+
public override void ExecuteCmdlet()
36+
{
37+
base.ExecuteCmdlet();
38+
39+
if (this.Force.IsPresent
40+
|| this.ShouldContinue(Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Properties.Resources.VirtualMachineExtensionRemovalCaption))
41+
{
42+
var op = this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
43+
WriteObject(op);
44+
}
45+
}
46+
47+
}
48+
}

0 commit comments

Comments
 (0)