Skip to content

Commit 693a730

Browse files
committed
Merge pull request #91 from huangpf/clu
Clu
2 parents 724782d + 048629a commit 693a730

26 files changed

+2163
-0
lines changed
Lines changed: 22 additions & 0 deletions
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+
}
Lines changed: 22 additions & 0 deletions
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+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 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 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 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+
protected override void ProcessRecord()
68+
{
69+
base.ProcessRecord();
70+
71+
ExecuteClientAction(() =>
72+
{
73+
if (Status)
74+
{
75+
var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name, "instanceView");
76+
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);
77+
78+
if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) &&
79+
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase))
80+
{
81+
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
82+
}
83+
else
84+
{
85+
WriteObject(null);
86+
}
87+
}
88+
else
89+
{
90+
var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name);
91+
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);
92+
93+
if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) &&
94+
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase))
95+
{
96+
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
97+
}
98+
else
99+
{
100+
WriteObject(null);
101+
}
102+
}
103+
});
104+
}
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
public class RemoveAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet
25+
{
26+
[Parameter(
27+
Mandatory = true,
28+
Position = 0,
29+
ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "The resource group name.")]
31+
[ValidateNotNullOrEmpty]
32+
public string ResourceGroupName { get; set; }
33+
34+
[Alias("ResourceName")]
35+
[Parameter(
36+
Mandatory = true,
37+
Position = 1,
38+
ValueFromPipelineByPropertyName = true,
39+
HelpMessage = "The virtual machine name.")]
40+
[ValidateNotNullOrEmpty]
41+
public string VMName { get; set; }
42+
43+
[Alias("ExtensionName")]
44+
[Parameter(
45+
Mandatory = true,
46+
Position = 2,
47+
ValueFromPipelineByPropertyName = true,
48+
HelpMessage = "The extension name.")]
49+
[ValidateNotNullOrEmpty]
50+
public string Name { get; set; }
51+
52+
[Parameter(HelpMessage = "To force the removal.")]
53+
[ValidateNotNullOrEmpty]
54+
public SwitchParameter Force { get; set; }
55+
56+
protected override void ProcessRecord()
57+
{
58+
base.ProcessRecord();
59+
60+
ExecuteClientAction(() =>
61+
{
62+
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption")))
63+
{
64+
this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
65+
}
66+
});
67+
}
68+
69+
}
70+
}

0 commit comments

Comments
 (0)