23
23
24
24
namespace Microsoft . WindowsAzure . Commands . ServiceManagement . IaaS
25
25
{
26
- [ Cmdlet ( VerbsCommon . Remove , "AzureVM" ) , OutputType ( typeof ( ManagementOperationContext ) ) ]
26
+ [ Cmdlet ( VerbsCommon . Remove , "AzureVM" , SupportsShouldProcess = true ) , OutputType ( typeof ( ManagementOperationContext ) ) ]
27
27
public class RemoveAzureVMCommand : IaaSDeploymentManagementCmdletBase
28
28
{
29
29
[ Parameter ( Position = 1 , Mandatory = true , ValueFromPipelineByPropertyName = true , HelpMessage = "The name of the role to remove." ) ]
@@ -43,38 +43,41 @@ public SwitchParameter DeleteVHD
43
43
44
44
protected override void ExecuteCommand ( )
45
45
{
46
- ServiceManagementProfile . Initialize ( ) ;
47
-
48
- base . ExecuteCommand ( ) ;
49
- if ( CurrentDeploymentNewSM == null )
46
+ if ( this . ShouldProcess ( String . Format ( "Service: {0}, VM: {1}" , this . ServiceName , this . Name ) , Resources . RemoveAzureVMShouldProcessAction ) )
50
47
{
51
- return ;
52
- }
48
+ ServiceManagementProfile . Initialize ( ) ;
53
49
54
- DeploymentGetResponse deploymentGetResponse = this . ComputeClient . Deployments . GetBySlot ( this . ServiceName , DeploymentSlot . Production ) ;
55
- if ( deploymentGetResponse . Roles . FirstOrDefault ( r => r . RoleName . Equals ( Name , StringComparison . InvariantCultureIgnoreCase ) ) == null )
56
- {
57
- throw new ArgumentOutOfRangeException ( String . Format ( Resources . RoleInstanceCanNotBeFoundWithName , Name ) ) ;
58
- }
50
+ base . ExecuteCommand ( ) ;
51
+ if ( CurrentDeploymentNewSM == null )
52
+ {
53
+ return ;
54
+ }
59
55
60
- if ( deploymentGetResponse . RoleInstances . Count > 1 )
61
- {
62
- ExecuteClientActionNewSM (
63
- null ,
64
- CommandRuntime . ToString ( ) ,
65
- ( ) => this . ComputeClient . VirtualMachines . Delete ( this . ServiceName , CurrentDeploymentNewSM . Name , Name , DeleteVHD . IsPresent ) ) ;
66
- }
67
- else
68
- {
69
- if ( deploymentGetResponse != null && ! string . IsNullOrEmpty ( deploymentGetResponse . ReservedIPName ) )
56
+ DeploymentGetResponse deploymentGetResponse = this . ComputeClient . Deployments . GetBySlot ( this . ServiceName , DeploymentSlot . Production ) ;
57
+ if ( deploymentGetResponse . Roles . FirstOrDefault ( r => r . RoleName . Equals ( Name , StringComparison . InvariantCultureIgnoreCase ) ) == null )
70
58
{
71
- WriteVerboseWithTimestamp ( string . Format ( Resources . ReservedIPNameNoLongerInUseByDeletingLastVMButStillBeingReserved , deploymentGetResponse . ReservedIPName ) ) ;
59
+ throw new ArgumentOutOfRangeException ( String . Format ( Resources . RoleInstanceCanNotBeFoundWithName , Name ) ) ;
72
60
}
73
61
74
- ExecuteClientActionNewSM < AzureOperationResponse > (
75
- null ,
76
- CommandRuntime . ToString ( ) ,
77
- ( ) => this . ComputeClient . Deployments . DeleteByName ( this . ServiceName , CurrentDeploymentNewSM . Name , DeleteVHD . IsPresent ) ) ;
62
+ if ( deploymentGetResponse . RoleInstances . Count > 1 )
63
+ {
64
+ ExecuteClientActionNewSM (
65
+ null ,
66
+ CommandRuntime . ToString ( ) ,
67
+ ( ) => this . ComputeClient . VirtualMachines . Delete ( this . ServiceName , CurrentDeploymentNewSM . Name , Name , DeleteVHD . IsPresent ) ) ;
68
+ }
69
+ else
70
+ {
71
+ if ( deploymentGetResponse != null && ! string . IsNullOrEmpty ( deploymentGetResponse . ReservedIPName ) )
72
+ {
73
+ WriteVerboseWithTimestamp ( string . Format ( Resources . ReservedIPNameNoLongerInUseByDeletingLastVMButStillBeingReserved , deploymentGetResponse . ReservedIPName ) ) ;
74
+ }
75
+
76
+ ExecuteClientActionNewSM < AzureOperationResponse > (
77
+ null ,
78
+ CommandRuntime . ToString ( ) ,
79
+ ( ) => this . ComputeClient . Deployments . DeleteByName ( this . ServiceName , CurrentDeploymentNewSM . Name , DeleteVHD . IsPresent ) ) ;
80
+ }
78
81
}
79
82
}
80
83
}
0 commit comments