@@ -1767,7 +1767,7 @@ public void shutdownVirtualMachine(AzureVMAgent agent) {
17671767 public static void terminateVirtualMachine (AzureVMAgent agent ) throws AzureCloudException {
17681768 AzureVMManagementServiceDelegate delegate = agent .getServiceDelegate ();
17691769 if (delegate != null ) {
1770- delegate .terminateVirtualMachine (agent .getNodeName (), agent .getResourceGroupName (), new ExecutionEngine ());
1770+ delegate .terminateVirtualMachine (agent .getNodeName (), agent .getResourceGroupName (), agent . getTemplate (). getUsePrivateIP (), new ExecutionEngine ());
17711771 }
17721772 }
17731773
@@ -1779,8 +1779,9 @@ public static void terminateVirtualMachine(AzureVMAgent agent) throws AzureCloud
17791779 */
17801780 public void terminateVirtualMachine (
17811781 String vmName ,
1782- String resourceGroupName ) throws AzureCloudException {
1783- terminateVirtualMachine (vmName , resourceGroupName , new ExecutionEngine ());
1782+ String resourceGroupName ,
1783+ boolean usePrivateIP ) throws AzureCloudException {
1784+ terminateVirtualMachine (vmName , resourceGroupName , usePrivateIP , new ExecutionEngine ());
17841785 }
17851786
17861787 /**
@@ -1792,6 +1793,7 @@ public void terminateVirtualMachine(
17921793 public void terminateVirtualMachine (
17931794 final String vmName ,
17941795 final String resourceGroupName ,
1796+ final boolean usePrivateIP ,
17951797 ExecutionEngine executionEngine ) throws AzureCloudException {
17961798 try {
17971799 if (virtualMachineExists (vmName , resourceGroupName )) {
@@ -1835,7 +1837,7 @@ public void terminateVirtualMachine(
18351837 } finally {
18361838 LOGGER .log (Level .INFO , "Clean operation starting for {0} NIC and IP" , vmName );
18371839 executionEngine .executeAsync ((Callable <Void >) () -> {
1838- removeIPName (resourceGroupName , vmName );
1840+ removeIPName (resourceGroupName , vmName , usePrivateIP );
18391841 return null ;
18401842 }, new NoRetryStrategy ());
18411843 }
@@ -1883,7 +1885,8 @@ public void removeStorageBlob(URI blobURI, String resourceGroupName) throws Exce
18831885 *
18841886 */
18851887 public void removeIPName (String resourceGroupName ,
1886- String vmName ) {
1888+ String vmName ,
1889+ boolean usePrivateIP ) {
18871890 final String nic = vmName + "NIC" ;
18881891 try {
18891892 LOGGER .log (Level .INFO , "Remove NIC {0}" , nic );
@@ -1894,8 +1897,11 @@ public void removeIPName(String resourceGroupName,
18941897
18951898 final String ip = vmName + "IPName" ;
18961899 try {
1897- LOGGER .log (Level .INFO , "Remove IP {0}" , ip );
1898- azureClient .publicIpAddresses ().deleteByResourceGroup (resourceGroupName , ip );
1900+ // Does not attempt to remove public IP if private IP is used because public IP does not exist
1901+ if (!usePrivateIP ) {
1902+ LOGGER .log (Level .INFO , "Remove IP {0}" , ip );
1903+ azureClient .publicIpAddresses ().deleteByResourceGroup (resourceGroupName , ip );
1904+ }
18991905 } catch (Exception e ) {
19001906 LOGGER .log (Level .WARNING , "Exception while deleting IPName" , e );
19011907 }
0 commit comments