Skip to content

Clu #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 15, 2015
Merged

Clu #91

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Compute
{
public class CustomScriptExtensionPrivateSettings
{
public string storageAccountName;
public string storageAccountKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Compute
{
public class CustomScriptExtensionPublicSettings
{
public string[] fileUris;
public string commandToExecute;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Management.Compute;
using Newtonsoft.Json;
using System;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(
VerbsCommon.Get,
ProfileNouns.VirtualMachineCustomScriptExtension,
DefaultParameterSetName = GetCustomScriptExtensionParamSetName),
OutputType(
typeof(VirtualMachineCustomScriptExtensionContext))]
public class GetAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet
{
protected const string GetCustomScriptExtensionParamSetName = "GetCustomScriptExtension";

[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("ResourceName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The virtual machine name.")]
[ValidateNotNullOrEmpty]
public string VMName { get; set; }

[Alias("ExtensionName")]
[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The extension name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Position = 3,
ValueFromPipelineByPropertyName = true,
HelpMessage = "To show the status.")]
[ValidateNotNullOrEmpty]
public SwitchParameter Status { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();

ExecuteClientAction(() =>
{
if (Status)
{
var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name, "instanceView");
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);

if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) &&
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase))
{
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
}
else
{
WriteObject(null);
}
}
else
{
var result = this.VirtualMachineExtensionClient.Get(this.ResourceGroupName, this.VMName, this.Name);
var returnedExtension = result.ToPSVirtualMachineExtension(this.ResourceGroupName);

if (returnedExtension.Publisher.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultPublisher, StringComparison.OrdinalIgnoreCase) &&
returnedExtension.ExtensionType.Equals(VirtualMachineCustomScriptExtensionContext.ExtensionDefaultName, StringComparison.OrdinalIgnoreCase))
{
WriteObject(new VirtualMachineCustomScriptExtensionContext(returnedExtension));
}
else
{
WriteObject(null);
}
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Management.Compute;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet(
VerbsCommon.Remove,
ProfileNouns.VirtualMachineCustomScriptExtension)]
public class RemoveAzureVMCustomScriptExtensionCommand : VirtualMachineExtensionBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("ResourceName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The virtual machine name.")]
[ValidateNotNullOrEmpty]
public string VMName { get; set; }

[Alias("ExtensionName")]
[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The extension name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(HelpMessage = "To force the removal.")]
[ValidateNotNullOrEmpty]
public SwitchParameter Force { get; set; }

protected override void ProcessRecord()
{
base.ProcessRecord();

ExecuteClientAction(() =>
{
if (this.Force.IsPresent || this.ShouldContinue(Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalConfirmation"), Microsoft.Azure.Commands.Compute.Properties.Resources.ResourceManager.GetString("VirtualMachineExtensionRemovalCaption")))
{
this.VirtualMachineExtensionClient.Delete(this.ResourceGroupName, this.VMName, this.Name);
}
});
}

}
}
Loading