Skip to content

Commit b868867

Browse files
author
NimishaS
committed
Added SupportsShouldProcess and ConfirmAction
1 parent bde7d03 commit b868867

File tree

2 files changed

+51
-52
lines changed

2 files changed

+51
-52
lines changed

src/ResourceManager/Compute/Commands.Compute/Extension/Chef/RemoveAzureRmVMChefExtension.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
namespace Microsoft.Azure.Commands.Compute.Extension.Chef
2626
{
2727
[Cmdlet(
28-
VerbsCommon.Remove,
29-
ProfileNouns.VirtualMachineChefExtension)]
28+
VerbsCommon.Remove, ProfileNouns.VirtualMachineChefExtension, SupportsShouldProcess = true)]
3029
[OutputType(typeof(PSAzureOperationResponse))]
3130
public class RemoveAzureRmVMChefExtension : VirtualMachineExtensionBaseCmdlet
3231
{
@@ -97,36 +96,37 @@ public override void ExecuteCmdlet()
9796
this.Name = ExtensionDefaultName;
9897
}
9998

100-
ExecuteClientAction(() =>
101-
{
102-
if (string.IsNullOrEmpty(this.Name))
99+
ConfirmAction("Remove Chef Extension", this.VMName,
100+
() =>
103101
{
104-
VirtualMachine virtualMachine = ComputeClient.ComputeManagementClient.VirtualMachines.Get(
105-
this.ResourceGroupName, this.VMName);
106-
var chefExtension = virtualMachine.Resources != null
107-
? virtualMachine.Resources.FirstOrDefault(extension =>
108-
extension.Publisher.Equals(ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) &&
109-
extension.VirtualMachineExtensionType.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase))
110-
: null;
111-
112-
if (chefExtension == null)
102+
if (string.IsNullOrEmpty(this.Name))
113103
{
114-
WriteWarning(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ChefExtensionNotFound, this.ResourceGroupName, this.VMName));
115-
return;
116-
}
117-
else
118-
{
119-
this.Name = chefExtension.Name;
104+
VirtualMachine virtualMachine = ComputeClient.ComputeManagementClient.VirtualMachines.Get(
105+
this.ResourceGroupName, this.VMName);
106+
var chefExtension = virtualMachine.Resources != null
107+
? virtualMachine.Resources.FirstOrDefault(extension =>
108+
extension.Publisher.Equals(ExtensionDefaultPublisher, StringComparison.InvariantCultureIgnoreCase) &&
109+
extension.VirtualMachineExtensionType.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase))
110+
: null;
111+
112+
if (chefExtension == null)
113+
{
114+
WriteWarning(string.Format(CultureInfo.InvariantCulture, Properties.Resources.ChefExtensionNotFound, this.ResourceGroupName, this.VMName));
115+
return;
116+
}
117+
else
118+
{
119+
this.Name = chefExtension.Name;
120+
}
120121
}
121-
}
122122

123-
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(
124-
this.ResourceGroupName,
125-
this.VMName,
126-
this.Name).GetAwaiter().GetResult();
127-
var result = Mapper.Map<PSAzureOperationResponse>(op);
128-
WriteObject(result);
129-
});
123+
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(
124+
this.ResourceGroupName,
125+
this.VMName,
126+
this.Name).GetAwaiter().GetResult();
127+
var result = Mapper.Map<PSAzureOperationResponse>(op);
128+
WriteObject(result);
129+
});
130130
}
131131
}
132132
}

src/ResourceManager/Compute/Commands.Compute/Extension/Chef/SetAzureVMChefExtension.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
namespace Microsoft.Azure.Commands.Compute.Extension.Chef
2626
{
2727
[Cmdlet(
28-
VerbsCommon.Set,
29-
ProfileNouns.VirtualMachineChefExtension)]
28+
VerbsCommon.Set, ProfileNouns.VirtualMachineChefExtension, SupportsShouldProcess = true)]
3029
[OutputType(typeof(PSAzureOperationResponse))]
3130
public class SetAzureVMChefExtensionCommand : VirtualMachineExtensionBaseCmdlet
3231
{
@@ -321,28 +320,28 @@ private Hashtable PrivateConfiguration
321320

322321
private void ExecuteCommand()
323322
{
324-
ExecuteClientAction(() =>
325-
{
326-
var parameters = new VirtualMachineExtension
327-
{
328-
Location = this.Location,
329-
Settings = this.PublicConfiguration,
330-
ProtectedSettings = this.PrivateConfiguration,
331-
Publisher = ExtensionDefaultPublisher,
332-
VirtualMachineExtensionType = this.Name,
333-
TypeHandlerVersion = this.TypeHandlerVersion,
334-
AutoUpgradeMinorVersion = this.AutoUpgradeMinorVersion
335-
};
336-
337-
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
338-
this.ResourceGroupName,
339-
this.VMName,
340-
this.Name,
341-
parameters).GetAwaiter().GetResult();
342-
343-
var result = Mapper.Map<PSAzureOperationResponse>(op);
344-
WriteObject(result);
345-
});
323+
ConfirmAction("Set Chef Extension", this.VMName,
324+
() => {
325+
var parameters = new VirtualMachineExtension
326+
{
327+
Location = this.Location,
328+
Settings = this.PublicConfiguration,
329+
ProtectedSettings = this.PrivateConfiguration,
330+
Publisher = ExtensionDefaultPublisher,
331+
VirtualMachineExtensionType = this.Name,
332+
TypeHandlerVersion = this.TypeHandlerVersion,
333+
AutoUpgradeMinorVersion = this.AutoUpgradeMinorVersion
334+
};
335+
336+
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
337+
this.ResourceGroupName,
338+
this.VMName,
339+
this.Name,
340+
parameters).GetAwaiter().GetResult();
341+
342+
var result = Mapper.Map<PSAzureOperationResponse>(op);
343+
WriteObject(result);
344+
});
346345
}
347346

348347
private void SetDefault()

0 commit comments

Comments
 (0)