@@ -802,7 +802,9 @@ private void addPublicIPResourceNode(
802802 publicIPIdNode .put ("id" , "[resourceId('Microsoft.Network/publicIPAddresses', concat("
803803 + ipName
804804 + "))]" );
805- // propertiesNode.putObject("publicIPAddress").put
805+ ObjectNode ipAddressPropertiesNode = MAPPER .createObjectNode ();
806+ ipAddressPropertiesNode .put ("deleteOption" , "Delete" );
807+ publicIPIdNode .set ("properties" , ipAddressPropertiesNode );
806808 propertiesNode .set ("publicIPAddress" , publicIPIdNode );
807809 break ;
808810 }
@@ -1834,14 +1836,7 @@ public void terminateVirtualMachine(
18341836 if (!Constants .ERROR_CODE_RESOURCE_NF .equalsIgnoreCase (e .getMessage ())) {
18351837 throw AzureCloudException .create (e );
18361838 }
1837- } finally {
1838- LOGGER .log (Level .INFO , "Clean operation starting for {0} NIC and IP" , vmName );
1839- executionEngine .executeAsync ((Callable <Void >) () -> {
1840- removeIPName (resourceGroupName , vmName , usePrivateIP );
1841- return null ;
1842- }, new NoRetryStrategy ());
18431839 }
1844-
18451840 }
18461841
18471842 public void removeImage (AzureResourceManager azureClient , String vmName , String resourceGroupName ) {
@@ -1880,33 +1875,6 @@ public void removeStorageBlob(URI blobURI, String resourceGroupName) throws Exce
18801875 }
18811876 }
18821877
1883- /**
1884- * Remove the IP name.
1885- *
1886- */
1887- public void removeIPName (String resourceGroupName ,
1888- String vmName ,
1889- boolean usePrivateIP ) {
1890- final String nic = vmName + "NIC" ;
1891- try {
1892- LOGGER .log (Level .INFO , "Remove NIC {0}" , nic );
1893- azureClient .networkInterfaces ().deleteByResourceGroup (resourceGroupName , nic );
1894- } catch (Exception e ) {
1895- LOGGER .log (Level .WARNING , "Exception while deleting NIC" , e );
1896- }
1897-
1898- final String ip = vmName + "IPName" ;
1899- try {
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- }
1905- } catch (Exception e ) {
1906- LOGGER .log (Level .WARNING , "Exception while deleting IPName" , e );
1907- }
1908- }
1909-
19101878 /**
19111879 * Restarts Azure virtual machine.
19121880 *
0 commit comments